eslint-plugin-big-react-app-plugin 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.history/lib/helpers/index_20251018092620.js +6 -0
- package/.history/lib/helpers/index_20251018092627.js +6 -0
- package/.history/lib/rules/public-api-imports_20251018092312.js +61 -0
- package/.history/lib/rules/public-api-imports_20251018092340.js +62 -0
- package/.history/package_20251018092723.json +32 -0
- package/lib/helpers/index.js +1 -1
- package/lib/rules/public-api-imports.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
alias: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
testFilesPatterns: {
|
|
21
|
+
type: 'array'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const checkingLayers = {
|
|
31
|
+
"entities":"entities",
|
|
32
|
+
"features":"features",
|
|
33
|
+
"pages":"pages",
|
|
34
|
+
"widgets":"widgets",
|
|
35
|
+
}
|
|
36
|
+
const alias = context.options[0]?.alias ?? "";
|
|
37
|
+
return {
|
|
38
|
+
ImportDeclaration(node) {
|
|
39
|
+
// example app/entities/Article
|
|
40
|
+
const value = node.source.value;
|
|
41
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
42
|
+
//если путь относительный то выходим
|
|
43
|
+
if(isPathRelative(importTo)){
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
47
|
+
const segments = importTo.split('/')
|
|
48
|
+
const layer = segments[0]//получаем слой
|
|
49
|
+
if(!checkingLayers[layer]){
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
54
|
+
|
|
55
|
+
if(isImportNotFromPublicApi) {
|
|
56
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const {isPathRelative} = require("../helpers")
|
|
3
|
+
module.exports = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: null,
|
|
6
|
+
docs: {
|
|
7
|
+
description: "description",
|
|
8
|
+
category: "Fill me in",
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null,
|
|
11
|
+
},
|
|
12
|
+
fixable: null,
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
alias: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
testFilesPatterns: {
|
|
21
|
+
type: 'array'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const checkingLayers = {
|
|
31
|
+
"entities":"entities",
|
|
32
|
+
"features":"features",
|
|
33
|
+
"pages":"pages",
|
|
34
|
+
"widgets":"widgets",
|
|
35
|
+
}
|
|
36
|
+
const alias = context.options[0]?.alias ?? "";
|
|
37
|
+
return {
|
|
38
|
+
ImportDeclaration(node) {
|
|
39
|
+
// example app/entities/Article
|
|
40
|
+
const value = node.source.value;
|
|
41
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
42
|
+
//если путь относительный то выходим
|
|
43
|
+
if(isPathRelative(importTo)){
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
//[enteties, article, ... далее еще что-то может быть]
|
|
47
|
+
const segments = importTo.split('/')
|
|
48
|
+
const layer = segments[0]//получаем слой
|
|
49
|
+
// проверяем что есть слой из массива
|
|
50
|
+
if(!checkingLayers[layer]){
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isImportNotFromPublicApi = segments.lenght > 2;
|
|
55
|
+
|
|
56
|
+
if(isImportNotFromPublicApi) {
|
|
57
|
+
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public Api(index.ts)'});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-big-react-app-plugin",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "plugin for prod proj",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin"
|
|
9
|
+
],
|
|
10
|
+
"author": "Vasilii",
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"test": "mocha tests --recursive"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"requireindex": "^1.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"eslint": "^8.0.1",
|
|
21
|
+
"eslint-plugin-eslint-plugin": "^4.0.1",
|
|
22
|
+
"eslint-plugin-node": "^11.1.0",
|
|
23
|
+
"mocha": "^9.1.3"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": "12.x || 14.x || >= 16"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"eslint": ">=6"
|
|
30
|
+
},
|
|
31
|
+
"license": "ISC"
|
|
32
|
+
}
|
package/lib/helpers/index.js
CHANGED
|
@@ -39,12 +39,14 @@ module.exports = {
|
|
|
39
39
|
// example app/entities/Article
|
|
40
40
|
const value = node.source.value;
|
|
41
41
|
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
42
|
+
//если путь относительный то выходим
|
|
42
43
|
if(isPathRelative(importTo)){
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
46
|
//[enteties, article, ... далее еще что-то может быть]
|
|
46
47
|
const segments = importTo.split('/')
|
|
47
48
|
const layer = segments[0]//получаем слой
|
|
49
|
+
// проверяем что есть слой из массива
|
|
48
50
|
if(!checkingLayers[layer]){
|
|
49
51
|
return;
|
|
50
52
|
}
|