eslint-plugin-gapone-plugin 0.0.14 → 0.3.15
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,104 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { isPathRelative } = require('../helpers');
|
|
3
|
+
const micromatch = require('micromatch');
|
|
4
|
+
|
|
5
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem', // `problem`, `suggestion`, or `layout`
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'desc',
|
|
11
|
+
recommended: false,
|
|
12
|
+
url: null, // URL to the documentation page for this rule
|
|
13
|
+
},
|
|
14
|
+
fixable: null, // Or `code` or `whitespace`
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
alias: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
},
|
|
22
|
+
ignoreImportPatterns: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
], // Add a schema if the rule has options
|
|
28
|
+
messages: {
|
|
29
|
+
invalidLayerImport:
|
|
30
|
+
'Слой может импортировать в себя только нижележащие слои(pages, widgets, features, shared, entities)',
|
|
31
|
+
}, // Add messageId and message
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
create(context) {
|
|
35
|
+
const layers = {
|
|
36
|
+
app: ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
37
|
+
pages: ['widgets', 'features', 'shared', 'entities'],
|
|
38
|
+
widgets: ['features', 'shared', 'entities'],
|
|
39
|
+
features: ['shared', 'entities'],
|
|
40
|
+
entities: ['shared', 'entities'],
|
|
41
|
+
shared: ['shared'],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const avalibaleLayers = {
|
|
45
|
+
app: 'app',
|
|
46
|
+
pages: 'pages',
|
|
47
|
+
widgets: 'widgets',
|
|
48
|
+
features: 'features',
|
|
49
|
+
entities: 'entities',
|
|
50
|
+
shared: 'shared',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const { alias = '', ignoreImportPatterns = [] } =
|
|
54
|
+
context.options[0] ?? {};
|
|
55
|
+
|
|
56
|
+
const getCurrentFileLayer = () => {
|
|
57
|
+
const currentFilePath = context.filename;
|
|
58
|
+
|
|
59
|
+
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
60
|
+
const projectPath = normalizedPath?.split('src')[1];
|
|
61
|
+
const segments = projectPath?.split('\\');
|
|
62
|
+
|
|
63
|
+
return segments?.[1];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getImportLayer = (value) => {
|
|
67
|
+
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
68
|
+
const segments = importPath?.split('/');
|
|
69
|
+
|
|
70
|
+
return segments?.[0];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
ImportDeclaration(node) {
|
|
75
|
+
const importPath = node.source.value;
|
|
76
|
+
const currentFileLayer = getCurrentFileLayer();
|
|
77
|
+
const importLayer = getImportLayer(importPath);
|
|
78
|
+
|
|
79
|
+
if (isPathRelative(importPath)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
!avalibaleLayers[importLayer] ||
|
|
85
|
+
!avalibaleLayers[currentFileLayer]
|
|
86
|
+
) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const isIgnored = ignoreImportPatterns.some((pattern) => {
|
|
91
|
+
return micromatch.isMatch(importPath, pattern);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (isIgnored) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!layers[currentFileLayer]?.includes(importLayer)) {
|
|
99
|
+
context.report({ node, messageId: 'invalidLayerImport' });
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
};
|
package/lib/rules/path-cheker.js
CHANGED
|
@@ -75,7 +75,6 @@ function shouldBeRelation(from, to) {
|
|
|
75
75
|
const normalizedPath = path.toNamespacedPath(from);
|
|
76
76
|
const projectFrom = normalizedPath.split('src')[1];
|
|
77
77
|
const fromArray = projectFrom.split('\\');
|
|
78
|
-
console.log(fromArray);
|
|
79
78
|
|
|
80
79
|
const fromLayer = fromArray[1];
|
|
81
80
|
const fromSlice = fromArray[2];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const { isPathRelative } = require('../helpers');
|
|
2
2
|
const micromatch = require('micromatch');
|
|
3
3
|
|
|
4
|
+
const PUBLIC_ERROR = 'PUBLIC_ERROR';
|
|
5
|
+
const TESTING_PUBLIC_ERROR = 'TESTING_PUBLIC_ERROR';
|
|
6
|
+
|
|
4
7
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
5
8
|
module.exports = {
|
|
6
9
|
meta: {
|
|
@@ -10,7 +13,7 @@ module.exports = {
|
|
|
10
13
|
recommended: false,
|
|
11
14
|
url: null, // URL to the documentation page for this rule
|
|
12
15
|
},
|
|
13
|
-
fixable:
|
|
16
|
+
fixable: 'code', // Or `code` or `whitespace`
|
|
14
17
|
schema: [
|
|
15
18
|
{
|
|
16
19
|
type: 'object',
|
|
@@ -25,9 +28,9 @@ module.exports = {
|
|
|
25
28
|
},
|
|
26
29
|
], // Add a schema if the rule has options
|
|
27
30
|
messages: {
|
|
28
|
-
|
|
31
|
+
[PUBLIC_ERROR]:
|
|
29
32
|
'Абсолютный импорт разрешен только из Public Api (index.ts)',
|
|
30
|
-
|
|
33
|
+
[TESTING_PUBLIC_ERROR]:
|
|
31
34
|
'Тестовые данные необходимо импортировать из Public Api (testing.ts)',
|
|
32
35
|
}, // Add messageId and message
|
|
33
36
|
},
|
|
@@ -53,8 +56,8 @@ module.exports = {
|
|
|
53
56
|
|
|
54
57
|
// [entities, article, model, types]
|
|
55
58
|
const segments = importTo.split('/');
|
|
56
|
-
|
|
57
59
|
const layer = segments[0];
|
|
60
|
+
const slice = segments[1];
|
|
58
61
|
|
|
59
62
|
if (!checkingLayers[layer]) {
|
|
60
63
|
return;
|
|
@@ -69,7 +72,13 @@ module.exports = {
|
|
|
69
72
|
if (isImportNotFromPublickApi && !isTestingPublickApi) {
|
|
70
73
|
context.report({
|
|
71
74
|
node,
|
|
72
|
-
messageId:
|
|
75
|
+
messageId: PUBLIC_ERROR,
|
|
76
|
+
fix: (fixer) => {
|
|
77
|
+
return fixer.replaceText(
|
|
78
|
+
node.source,
|
|
79
|
+
`'${alias}/${layer}/${slice}'`
|
|
80
|
+
);
|
|
81
|
+
},
|
|
73
82
|
});
|
|
74
83
|
}
|
|
75
84
|
|
|
@@ -84,7 +93,7 @@ module.exports = {
|
|
|
84
93
|
if (!isCurrentFileTesting) {
|
|
85
94
|
context.report({
|
|
86
95
|
node,
|
|
87
|
-
messageId:
|
|
96
|
+
messageId: TESTING_PUBLIC_ERROR,
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
}
|