eslint-plugin-fsd-arch-validator
Version:
Validate whether module imports within your project meet the requirements of FSD architecture
82 lines (74 loc) • 2.85 kB
JavaScript
/**
* @fileoverview Imports from another modules may only be through an interface - public api
* @author demetrxx
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/import-from-public-api"),
RuleTester = require("eslint").RuleTester;
const ruleTester = new RuleTester({
parserOptions: {ecmaVersion: 6, sourceType: 'module'}
});
const aliasOptions = [
{
alias: '@'
}
]
ruleTester.run("public-api-imports", rule, {
valid: [
{
code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice'",
errors: [],
},
{
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
errors: [],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/dev'",
errors: [],
options: [{
alias: '@',
devFiles: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
}],
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/dev'",
errors: [],
options: [{
alias: '@',
devFiles: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
}],
}
],
invalid: [
{
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
errors: [{ message: "Imports from another modules should only be from public API (index.ts)."}],
options: aliasOptions,
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/dev/file.tsx'",
errors: [{message: 'Imports from another modules should only be from public API (index.ts).'}],
options: [{
alias: '@',
testFilesPatterns: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
}],
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/dev'",
errors: [{message: 'Imports from another modules should only be from public API (dev.ts).'}],
options: [{
alias: '@',
devFiles: ['**/*.test.ts', '**/*.test.ts', '**/StoreDecorator.tsx']
}],
}
],
});