eslint-plugin-big-react-app-plugin 0.2.4 → 0.2.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.
- package/lib/rules/path-checker.js +18 -4
- package/package.json +1 -1
- package/.history/lib/rules/layer-imports_20251101143845.js +0 -44
- package/.history/lib/rules/layer-imports_20251101144032.js +0 -106
- package/.history/lib/rules/layer-imports_20251101144044.js +0 -106
- package/.history/lib/rules/layer-imports_20251101144137.js +0 -106
- package/.history/lib/rules/layer-imports_20251101144214.js +0 -110
- package/.history/lib/rules/public-api-imports_20251028164625.js +0 -76
- package/.history/lib/rules/public-api-imports_20251028165757.js +0 -75
- package/.history/lib/rules/public-api-imports_20251028165803.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029144637.js +0 -74
- package/.history/lib/rules/public-api-imports_20251029144640.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029144926.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029144953.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029145009.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029145022.js +0 -75
- package/.history/lib/rules/public-api-imports_20251029145049.js +0 -75
- package/.history/lib/rules/public-api-imports_20251030070810.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030070822.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030072017.js +0 -77
- package/.history/lib/rules/public-api-imports_20251030072333.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030072413.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030072442.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030072512.js +0 -76
- package/.history/lib/rules/public-api-imports_20251030073010.js +0 -77
- package/.history/lib/rules/public-api-imports_20251030073013.js +0 -77
- package/.history/lib/rules/public-api-imports_20251030073246.js +0 -77
- package/.history/lib/rules/public-api-imports_20251205122825.js +0 -77
- package/.history/lib/rules/public-api-imports_20251205122909.js +0 -80
- package/.history/lib/rules/public-api-imports_20251205123003.js +0 -83
- package/.history/lib/rules/public-api-imports_20251205123008.js +0 -83
- package/.history/lib/rules/public-api-imports_20251205123034.js +0 -84
- package/.history/lib/rules/public-api-imports_20251205123130.js +0 -84
- package/.history/lib/rules/public-api-imports_20251205123148.js +0 -84
- package/.history/lib/rules/public-api-imports_20251205123152.js +0 -84
- package/.history/lib/rules/public-api-imports_20251205123439.js +0 -89
- package/.history/lib/rules/public-api-imports_20251205123459.js +0 -91
- package/.history/lib/rules/public-api-imports_20251205123526.js +0 -91
- package/.history/lib/rules/public-api-imports_20251205123607.js +0 -91
- package/.history/lib/rules/public-api-imports_20251205123716.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205123800.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124519.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124522.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124613.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124633.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124639.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205124641.js +0 -92
- package/.history/lib/rules/public-api-imports_20251205134735.js +0 -94
- package/.history/lib/rules/public-api-imports_20251205134740.js +0 -95
- package/.history/lib/rules/public-api-imports_20251205141848.js +0 -95
- package/.history/package_20251028164641.json +0 -33
- package/.history/package_20251028165941.json +0 -33
- package/.history/package_20251029164755.json +0 -33
- package/.history/package_20251030070953.json +0 -33
- package/.history/package_20251030073306.json +0 -33
- package/.history/package_20251102101931.json +0 -33
- package/.history/package_20251102101944.json +0 -33
- package/.history/package_20251205123841.json +0 -33
- package/.history/package_20251205124820.json +0 -33
- package/.history/package_20251205134812.json +0 -33
- package/.history/package_20251205141859.json +0 -33
- package/.history/tests/lib/rules/layer-imports_20251101143845.js +0 -31
- package/.history/tests/lib/rules/layer-imports_20251101144101.js +0 -77
- package/.history/tests/lib/rules/layer-imports_20251101144110.js +0 -81
- package/.history/tests/lib/rules/layer-imports_20251101144121.js +0 -83
- package/.history/tests/lib/rules/layer-imports_20251101144130.js +0 -97
- package/.history/tests/lib/rules/path-checker_19851026131459.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251029145043.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251029145120.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251029145122.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251029145130.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251029145140.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251030070901.js +0 -44
- package/.history/tests/lib/rules/path-checker_20251101143521.js +0 -34
- package/.history/tests/lib/rules/public-api-imports_20251028164324.js +0 -87
- package/.history/tests/lib/rules/public-api-imports_20251029145051.js +0 -87
- package/.history/tests/lib/rules/public-api-imports_20251029145116.js +0 -87
- package/.history/tests/lib/rules/public-api-imports_20251029145250.js +0 -87
- package/.history/tests/lib/rules/public-api-imports_20251029145328.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029145415.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029145417.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029145434.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029150710.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029150715.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029150734.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029150749.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029153345.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251029153548.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030070849.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030071316.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030071331.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030073042.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030073103.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030073107.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251030073112.js +0 -96
- package/.history/tests/lib/rules/public-api-imports_20251101143401.js +0 -95
- package/.history/tests/lib/rules/public-api-imports_20251101143431.js +0 -95
- package/.history/tests/lib/rules/public-api-imports_20251101143526.js +0 -87
|
@@ -37,7 +37,17 @@ module.exports = {
|
|
|
37
37
|
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
38
38
|
const fromFilename = context.getFilename();
|
|
39
39
|
if(shouldBeRelative(fromFilename, importTo)) {
|
|
40
|
-
context.report({node:
|
|
40
|
+
context.report({node:
|
|
41
|
+
node,
|
|
42
|
+
message: 'В рамках одного слайса все пути должны быть относительными'});
|
|
43
|
+
fix:(fixer)=>{
|
|
44
|
+
const normalizedPath = getNormalizedFilePath(fromFilename).split('/').slice(0, -1).join('/')//enteties/Article/Artcile.tsx файл в который делаем импорт и также убираем концовку
|
|
45
|
+
let relativePath = path.relative(normalizedPath, `/${importTo}`).split('\\').join('/')
|
|
46
|
+
if(!relativePath.startsWith('.')){
|
|
47
|
+
relativePath = './' + relativePath
|
|
48
|
+
}
|
|
49
|
+
return fixer.replaceText(node.source, `'${relativePath}'`)
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
};
|
|
@@ -51,7 +61,12 @@ const layers = {
|
|
|
51
61
|
"shared":"shared",
|
|
52
62
|
"widgets":"widgets",
|
|
53
63
|
}
|
|
54
|
-
|
|
64
|
+
function getNormalizedFilePath (){
|
|
65
|
+
const normalizationPath = path.toNamespacedPath(from);
|
|
66
|
+
const projFrom = normalizationPath.split('src')[1]
|
|
67
|
+
return projFrom.split('\\').join('/')
|
|
68
|
+
}
|
|
69
|
+
function shouldBeRelative (from, to){
|
|
55
70
|
if(isPathRelative(to)){
|
|
56
71
|
return false
|
|
57
72
|
}
|
|
@@ -64,8 +79,7 @@ const shouldBeRelative = (from, to)=>{
|
|
|
64
79
|
return false
|
|
65
80
|
}
|
|
66
81
|
//нормализуем путь
|
|
67
|
-
const
|
|
68
|
-
const projFrom = normalizationPath.split('src')[1]
|
|
82
|
+
const projFrom = getNormalizedFilePath(from)
|
|
69
83
|
const fromArray = projFrom.split('\\')
|
|
70
84
|
|
|
71
85
|
const fromLayer = fromArray[1];
|
package/package.json
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview The rule ensures that the layers above are not used in the layers below.
|
|
3
|
-
* @author vasilii
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Rule Definition
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = {
|
|
15
|
-
meta: {
|
|
16
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
-
docs: {
|
|
18
|
-
description: "The rule ensures that the layers above are not used in the layers below.",
|
|
19
|
-
category: "Fill me in",
|
|
20
|
-
recommended: false,
|
|
21
|
-
url: null, // URL to the documentation page for this rule
|
|
22
|
-
},
|
|
23
|
-
fixable: null, // Or `code` or `whitespace`
|
|
24
|
-
schema: [], // Add a schema if the rule has options
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
create(context) {
|
|
28
|
-
// variables should be defined here
|
|
29
|
-
|
|
30
|
-
//----------------------------------------------------------------------
|
|
31
|
-
// Helpers
|
|
32
|
-
//----------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
// any helper functions should go here or else delete this section
|
|
35
|
-
|
|
36
|
-
//----------------------------------------------------------------------
|
|
37
|
-
// Public
|
|
38
|
-
//----------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
// visitor functions for different types of nodes
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview The rule ensures that the layers above are not used in the layers below.
|
|
3
|
-
* @author vasilii
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Rule Definition
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = {
|
|
15
|
-
meta: {
|
|
16
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
-
docs: {
|
|
18
|
-
description: "saf",
|
|
19
|
-
category: "Fill me in",
|
|
20
|
-
recommended: false,
|
|
21
|
-
url: null, // URL to the documentation page for this rule
|
|
22
|
-
},
|
|
23
|
-
fixable: null, // Or `code` or `whitespace`
|
|
24
|
-
schema: [
|
|
25
|
-
{
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
alias: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
},
|
|
31
|
-
ignoreImportPatterns: {
|
|
32
|
-
type: 'array',
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
create(context) {
|
|
40
|
-
const layers = {
|
|
41
|
-
'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
42
|
-
'pages': ['widgets', 'features', 'shared', 'entities'],
|
|
43
|
-
'widgets': ['features', 'shared', 'entities'],
|
|
44
|
-
'features': ['shared', 'entities'],
|
|
45
|
-
'entities': ['shared', 'entities'],
|
|
46
|
-
'shared': ['shared'],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const availableLayers = {
|
|
50
|
-
'app': 'app',
|
|
51
|
-
'entities': 'entities',
|
|
52
|
-
'features': 'features',
|
|
53
|
-
'shared': 'shared',
|
|
54
|
-
'pages': 'pages',
|
|
55
|
-
'widgets': 'widgets',
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
|
|
60
|
-
|
|
61
|
-
const getCurrentFileLayer = () => {
|
|
62
|
-
const currentFilePath = context.getFilename();
|
|
63
|
-
|
|
64
|
-
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
65
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
66
|
-
const segments = projectPath?.split('\\')
|
|
67
|
-
|
|
68
|
-
return segments?.[1];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const getImportLayer = (value) => {
|
|
72
|
-
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
73
|
-
const segments = importPath?.split('/')
|
|
74
|
-
|
|
75
|
-
return segments?.[0]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
ImportDeclaration(node) {
|
|
80
|
-
const importPath = node.source.value
|
|
81
|
-
const currentFileLayer = getCurrentFileLayer()
|
|
82
|
-
const importLayer = getImportLayer(importPath)
|
|
83
|
-
|
|
84
|
-
if(isPathRelative(importPath)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const isIgnored = ignoreImportPatterns.some(pattern => {
|
|
93
|
-
return micromatch.isMatch(importPath, pattern)
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if(isIgnored) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if(!layers[currentFileLayer]?.includes(importLayer)) {
|
|
101
|
-
context.report(node, 'Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview The rule ensures that the layers above are not used in the layers below.
|
|
3
|
-
* @author vasilii
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Rule Definition
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = {
|
|
15
|
-
meta: {
|
|
16
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
-
docs: {
|
|
18
|
-
description: "saf",
|
|
19
|
-
category: "Fill me in",
|
|
20
|
-
recommended: false,
|
|
21
|
-
url: null, // URL to the documentation page for this rule
|
|
22
|
-
},
|
|
23
|
-
fixable: null, // Or `code` or `whitespace`
|
|
24
|
-
schema: [
|
|
25
|
-
{
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
alias: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
},
|
|
31
|
-
ignoreImportPatterns: {
|
|
32
|
-
type: 'array',
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
create(context) {
|
|
40
|
-
const layers = {
|
|
41
|
-
'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
42
|
-
'pages': ['widgets', 'features', 'shared', 'entities'],
|
|
43
|
-
'widgets': ['features', 'shared', 'entities'],
|
|
44
|
-
'features': ['shared', 'entities'],
|
|
45
|
-
'entities': ['shared', 'entities'],
|
|
46
|
-
'shared': ['shared'],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const availableLayers = {
|
|
50
|
-
'app': 'app',
|
|
51
|
-
'entities': 'entities',
|
|
52
|
-
'features': 'features',
|
|
53
|
-
'shared': 'shared',
|
|
54
|
-
'pages': 'pages',
|
|
55
|
-
'widgets': 'widgets',
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
|
|
60
|
-
|
|
61
|
-
const getCurrentFileLayer = () => {
|
|
62
|
-
const currentFilePath = context.getFilename();
|
|
63
|
-
|
|
64
|
-
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
65
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
66
|
-
const segments = projectPath?.split('\\')
|
|
67
|
-
|
|
68
|
-
return segments?.[1];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const getImportLayer = (value) => {
|
|
72
|
-
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
73
|
-
const segments = importPath?.split('/')
|
|
74
|
-
|
|
75
|
-
return segments?.[0]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
ImportDeclaration(node) {
|
|
80
|
-
const importPath = node.source.value
|
|
81
|
-
const currentFileLayer = getCurrentFileLayer()
|
|
82
|
-
const importLayer = getImportLayer(importPath)
|
|
83
|
-
|
|
84
|
-
if(isPathRelative(importPath)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const isIgnored = ignoreImportPatterns.some(pattern => {
|
|
93
|
-
return micromatch.isMatch(importPath, pattern)
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if(isIgnored) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if(!layers[currentFileLayer]?.includes(importLayer)) {
|
|
101
|
-
context.report(node, 'Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview The rule ensures that the layers above are not used in the layers below.
|
|
3
|
-
* @author vasilii
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Rule Definition
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = {
|
|
15
|
-
meta: {
|
|
16
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
17
|
-
docs: {
|
|
18
|
-
description: "saf",
|
|
19
|
-
category: "Fill me in",
|
|
20
|
-
recommended: false,
|
|
21
|
-
url: null, // URL to the documentation page for this rule
|
|
22
|
-
},
|
|
23
|
-
fixable: null, // Or `code` or `whitespace`
|
|
24
|
-
schema: [
|
|
25
|
-
{
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
alias: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
},
|
|
31
|
-
ignoreImportPatterns: {
|
|
32
|
-
type: 'array',
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
create(context) {
|
|
40
|
-
const layers = {
|
|
41
|
-
'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
42
|
-
'pages': ['widgets', 'features', 'shared', 'entities'],
|
|
43
|
-
'widgets': ['features', 'shared', 'entities'],
|
|
44
|
-
'features': ['shared', 'entities'],
|
|
45
|
-
'entities': ['shared', 'entities'],
|
|
46
|
-
'shared': ['shared'],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const availableLayers = {
|
|
50
|
-
'app': 'app',
|
|
51
|
-
'entities': 'entities',
|
|
52
|
-
'features': 'features',
|
|
53
|
-
'shared': 'shared',
|
|
54
|
-
'pages': 'pages',
|
|
55
|
-
'widgets': 'widgets',
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
|
|
60
|
-
|
|
61
|
-
const getCurrentFileLayer = () => {
|
|
62
|
-
const currentFilePath = context.getFilename();
|
|
63
|
-
|
|
64
|
-
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
65
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
66
|
-
const segments = projectPath?.split('\\')
|
|
67
|
-
|
|
68
|
-
return segments?.[1];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const getImportLayer = (value) => {
|
|
72
|
-
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
73
|
-
const segments = importPath?.split('/')
|
|
74
|
-
|
|
75
|
-
return segments?.[0]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
ImportDeclaration(node) {
|
|
80
|
-
const importPath = node.source.value
|
|
81
|
-
const currentFileLayer = getCurrentFileLayer()
|
|
82
|
-
const importLayer = getImportLayer(importPath)
|
|
83
|
-
|
|
84
|
-
if(isPathRelative(importPath)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const isIgnored = ignoreImportPatterns.some(pattern => {
|
|
93
|
-
return micromatch.isMatch(importPath, pattern)
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if(isIgnored) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if(!layers[currentFileLayer]?.includes(importLayer)) {
|
|
101
|
-
context.report(node, 'Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview The rule ensures that the layers above are not used in the layers below.
|
|
3
|
-
* @author vasilii
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
//------------------------------------------------------------------------------
|
|
8
|
-
// Rule Definition
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {import('eslint').Rule.RuleModule}
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const path = require('path');
|
|
16
|
-
const {isPathRelative} = require('../helpers');
|
|
17
|
-
const micromatch = require('micromatch');
|
|
18
|
-
module.exports = {
|
|
19
|
-
meta: {
|
|
20
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
21
|
-
docs: {
|
|
22
|
-
description: "saf",
|
|
23
|
-
category: "Fill me in",
|
|
24
|
-
recommended: false,
|
|
25
|
-
url: null, // URL to the documentation page for this rule
|
|
26
|
-
},
|
|
27
|
-
fixable: null, // Or `code` or `whitespace`
|
|
28
|
-
schema: [
|
|
29
|
-
{
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
alias: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
},
|
|
35
|
-
ignoreImportPatterns: {
|
|
36
|
-
type: 'array',
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
create(context) {
|
|
44
|
-
const layers = {
|
|
45
|
-
'app': ['pages', 'widgets', 'features', 'shared', 'entities'],
|
|
46
|
-
'pages': ['widgets', 'features', 'shared', 'entities'],
|
|
47
|
-
'widgets': ['features', 'shared', 'entities'],
|
|
48
|
-
'features': ['shared', 'entities'],
|
|
49
|
-
'entities': ['shared', 'entities'],
|
|
50
|
-
'shared': ['shared'],
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const availableLayers = {
|
|
54
|
-
'app': 'app',
|
|
55
|
-
'entities': 'entities',
|
|
56
|
-
'features': 'features',
|
|
57
|
-
'shared': 'shared',
|
|
58
|
-
'pages': 'pages',
|
|
59
|
-
'widgets': 'widgets',
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const {alias = '', ignoreImportPatterns = []} = context.options[0] ?? {};
|
|
64
|
-
|
|
65
|
-
const getCurrentFileLayer = () => {
|
|
66
|
-
const currentFilePath = context.getFilename();
|
|
67
|
-
|
|
68
|
-
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
69
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
70
|
-
const segments = projectPath?.split('\\')
|
|
71
|
-
|
|
72
|
-
return segments?.[1];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const getImportLayer = (value) => {
|
|
76
|
-
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
77
|
-
const segments = importPath?.split('/')
|
|
78
|
-
|
|
79
|
-
return segments?.[0]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
ImportDeclaration(node) {
|
|
84
|
-
const importPath = node.source.value
|
|
85
|
-
const currentFileLayer = getCurrentFileLayer()
|
|
86
|
-
const importLayer = getImportLayer(importPath)
|
|
87
|
-
|
|
88
|
-
if(isPathRelative(importPath)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if(!availableLayers[importLayer] || !availableLayers[currentFileLayer]) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const isIgnored = ignoreImportPatterns.some(pattern => {
|
|
97
|
-
return micromatch.isMatch(importPath, pattern)
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if(isIgnored) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if(!layers[currentFileLayer]?.includes(importLayer)) {
|
|
105
|
-
context.report(node, 'Слой может импортировать в себя только нижележащие слои (shared, entities, features, widgets, pages, app)');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const micromatch = require("micromatch");
|
|
3
|
-
const {isPathRelative} = require("../helpers")
|
|
4
|
-
const path = require("path");
|
|
5
|
-
module.exports = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: null,
|
|
8
|
-
docs: {
|
|
9
|
-
description: "description",
|
|
10
|
-
category: "Fill me in",
|
|
11
|
-
recommended: false,
|
|
12
|
-
url: null,
|
|
13
|
-
},
|
|
14
|
-
fixable: null,
|
|
15
|
-
schema: [
|
|
16
|
-
{
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
alias: {
|
|
20
|
-
type: 'string'
|
|
21
|
-
},
|
|
22
|
-
testFilesPatterns: {
|
|
23
|
-
type: 'array'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
create(context) {
|
|
32
|
-
const checkingLayers = {
|
|
33
|
-
"entities":"entities",
|
|
34
|
-
"features":"features",
|
|
35
|
-
"pages":"pages",
|
|
36
|
-
"widgets":"widgets",
|
|
37
|
-
}
|
|
38
|
-
const {alias='', testFilesPatterns=[]} = context.options[0] ?? {};
|
|
39
|
-
return {
|
|
40
|
-
ImportDeclaration(node) {
|
|
41
|
-
// example app/entities/Article
|
|
42
|
-
const value = node.source.value;
|
|
43
|
-
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
44
|
-
//если путь относительный то выходим
|
|
45
|
-
if(isPathRelative(importTo)){
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
//[enteties, article, ... далее еще что-то может быть]
|
|
49
|
-
const segments = importTo.split('/')
|
|
50
|
-
const layer = segments[0]//получаем слой
|
|
51
|
-
// проверяем что есть слой из массива
|
|
52
|
-
|
|
53
|
-
//[enteties, article, testing]
|
|
54
|
-
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
55
|
-
|
|
56
|
-
if(!checkingLayers[layer]){
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const isImportNotFromPublicApi = segments.length > 2;
|
|
60
|
-
|
|
61
|
-
if(isImportNotFromPublicApi && !isTestingPublicApi ) {
|
|
62
|
-
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if(isTestingPublicApi){
|
|
66
|
-
const currentFilePath = context.getFilename();
|
|
67
|
-
const normalizedPath = path.toNamespacedPath(currentFilePath);
|
|
68
|
-
const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
|
|
69
|
-
if(!isCurrentFileTesting){
|
|
70
|
-
context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const micromatch = require("micromatch");
|
|
3
|
-
const {isPathRelative} = require("../helpers")
|
|
4
|
-
const path = require("path");
|
|
5
|
-
module.exports = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: null,
|
|
8
|
-
docs: {
|
|
9
|
-
description: "description",
|
|
10
|
-
category: "Fill me in",
|
|
11
|
-
recommended: false,
|
|
12
|
-
url: null,
|
|
13
|
-
},
|
|
14
|
-
fixable: null,
|
|
15
|
-
schema: [
|
|
16
|
-
{
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
alias: {
|
|
20
|
-
type: 'string'
|
|
21
|
-
},
|
|
22
|
-
testFilesPatterns: {
|
|
23
|
-
type: 'array'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
create(context) {
|
|
32
|
-
const checkingLayers = {
|
|
33
|
-
"entities":"entities",
|
|
34
|
-
"features":"features",
|
|
35
|
-
"pages":"pages",
|
|
36
|
-
"widgets":"widgets",
|
|
37
|
-
}
|
|
38
|
-
const {alias='', testFilesPatterns=[]} = context.options[0] ?? {};
|
|
39
|
-
return {
|
|
40
|
-
ImportDeclaration(node) {
|
|
41
|
-
// example app/entities/Article
|
|
42
|
-
const value = node.source.value;
|
|
43
|
-
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
44
|
-
//если путь относительный то выходим
|
|
45
|
-
if(isPathRelative(importTo)){
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
//[enteties, article, ... далее еще что-то может быть]
|
|
49
|
-
const segments = importTo.split('/')
|
|
50
|
-
const layer = segments[0]//получаем слой
|
|
51
|
-
// проверяем что есть слой из массива
|
|
52
|
-
|
|
53
|
-
//[enteties, article, testing]
|
|
54
|
-
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
55
|
-
|
|
56
|
-
if(!checkingLayers[layer]){
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const isImportNotFromPublicApi = segments.length > 2;
|
|
60
|
-
|
|
61
|
-
if(isImportNotFromPublicApi && !isTestingPublicApi ) {
|
|
62
|
-
context.report({node: node, message: 'Абсолютный импорт разрешен только из Public API (index.ts)'});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if(isTestingPublicApi){
|
|
66
|
-
const currentFilePath = context.getFilename();
|
|
67
|
-
const isCurrentFileTesting = testFilesPatterns.some(pattern=>micromatch.isMatch(normalizedPath, pattern))
|
|
68
|
-
if(!isCurrentFileTesting){
|
|
69
|
-
context.report({node: node, message: 'Тестовые данные необходимо импортировать из publicApi/testing.ts'});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
};
|