eslint-plugin-fsd-lite
v1.0.9
Published
ESLint plugin for FSD architecture
Readme
ESLint Plugin FSD Lite
A lightweight ESLint plugin that enforces FSD (Feature-Sliced Design) architectural methodology by controlling import patterns between different layers of your application.
Installation
npm install --save-dev eslint-plugin-fsd-liteConfiguration
Add the plugin to your ESLint configuration:
// .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,sharedfeatures → can import from:
entities,sharedentities → can import from:
sharedshared → can import from:
sharedonly
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
{
aliases?: string[]; // array of path alias prefixes (e.g., ['@', '~'])
}Usage Examples
✅ Valid Imports
// 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';❌ Invalid Imports
// 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
// .eslintrc.js
module.exports = {
plugins: {
fsd: require('eslint-plugin-fsd-lite'),
},
rules: {
'fsd/no-fsd-imports': ['error', {
aliases: ['@', '~', '@/'] // multiple aliases supported
}],
},
};Why Use This Plugin?
Architectural Consistency: Ensures your project follows FSD principles
Maintainable Code: Prevents circular dependencies and tight coupling
Clear Boundaries: Enforces clear separation between business logic and presentation
Team Alignment: Helps teams follow consistent import patterns
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
