eslint-plugin-gapone-plugin 0.0.14 → 0.3.14
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/lib/rules/layer-imports.js +104 -0
- package/lib/rules/path-cheker.js +0 -1
- package/package.json +1 -1
|
@@ -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];
|