eslint-plugin-fsd-import
v0.1.1
Published
Plugin for checking imports path in FSD project
Maintainers
Readme
eslint-plugin-fsd-import
ESLint plugin for checking import paths in Feature-Sliced Design projects.
Installation
Install ESLint and eslint-plugin-fsd-import:
npm install --save-dev eslint eslint-plugin-fsd-importUsage
Flat config
For ESLint v9 and newer, add the plugin to eslint.config.js:
const fsdImport = require("eslint-plugin-fsd-import");
module.exports = [
fsdImport.configs["flat/recommended"],
];Legacy config
For ESLint v8 and older, add fsd-import to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"extends": ["plugin:fsd-import/recommended"]
}Both recommended presets enable every exported rule except
public-api-imports. That rule is opt-in because testing-file exceptions and
layer choices are project-specific. Enable it with the project alias and source
root when appropriate:
{
rules: {
"fsd-import/public-api-imports": ["error", {
alias: "@",
rootDir: "src",
testFilesPatterns: ["**/*.test.ts"]
}]
}
}Supported Rules
Check that FSD imports are correct:
- fsd-relative-path - imports within one slice should be relative.
- no-cross-slice-relative-imports - relative imports cannot leave a slice.
- layer-imports - modules can import only from allowed lower FSD layers;
entitiesandsharedmay also import from the same layer. - public-api-imports - opt-in absolute imports should use the public API.
- shared-public-api-imports - shared segments must use their public API.
- forbidden-app-imports - imports from
appneed explicit exceptions. - no-deprecated-layer-names - maps legacy layer names in imports.
- slice-boundaries - prevents cross-slice public-API imports.
Rule-specific options and examples are documented on each rule page.
Contributing
When adding a rule, register it explicitly in lib/index.js, add its tests and
documentation, and include it in the published configuration when appropriate.
