ESLint plugin for FSD architecture
npm install eslint-plugin-fsd-litebash
npm install --save-dev eslint-plugin-fsd-lite
`
Configuration
Add the plugin to your ESLint configuration:
`javascript
// .eslintrc.js
const fsdLitePlugin = require('eslint-plugin-fsd-lite');
module.exports = {
plugins: {
fsd: fsdLitePlugin,
},
rules: {
'fsd/no-fsd-imports': ['error', {
aliases: ['@'] // your path aliases
}],
},
};
`
Rule:
no-fsd-imports
This rule enforces the FSD dependency flow between layers:
#### Layer Dependency Rules
- app → can import from any layer
- widgets → can import from: features, entities, shared
- features → can import from: entities, shared
- entities → can import from: shared
- shared → can import from: shared only
Allowed Local Imports
Local imports within the same feature/slice are always allowed:
- ../feature/constants
- ./components
- Any relative path within the same architectural slice
Options
`javascript
{
aliases?: string[]; // array of path alias prefixes (e.g., ['@', '~'])
}
`
Usage Examples
$3
`javascript
// app → any layer (allowed)
import { Button } from '@/shared/ui';
import { UserCard } from '@/entities/user';
import { AuthForm } from '@/features/auth';
import { Header } from '@/widgets/header';
// widgets → features, entities, shared (allowed)
import { authApi } from '@/features/auth';
import { userModel } from '@/entities/user';
import { Input } from '@/shared/ui';
// features → entities, shared (allowed)
import { userModel } from '@/entities/user';
import { api } from '@/shared/api';
// entities → shared (allowed)
import { api } from '@/shared/api';
// shared → shared (allowed)
import { lib } from '@/shared/lib';
// Local imports within same slice (always allowed)
import { constants } from '../constants';
import { utils } from './utils';
`
$3
`javascript
// widgets → app (forbidden)
import { store } from '@/app/store';
// features → widgets, app (forbidden)
import { Header } from '@/widgets/header';
import { config } from '@/app/config';
// entities → features, widgets, app (forbidden)
import { authApi } from '@/features/auth';
import { Sidebar } from '@/widgets/sidebar';
import { router } from '@/app/router';
// shared → entities, features, widgets, app (forbidden)
import { userModel } from '@/entities/user';
import { AuthForm } from '@/features/auth';
`
Example Configuration
`javascript
// .eslintrc.js
module.exports = {
plugins: {
fsd: require('eslint-plugin-fsd-lite'),
},
rules: {
'fsd/no-fsd-imports': ['error', {
aliases: ['@', '~', '@/'] // multiple aliases supported
}],
},
};
``