eslint-plugin-forum-react
Advanced tools
Comparing version
const {isPathRelative} = require("../helpers"); | ||
const micromatch = require('micromatch'); | ||
@@ -19,2 +20,5 @@ module.exports = { | ||
}, | ||
testFilesPatterns: { | ||
type: 'array', | ||
}, | ||
}, | ||
@@ -26,3 +30,3 @@ }, | ||
create(context) { | ||
const alias = context.options[0]?.alias || ''; | ||
const { alias = '', testFilesPatterns = [] } = context.options[0] ?? {}; | ||
@@ -54,6 +58,19 @@ const checkingLayers = { | ||
const isImportNotFromPublicApi = segments.length > 2; | ||
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4; | ||
if(isImportNotFromPublicApi) { | ||
if(isImportNotFromPublicApi && !isTestingPublicApi) { | ||
context.report(node, 'Абсолютный импорт разрешен только из Public API (index.ts)!'); | ||
} | ||
if(isTestingPublicApi) { | ||
const currentFilePath = context.getFilename(); | ||
const isCurrentFileTesting = testFilesPatterns.some( | ||
pattern => micromatch.isMatch(currentFilePath, pattern) | ||
) | ||
if(!isCurrentFileTesting) { | ||
context.report(node, 'Тестовые данные необходимо импортировать из Public API / testing.ts'); | ||
} | ||
} | ||
} | ||
@@ -60,0 +77,0 @@ }; |
{ | ||
"name": "eslint-plugin-forum-react", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "plugin for forum-react-project", | ||
@@ -21,2 +21,3 @@ "keywords": [ | ||
"dependencies": { | ||
"micromatch": "^4.0.5", | ||
"requireindex": "^1.2.0" | ||
@@ -23,0 +24,0 @@ }, |
@@ -39,3 +39,21 @@ /** | ||
options: aliasOptions, | ||
} | ||
}, | ||
{ | ||
filename: "C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\file.test.ts", | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing';", | ||
errors: [], | ||
options: [{ | ||
alias: '@', | ||
testFilesPatterns: ['**/*.test.ts', '**/*.stories.ts', '**/StoreDecorator.tsx'], | ||
}], | ||
}, | ||
{ | ||
filename: "C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx", | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing';", | ||
errors: [], | ||
options: [{ | ||
alias: '@', | ||
testFilesPatterns: ['**/*.test.ts', '**/*.stories.ts', '**/StoreDecorator.tsx'], | ||
}], | ||
}, | ||
], | ||
@@ -49,3 +67,21 @@ | ||
}, | ||
{ | ||
filename: "C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\StoreDecorator.tsx", | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing/file.tsx';", | ||
errors: [{message: "Абсолютный импорт разрешен только из Public API (index.ts)!"}], | ||
options: [{ | ||
alias: '@', | ||
testFilesPatterns: ['**/*.test.ts', '**/*.stories.ts', '**/StoreDecorator.tsx'], | ||
}], | ||
}, | ||
{ | ||
filename: "C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\forbiden.ts", | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/testing';", | ||
errors: [{message: "Тестовые данные необходимо импортировать из Public API / testing.ts"}], | ||
options: [{ | ||
alias: '@', | ||
testFilesPatterns: ['**/*.test.ts', '**/*.stories.ts', '**/StoreDecorator.tsx'], | ||
}], | ||
}, | ||
], | ||
}); |
14893
19.91%292
20.66%3
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added