🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-forum-react

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-forum-react - npm Package Compare versions

Comparing version

to
0.0.5

21

lib/rules/public-api-imports.js
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 @@ };

3

package.json
{
"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'],
}],
},
],
});