eslint-plugin-zozu-plugin 0.0.4 → 0.0.6
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.
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {isPathRelative} = require('../helpers');
|
|
5
|
+
const micromatch = require("micromatch");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
10
|
+
docs: {
|
|
11
|
+
description: "description",
|
|
12
|
+
recommended: false,
|
|
13
|
+
url: null, // URL to the documentation page for this rule
|
|
14
|
+
},
|
|
15
|
+
fixable: null, // Or `code` or `whitespace`
|
|
16
|
+
schema: [
|
|
17
|
+
{
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
alias: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
},
|
|
23
|
+
ignoreFilesPatterns: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
messages: {}, // Add messageId and message
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
create(context) {
|
|
33
|
+
const layers = {
|
|
34
|
+
'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
35
|
+
'pages': ['widgets', 'features', 'shared', 'entities'],
|
|
36
|
+
'widgets': ['features', 'shared', 'entities'],
|
|
37
|
+
'features': ['shared', 'entities'],
|
|
38
|
+
'entities': ['shared', 'entities'],
|
|
39
|
+
'shared': ['shared'],
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const availableLayers = {
|
|
43
|
+
'app': 'app',
|
|
44
|
+
'entities': 'entities',
|
|
45
|
+
'features': 'features',
|
|
46
|
+
'shared': 'shared',
|
|
47
|
+
'pages': 'pages',
|
|
48
|
+
'widgets': 'widgets',
|
|
49
|
+
}
|
|
50
|
+
const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
|
|
51
|
+
|
|
52
|
+
const getCurrentFileLayer = () => {
|
|
53
|
+
const currentFilePath = context.getFilename();
|
|
54
|
+
|
|
55
|
+
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
56
|
+
const projectPath = normalizedPath?.split('src')[1];
|
|
57
|
+
const segments = projectPath?.split('\\');
|
|
58
|
+
|
|
59
|
+
return segments?.[1];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getImportLayer = (value) => {
|
|
63
|
+
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
64
|
+
const segments = importPath?.split('/');
|
|
65
|
+
|
|
66
|
+
return segments?.[0];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
ImportDeclaration(node) {
|
|
71
|
+
const importPath = node.source.value;
|
|
72
|
+
const currentFileLayer = getCurrentFileLayer();
|
|
73
|
+
const importLayer = getImportLayer(importPath);
|
|
74
|
+
|
|
75
|
+
if (isPathRelative(importPath)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const isIgnored = ignoreImportPatterns.some(pattern => {
|
|
84
|
+
return micromatch.isMatch(importPath, pattern);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (isIgnored) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!layers[currentFileLayer]?.includes(importLayer)) {
|
|
92
|
+
context.report({node: node, message: 'Слой может импортировать в себя только нижележащие слои (shared, enities, features, widgets, pages, app'});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {isPathRelative} = require('../helpers');
|
|
4
|
+
const micromatch = require("micromatch");
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
meta: {
|
|
@@ -17,6 +18,9 @@ module.exports = {
|
|
|
17
18
|
properties: {
|
|
18
19
|
alias: {
|
|
19
20
|
type: 'string',
|
|
21
|
+
},
|
|
22
|
+
testFilesPatterns: {
|
|
23
|
+
type: 'array',
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
}
|
|
@@ -25,7 +29,7 @@ module.exports = {
|
|
|
25
29
|
},
|
|
26
30
|
|
|
27
31
|
create(context) {
|
|
28
|
-
const alias = context.options[0]
|
|
32
|
+
const {alias = '', testFilesPatterns = []} = context.options[0] ?? {};
|
|
29
33
|
|
|
30
34
|
const checkingLayers = {
|
|
31
35
|
'entities': 'entities',
|
|
@@ -54,9 +58,21 @@ module.exports = {
|
|
|
54
58
|
}
|
|
55
59
|
const isImportNotFromPublicApi = segments.length > 2;
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
62
|
+
|
|
63
|
+
if (isImportNotFromPublicApi && !isTestingPublicApi) {
|
|
58
64
|
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
|
|
59
65
|
}
|
|
66
|
+
|
|
67
|
+
if (isTestingPublicApi) {
|
|
68
|
+
const currentFilePath = context.getFilename();
|
|
69
|
+
const isCurrentFileTesting = testFilesPatterns.some(
|
|
70
|
+
pattern => micromatch.isMatch(currentFilePath, pattern)
|
|
71
|
+
)
|
|
72
|
+
if (!isCurrentFileTesting) {
|
|
73
|
+
context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
60
76
|
}
|
|
61
77
|
};
|
|
62
78
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-zozu-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "plugin for my pet project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
"update:eslint-docs": "eslint-doc-generator"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"micromatch": "^4.0.8",
|
|
24
25
|
"requireindex": "^1.2.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"eslint": "^9.0.0",
|
|
28
28
|
"@eslint/js": "^9.0.0",
|
|
29
|
+
"eslint": "^9.0.0",
|
|
29
30
|
"eslint-doc-generator": "^2.0.0",
|
|
30
31
|
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
31
32
|
"eslint-plugin-n": "^17.0.0",
|