eslint-plugin-path-supervisor
Version:
Plugin for checking the rules of absolute and relative paths in project
84 lines (81 loc) • 3.2 kB
JavaScript
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\\tim\\Desktop\\javascript\\production_project\\src\\features\\Article',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/shared/Button.tsx'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\features\\Article',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\app\\providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Articl'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\widgets\\pages',
code: "import { useLocation } from 'react-router-dom'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\app\\providers',
code: "import { addCommentFormActions, addCommentFormReducer } from 'redux'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\index.tsx',
code: "import { StoreProvider } from '@/app/providers/StoreProvider';",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\Article.tsx',
code: "import { StateSchema } from '@/app/providers/StoreProvider'",
errors: [],
options: [
{
alias: '@',
ignoreImportPatterns: ['**/StoreProvider']
}
],
},
],
invalid: [
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/features/Article'",
errors: [{ message: "A layer can only import underlying layers (shared, entities, features, widgets, pages, app)"}],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\features\\providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Article'",
errors: [{ message: "A layer can only import underlying layers (shared, entities, features, widgets, pages, app)"}],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\providers',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/widgets/Articl'",
errors: [{ message: "A layer can only import underlying layers (shared, entities, features, widgets, pages, app)"}],
options: aliasOptions,
},
],
});