Quick Start
Follow these steps to quickly set up ESLint Plugin Boundaries in your project. Then you can explore more advanced configurations to fit your project's needs, starting with Classification.
1. Installation
If you have not installed them yet, install ESLint and ESLint Plugin Boundaries:
npm install eslint eslint-plugin-boundaries --save-dev
2. Register the Plugin
Once installed, enable the plugin in your eslint.config.js file:
- JavaScript
- TypeScript
import boundaries from "eslint-plugin-boundaries";
export default [
{
plugins: {
boundaries,
},
}
];
import boundaries, { Config } from "eslint-plugin-boundaries";
export default [
{
plugins: {
boundaries,
},
} satisfies Config
];
3. Define your Elements
Elements classify a project by the architectural piece each file belongs to. Define them using the boundaries/elements setting.
These patterns determine how each file or dependency is classified. This step is optional on its own — as the next step explains, you only need to define at least one classification layer, elements or files.
Read the Classification section for guidance on how to define the patterns for the elements and files in your project.
- JavaScript
- TypeScript
import boundaries from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],},}];
import boundaries, { Config, Settings } from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],} satisfies Settings,} satisfies Config];
This is only a basic example of configuration. The plugin can also capture path fragments from element paths so you can reuse them in rule policy selectors. Read Elements to learn the full range of descriptor options.
Element patterns match folders (e.g. components/*/*), not individual files. To classify files by kind — tests, styles, stories — use file descriptors in boundaries/files, as shown in the next step.
4. Categorize your Files
This step is optional. The plugin needs at least one classification layer to work, so you only have to define either elements or file descriptors — the previous step is optional too, and defining both is not required.
While elements group files into architectural units (usually folders, such as components/Button/), file descriptors classify each file on its own, independently of the element it belongs to. They answer the question "what kind of file is this?" — a test, a style, a story — regardless of where it lives. Define them with the boundaries/files setting.
- JavaScript
- TypeScript
import boundaries from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],},}];
import boundaries, { Config, Settings } from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],} satisfies Settings,} satisfies Config];
File categories are independent from elements, so the same file can be element type component and file category test at the same time. Unlike element types, every matching descriptor contributes its category, so a file can carry several at once. Read Files to learn the full range of file descriptor options.
The rest of this guide keeps these file descriptors so you can see the file layer matched in a rule policy. If you skip this optional step, simply omit the boundaries/files setting and any rule that targets file.
5. Apply Predefined Rules
Apply one of the predefined rule configurations as a starting point by extending it in your rules section.
Use recommended for existing projects to introduce rules gradually — it allows files outside defined elements. Use strict for new projects to require all files to belong to a known element from the start.
- JavaScript
- TypeScript
import boundaries from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],},rules: {...boundaries.configs.recommended.rules,},},];
import boundaries, { Config, Settings, Rules } from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],} satisfies Settings,rules: {...boundaries.configs.recommended.rules,} satisfies Rules,} satisfies Config];
6. Set Dependencies Rule Policies
Now you can define your own dependency rule policies using the boundaries/dependencies rule.
Read how to use Selectors to configure your Rule Policies in detail.
- JavaScript
- TypeScript
import boundaries from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],},rules: {...boundaries.configs.recommended.rules,"boundaries/dependencies": [2, {default: "disallow",policies: [{from: { element: { types: "component" } },allow: { to: { element: { types: "helper" } } }},{from: { element: { types: "module" } },allow: { to: { element: { types: ["component", "helper"] } } }},{// No element may import a test file, whatever element it belongs todisallow: { to: { file: { categories: "test" } } }}]}]},},];
import boundaries, { Config, Settings, Rules } from "eslint-plugin-boundaries";export default [{plugins: {boundaries,},settings: {"boundaries/elements": [{ type: "helper", pattern: "helpers/*" },{ type: "component", pattern: "components/*/*" },{ type: "module", pattern: "modules/*" }],"boundaries/files": [{ pattern: "**/*.spec.js", category: "test" },{ pattern: "**/*.css", category: "style" }],} satisfies Settings,rules: {...boundaries.configs.recommended.rules,"boundaries/dependencies": [2, {default: "disallow",policies: [{from: { element: { types: "component" } },allow: { to: { element: { types: "helper" } } }},{from: { element: { types: "module" } },allow: { to: { element: { types: ["component", "helper"] } } }},{// No element may import a test file, whatever element it belongs todisallow: { to: { file: { categories: "test" } } }}]}]} satisfies Rules,} satisfies Config];
You can customize the error messages reported by rule policies using message templates.
7. Next Steps
You are all set! Now you can start enforcing architectural boundaries in your project 🎉
From here you can:
- Explore the configuration sections to learn:
- How to Classify Elements and Files.
- How to define Selectors to match dependencies.
- How to define Rule Policies using those Selectors.
- How to customize Global Settings.
- Review the Rules section to understand all available rules and how to configure them.
- Browse the Guides for task-oriented walkthroughs, such as setting up a monorepo.