
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
eslint-plugin-import-fsd
Advanced tools
ESLint plugin for following FSD methodology in imports and file locations
ESLint plugin for following Feature-Sliced Design methodology in imports and file locations. Compatible with FSD versions up to 2.
Contents:
Install eslint-plugin-import-fsd
to your repository as dev dependency:
npm install eslint-plugin-import-fsd --save-dev
pnpm install eslint-plugin-import-fsd --save-dev
yarn add eslint-plugin-import-fsd --dev
In your ESLint configuration file, add eslint-plugin-import-fsd
to the list of plugins:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
plugins: {
'import-fsd': importFsdPlugin,
},
},
];
Specify the directory where your FSD layers are located:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
plugins: {
'import-fsd': importFsdPlugin,
},
settings: {
fsd: {
rootDir: `${__dirname}/src`,
},
},
},
];
Configure the plugin rules or use the recommended configuration.
The plugin supports both the eslintrc configuration format and the flat configuration format. Example plugin configuration in eslintrc format:
/* .eslintrc.js */
module.exports = {
plugins: ['import-fsd'],
settings: {
fsd: {
rootDir: `${__dirname}/src`,
},
},
};
Defines a directory that follows the FSD methodology. If not specified, the root directory will default to the directory containing the ESLint configuration file or the path passed with the cwd
linter option.
The value must be an absolute path to a folder with the layers. Files and folders lying directly in this directory will be considered as layers.
For example, if your FSD layers are located in the src
folder in the same directory as the ESLint configuration file, the rootDir
option should be set as follows:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
settings: {
fsd: {
rootDir: `${__dirname}/src`,
},
},
},
];
Tells the plugin which aliases used in your project should be handled.
The path associated with an alias can be absolute or relative to the project root directory. Other values will not be resolved and will be used as is.
Alias patterns can contain the *
wildcard that matches any string. If it's present, the matching part will be substituted into the path associated with the alias.
If an import path matches multiple aliases, the first match will be applied.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
settings: {
fsd: {
rootDir: `${__dirname}/src`,
aliases: {
// @/features/foo/bar -> <__dirname>/src/features/foo/bar
'@/*': './src/*',
// foo -> <__dirname>/vendor/foo
foo: './vendor/foo',
// bar -> /bar
bar: '/bar',
// baz -> baz/qwe
// qux -> qwe/qwe
baz: 'baz/qwe',
'*': 'qwe/qwe',
qux: 'qux/qwe',
},
},
},
},
];
Assigns a layer and slice to a specified import path.
Once a layer and slice are assigned to an import path, it will be considered part of the project's FSD file structure.
Path patterns can contain the *
wildcard that matches any string.
If an import path matches multiple overrides, the first match will be applied.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
settings: {
fsd: {
overrides: {
// foo -> features/foo
foo: { layer: 'features', slice: 'foo' },
// bar/baz -> features/bar
'bar/*': { layer: 'features', slice: 'bar' },
// @baz -> features/qwe
'*': { layer: 'features', slice: 'qwe' },
'@baz': { layer: 'features', slice: 'baz' },
},
},
},
},
];
Prevents import from a denied layer for a current one.
FSD layers have the following hierarchy, in which the first layer having the highest rank and the last one has the lowest:
app
processes
(deprecated)pages
widgets
features
entities
shared
A module of each layer has access only to layers located strictly lower in the hierarchy:
Layer | Available layers |
---|---|
app | processes , pages , widgets , features , entities , shared |
processes | pages , widgets , features , entities , shared |
pages | widgets , features , entities , shared |
widgets | features , entities , shared |
features | entities , shared |
entities | shared |
shared | — |
Each segment module on a slice has access to other segments, but not to other slices on the same layer.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
plugins: {
'import-fsd': importFsdPlugin,
},
settings: {
fsd: {
rootDir: `${__dirname}/src`,
aliases: {
'@/*': './src/*',
},
},
},
rules: {
'import-fsd/no-denied-layers': 'error',
},
},
];
/* src/features/foo/bar/qwe.js */
// 📛 Error (denied layers)
import foo from '@/app/foo/bar';
import foo from '@/processes/foo/bar';
import foo from '@/pages/foo/bar';
import foo from '@/widgets/foo/bar';
// ✅ OK
import foo from '@/entities/foo/bar';
import foo from '@/shared/foo/bar';
// 📛 Error (denied slice)
import foo from '@/features/baz/qux';
// ✅ OK
import foo from '@/features/foo/qux';
ignores
- allows you to exclude the import from a listed layers from being checked by the rule.
Possible value is an array consisting of a layer names.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
// ...
rules: {
'import-fsd/no-denied-layers': [
'error',
{ ignores: ['pages', 'widgets'] },
],
},
},
];
/* src/widgets/foo/bar/qwe.js */
// ✅ OK
import foo from '@/pages/foo/bar'; // Ignored denied layer
import foo from '@/widgets/foo/baz'; // Ignored denied slice
Prevents import from deprecated layers.
Previous versions of FSD have different layer names. Version FSD 2 provides new naming:
Deprecated names | Recommended names |
---|---|
core , init | app (apps ) |
processes (process ), flows (flow ), workflows (workflow ) | app (apps ), features (feature ) |
screens (screen ), views (view ), layouts (layout ) | pages (page ) |
— | widgets (widget ) |
components (component ), containers (container ) | features (feature ) |
models (model ) | entities (entity ) |
common , lib (libs ) | shared |
If you are using FSD version 2.0.0 or higher, it's recommended to add this rule to your ESLint configuration to follow the new layer naming.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
plugins: {
'import-fsd': importFsdPlugin,
},
settings: {
fsd: {
rootDir: `${__dirname}/src`,
aliases: {
'@/*': './src/*',
},
},
},
rules: {
'import-fsd/no-deprecated-layers': 'error',
},
},
];
/* src/widgets/foo/bar/qwe.js */
// 📛 Error
import foo from '@/components/foo/bar';
import foo from '@/models/foo/bar';
import foo from '@/lib/foo/bar';
// ✅ OK
import foo from '@/features/foo/bar';
import foo from '@/entities/foo/bar';
import foo from '@/shared/foo/bar';
scope
- defines the target scope of the rule check.
Possible values:
import
- the rule will only check importsfile
- the rule will only check files to see if they are in a deprecated layerall
(default) - the rule will check both imports and filesignores
- allows you to exclude the import from a listed layers from being checked by the rule.
Possible value is an array consisting of a layer names.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
// ...
rules: {
'import-fsd/no-deprecated-layers': [
'error',
{ ignores: ['components', 'models'] },
],
},
},
];
/* src/widgets/foo/bar/qwe.js */
// ✅ OK
import foo from '@/components/foo/bar'; // Ignored deprecated layer
import foo from '@/models/foo/bar'; // Ignored deprecated layer
Prevents import from unknown layers.
The plugin supports layer naming corresponding to FSD version 2 and lower. Some layer names support both plural and singular.
Available layer names:
Deprecated names | Recommended names |
---|---|
core , init | app (apps ) |
processes (process ), flows (flow ), workflows (workflow ) | app (apps ), features (feature ) |
screens (screen ), views (view ), layouts (layout ) | pages (page ) |
— | widgets (widget ) |
components (component ), containers (container ) | features (feature ) |
models (model ) | entities (entity ) |
common , lib (libs ) | shared |
All other layer names are considered unknown.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
plugins: {
'import-fsd': importFsdPlugin,
},
settings: {
fsd: {
rootDir: `${__dirname}/src`,
aliases: {
'@/*': './src/*',
},
},
},
rules: {
'import-fsd/no-unknown-layers': 'error',
},
},
];
/* src/widgets/foo/bar/qwe.js */
// 📛 Error
import foo from '@/qwe/foo/bar';
import foo from '@/some-feature/foo/bar';
import foo from '@/cores/foo/bar';
// ✅ OK
import foo from '@/feature/foo/bar';
import foo from '@/features/foo/bar';
import foo from '@/entities/foo/bar';
scope
- defines the target scope of the rule check.
Possible values:
import
- the rule will only check importsfile
- the rule will only check files to see if they are in an unknown layerall
(default) - the rule will check both imports and filesignores
- allows you to exclude the import from a listed layers from being checked by the rule.
Possible value is an array consisting of a layer names.
Example:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
{
// ...
rules: {
'import-fsd/no-unknown-layers': ['error', { ignores: ['qwe'] }],
},
},
];
/* src/widgets/foo/bar/qwe.js */
// ✅ OK
import foo from '@/qwe/foo/bar'; // Ignored unknown layer
Compatible with flat configuration format.
Contains recommended plugin rules configuration:
Rule | Severity | Options |
---|---|---|
no-denied-layers | error | — |
no-deprecated-layers | warn | — |
no-unknown-layers | error | — |
To include the recommended configuration in yours, you need to add it to the list of configurations in your ESLint configuration file:
/* eslint.config.js */
import importFsdPlugin from 'eslint-plugin-import-fsd';
export default [
importFsdPlugin.configs.recommended,
// ...
];
Compatible with eslintrc configuration format.
Contains recommended plugin rules configuration:
Rule | Severity | Options |
---|---|---|
no-denied-layers | error | — |
no-deprecated-layers | warn | — |
no-unknown-layers | error | — |
To include the recommended configuration in yours, you need to add plugin:import-fsd/recommended-legacy
to the list of extensions in your ESLint configuration file:
/* .eslintrc.js */
module.exports = {
extends: ['plugin:import-fsd/recommended-legacy'],
// ...
};
FAQs
ESLint plugin for following FSD methodology in imports and file locations
The npm package eslint-plugin-import-fsd receives a total of 11 weekly downloads. As such, eslint-plugin-import-fsd popularity was classified as not popular.
We found that eslint-plugin-import-fsd demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.