eslint-plugin-fsd-architecture
Version:
ESlint plugin to comply with FSD (Feature Sliced Design) frontend architecture rules
89 lines (85 loc) • 2.97 kB
JavaScript
/**
* @fileoverview Rule for check imports from layers structure of FSD architecture
* @author Anatoly Ivashov
*/
const rule = require("../../../lib/rules/layer-imports"),
RuleTester = require("eslint").RuleTester;
const aliasOptions = [
{
alias: '@'
}
]
const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
});
ruleTester.run("layer-imports", rule, {
valid: [
{
filename: 'C:/Users/project/src/features/Article',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/shared/Button.tsx'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/features/Article',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/app/providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Article'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/widgets/pages',
code: "import { useLocation } from 'react-router-dom'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/app/providers',
code: "import { addCommentFormActions, addCommentFormReducer } from 'redux'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/index.tsx',
code: "import { StoreProvider } from '@/app/providers/StoreProvider';",
errors: [],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/entities/Article.tsx',
code: "import { StateSchema } from '@/app/providers/StoreProvider'",
errors: [],
options: [
{
alias: '@',
ignoreImportPatterns: ['**/StoreProvider']
}
],
},
],
invalid: [
{
filename: 'C:/Users/project/src/entities/providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/features/Article'",
errors: [{ message: "A layer can only import the underlying layers into itself. (app > pages > widgets > features > entities > shared)"}],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/features/providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Article'",
errors: [{ message: "A layer can only import the underlying layers into itself. (app > pages > widgets > features > entities > shared)"}],
options: aliasOptions,
},
{
filename: 'C:/Users/project/src/entities/providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Article'",
errors: [{ message: "A layer can only import the underlying layers into itself. (app > pages > widgets > features > entities > shared)"}],
options: aliasOptions,
},
],
});