eslint-plugin-forum-react
Advanced tools
Comparing version
@@ -7,3 +7,3 @@ "use strict"; | ||
meta: { | ||
type: null, // `problem`, `suggestion`, or `layout` | ||
type: null, | ||
docs: { | ||
@@ -13,15 +13,26 @@ description: "feature sliced relative path checker", | ||
recommended: false, | ||
url: null, // URL to the documentation page for this rule | ||
url: null, | ||
}, | ||
fixable: null, // Or `code` or `whitespace` | ||
schema: [], // Add a schema if the rule has options | ||
fixable: null, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
alias: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
create(context) { | ||
const alias = context.options[0]?.alias || ''; | ||
return { | ||
ImportDeclaration(node) { | ||
// example app/entities/Article | ||
const importTo = node.source.value; | ||
const value = node.source.value; | ||
const importTo = alias ? value.replace(`${alias}/`, '') : value; | ||
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article | ||
// example C:\Users\vld\Desktop\javascript\production_project\src\entities\Article | ||
const fromFilename = context.getFilename(); | ||
@@ -28,0 +39,0 @@ |
{ | ||
"name": "eslint-plugin-forum-react", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "plugin for forum-react-project", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -12,3 +12,3 @@ /** | ||
const rule = require("../../../lib/rules/path-checker"), | ||
RuleTester = require("eslint").RuleTester; | ||
RuleTester = require("eslint").RuleTester; | ||
@@ -20,6 +20,12 @@ | ||
const ruleTester = new RuleTester(); | ||
const ruleTester = new RuleTester({ | ||
parserOptions: {ecmaVersion: 6, sourceType: 'module'} | ||
}); | ||
ruleTester.run("path-checker", rule, { | ||
valid: [ | ||
// give me some code that won't trigger a warning | ||
{ | ||
filename: 'C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\Article', | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '../../model/slices/addCommentFormSlice';", | ||
errors: [], | ||
}, | ||
], | ||
@@ -29,6 +35,15 @@ | ||
{ | ||
code: "test", | ||
errors: [{ message: "Fill me in.", type: "Me too" }], | ||
filename: 'C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\Article', | ||
code: "import { addCommentFormActions, addCommentFormReducer } from 'entities/Article/model/slices/addCommentFormSlice';", | ||
errors: [{ message: "В рамках одного слайса все пути должны быть относительными"}], | ||
}, | ||
{ | ||
filename: 'C:\\Users\\vld\\Desktop\\javascript\\production_project\\src\\entities\\Article', | ||
code: "import { addCommentFormActions, addCommentFormReducer } from '@/entities/Article/model/slices/addCommentFormSlice';", | ||
errors: [{ message: "В рамках одного слайса все пути должны быть относительными"}], | ||
options: [{ | ||
alias: '@' | ||
}] | ||
}, | ||
], | ||
}); |
8967
13.64%149
21.14%