eslint-plugin-path-supervisor
Version:
Plugin for checking the rules of absolute and relative paths in project
88 lines (79 loc) • 3.21 kB
JavaScript
/**
* @fileoverview descr
* @author timur
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/public-api-imports"),
RuleTester = require("eslint").RuleTester;
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
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/testing'",
errors: [],
options: [{
alias: '@',
testFilesPatterns: ['**/*.test.ts', '**/*.stories.tsx', '**/StoreDecorator.tsx']
}],
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
errors: [],
options: [{
alias: '@',
testFilesPatterns: ['**/*.test.ts', '**/*.stories.tsx', '**/StoreDecorator.tsx']
}],
}
],
invalid: [
{
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/file.ts'",
errors: [{ message: "Absolute import is only allowed from the Public API (index.ts)"}],
options: aliasOptions,
output: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
},
{
filename: 'C:\\Users\\maryna\\Desktop\\javascript\\production_project\\src\\shared\\config\\storybook\\StoreDecorator\\StoreDecorator.tsx',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx'",
errors: [{message: 'Absolute import is only allowed from the Public API (index.ts)'}],
options: [{
alias: '@',
testFilesPatterns: ['**/*.test.ts', '**/*.stories.tsx', '**/StoreDecorator.tsx']
}],
output: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article'",
},
{
filename: 'C:\\Users\\tim\\Desktop\\javascript\\production_project\\src\\entities\\forbidden.ts',
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing'",
errors: [{message: 'Test data needs to be imported from publicApi/testing.ts'}],
options: [{
alias: '@',
testFilesPatterns: ['**/*.test.ts', '**/*.stories.tsx', '**/StoreDecorator.tsx']
}],
}
],
});