Skip to main content

Rules Overview

ESLint Plugin Boundaries provides a primary rule (boundaries/element-types) that enables you to define and enforce architectural boundaries within your codebase. With this rule, you can specify which types of elements (e.g., modules, components, services) are allowed to interact with each other.

But that’s not all. In addition to the main rule, the plugin includes other complementary rules that further enhance its capabilities and help you maintain the integrity and consistency of your architecture.

Here are the key rules provided by the plugin:

Element types

This rule ensures that dependencies between the elements in your project follow the constraints you have defined.

Examples:

  • Define the element types in your project as “models”, “views”, and “controllers”. Then enforce that “views” and “models” can only be imported by “controllers”, and that “controllers” are never used by “views” or “models”.
  • Define the element types in your project as “components”, “views”, “layouts”, “pages”, and “helpers”. Then enforce that “components” can only import “helpers”; “views” can only import “components” or “helpers”; “layouts” can only import “views”, “components”, or “helpers”; and “pages” can import any other element type.

See the documentation for the boundaries/element-types rule for more details.

Entry point

This rule ensures that elements cannot import files from another element except through the defined entry point for that type.

See the documentation for the boundaries/entry-point rule for more details.

Allowed external modules

This rule checks which external dependencies can be used by each element type. It helps maintain consistent dependency management across different architectural layers. For example, you can configure that “helpers” cannot import react, that “components” cannot import react-router-dom, or that modules cannot import { Link } from react-router-dom.

See the documentation for the boundaries/external rule for more details.

Private elements

This rule ensures that elements cannot import the children of another element. When element B is a child of element A, B becomes a “private” element of A, and only A is allowed to use it.

See the documentation for the boundaries/no-private rule for more details.

Rules about unknown or ignored files

Next rules help you manage files or dependencies with files that do not belong to any known element type, or files that are explicitly ignored in the plugin settings:

  • No Unknown: This rule ensures that files cannot import unknown files (files that do not belong to any known element type). It helps maintain clear boundaries by preventing dependencies on unclassified files.
  • No Unknown Files: This rule ensures that all files in your project belong to a known element type. It helps maintain a well-defined architecture by preventing stray files from being even created.
  • No Ignored: This rule ensures that all known files can only import non-ignored files. It helps maintain the integrity of your architecture by preventing dependencies on files that are intentionally excluded from the architectural boundaries.