eslint-plugin-laygrd-plugin 0.0.7 → 0.0.8
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/README.md +6 -0
- package/docs/rules/layer-imports.md +35 -0
- package/lib/helpers/index.js +3 -0
- package/lib/rules/fsd-relative-path.js +91 -92
- package/lib/rules/layer-imports.js +111 -0
- package/lib/rules/public-api-imports.js +96 -96
- package/package.json +1 -1
- package/tests/lib/rules/layer-imports.js +77 -0
package/README.md
CHANGED
|
@@ -49,6 +49,12 @@ Then configure the rules you want to use under the rules section.
|
|
|
49
49
|
alias: '@',
|
|
50
50
|
testFilesPatterns: ['**/\*.test.*', '**/\*.stories.*', '**/StoreDecorator.tsx'],
|
|
51
51
|
}
|
|
52
|
+
],
|
|
53
|
+
"laygrd-plugin/layer-imports": ['error,
|
|
54
|
+
{
|
|
55
|
+
alias: '@',
|
|
56
|
+
ignoreImportPatterns: ['**/StoreProvider'],
|
|
57
|
+
}
|
|
52
58
|
]
|
|
53
59
|
}
|
|
54
60
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# checks import from layer to layer according to fsd (you can`t import from higher layer to lower in fsd) (`layer-imports`)
|
|
2
|
+
|
|
3
|
+
Please describe the origin of the rule here.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule aims to...
|
|
8
|
+
|
|
9
|
+
Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
|
|
13
|
+
// fill me in
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
|
|
21
|
+
// fill me in
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Options
|
|
26
|
+
|
|
27
|
+
If there are any options, describe them here. Otherwise, delete this section.
|
|
28
|
+
|
|
29
|
+
## When Not To Use It
|
|
30
|
+
|
|
31
|
+
Give a short description of when it would be appropriate to turn off this rule.
|
|
32
|
+
|
|
33
|
+
## Further Reading
|
|
34
|
+
|
|
35
|
+
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
|
package/lib/helpers/index.js
CHANGED
|
@@ -1,92 +1,91 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview check relative paths inside module
|
|
3
|
-
* @author laygrd
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview check relative paths inside module
|
|
3
|
+
* @author laygrd
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const { isPathRelative, normalizePathSeparators } = require('../helpers');
|
|
8
|
+
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
// Rule Definition
|
|
11
|
+
//------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
15
|
+
*/
|
|
16
|
+
module.exports = {
|
|
17
|
+
meta: {
|
|
18
|
+
// eslint-disable-next-line eslint-plugin/require-meta-type
|
|
19
|
+
type: null,
|
|
20
|
+
docs: {
|
|
21
|
+
description: "check relative paths inside module ",
|
|
22
|
+
category: "fsd",
|
|
23
|
+
recommended: false,
|
|
24
|
+
url: null,
|
|
25
|
+
},
|
|
26
|
+
fixable: null,
|
|
27
|
+
schema: [
|
|
28
|
+
{
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
alias: {
|
|
32
|
+
type: 'string'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
create(context) {
|
|
40
|
+
const alias = context.options[0]?.alias || '';
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
ImportDeclaration(node) {
|
|
44
|
+
const value = node.source.value;
|
|
45
|
+
|
|
46
|
+
// import from 'shared/Button/Button' <--- this path
|
|
47
|
+
const importSrc = alias ? value.replace(`${alias}/`, '') : value;
|
|
48
|
+
|
|
49
|
+
// location of file where current import statement is
|
|
50
|
+
const currentFileName = context.getFilename();
|
|
51
|
+
|
|
52
|
+
if (shouldPathBeRelative(currentFileName, importSrc)) {
|
|
53
|
+
context.report({node: node, message: 'Imports within the same module must be relative, according to FSD. '});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const layers = {
|
|
61
|
+
'pages':'pages',
|
|
62
|
+
'widgets':'widgets',
|
|
63
|
+
'features':'features',
|
|
64
|
+
'entities':'entities',
|
|
65
|
+
'shared':'shared',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const shouldPathBeRelative = (curFile, impSrc) => {
|
|
69
|
+
if (isPathRelative(impSrc)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const inpSrcArray = impSrc.split('/'); // entities/Profile/ui/ProfileCard -> [entities, Profile, ui, ProfileCard]
|
|
74
|
+
const inpSrcLayer = inpSrcArray[0]; // entities
|
|
75
|
+
const inpSrcSlice = inpSrcArray[1]; // Profile
|
|
76
|
+
|
|
77
|
+
if ( !inpSrcLayer || !inpSrcSlice || !layers[inpSrcLayer] ) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const normalizedPath = curFile.split('src')[1]; // 'C:\Users\rosti\Desktop\projects\blog-app\src\entities\Article\ui\ArticleList' -> \entities\Article\ui\ArticleList
|
|
82
|
+
const projectFileArray = normalizePathSeparators(normalizedPath).split('/'); // \entities\Article\ui\ArticleList -> [ '', 'entities', 'Article', 'ui', 'ArticleList' ]
|
|
83
|
+
const curFileLayer = projectFileArray[1]; // entities
|
|
84
|
+
const curFileSlice = projectFileArray[2]; // Article
|
|
85
|
+
|
|
86
|
+
if ( !curFileLayer || !curFileSlice || !layers[curFileLayer] ) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return inpSrcLayer === curFileLayer && inpSrcSlice === curFileSlice;
|
|
91
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview checks imports from layer to layer according to fsd rules (you cant't import into lower layer from higher)
|
|
3
|
+
* @author laygrd
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const micromatch = require('micromatch');
|
|
12
|
+
const { isPathRelative, normalizePathSeparators } = require('../helpers');
|
|
13
|
+
|
|
14
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
15
|
+
module.exports = {
|
|
16
|
+
meta: {
|
|
17
|
+
// eslint-disable-next-line eslint-plugin/require-meta-type
|
|
18
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
19
|
+
docs: {
|
|
20
|
+
description: "checks imports from layer to layer according to fsd rules (you cant't import into lower layer from higher)",
|
|
21
|
+
recommended: false,
|
|
22
|
+
url: null,
|
|
23
|
+
},
|
|
24
|
+
fixable: null, // Or `code` or `whitespace`
|
|
25
|
+
schema: [
|
|
26
|
+
{
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
alias: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
ignoreImportPatterns: {
|
|
33
|
+
type: 'array'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
messages: {},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
create(context) {
|
|
42
|
+
const layers = {
|
|
43
|
+
'app': ['shared', 'entities', 'features', 'widgets', 'pages'],
|
|
44
|
+
'pages': ['shared', 'entities', 'features', 'widgets'],
|
|
45
|
+
'widgets': ['shared', 'entities', 'features'],
|
|
46
|
+
'features': ['shared', 'entities'],
|
|
47
|
+
'entities': ['shared', 'entities'],
|
|
48
|
+
'shared': ['shared']
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const availableLayers = {
|
|
52
|
+
'app': 'app',
|
|
53
|
+
'pages': 'pages',
|
|
54
|
+
'widgets': 'widgets',
|
|
55
|
+
'features': 'features',
|
|
56
|
+
'entities': 'entities',
|
|
57
|
+
'shared': 'shared'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { alias = '', ignoreImportPatterns = [] } = context.options[0] || {};
|
|
61
|
+
|
|
62
|
+
const getCurrentFileLayer = () => {
|
|
63
|
+
const currentFilePath = context.getFilename();
|
|
64
|
+
|
|
65
|
+
const normalizedPath = normalizePathSeparators(currentFilePath);
|
|
66
|
+
const projectPath = normalizedPath?.split('src')[1];
|
|
67
|
+
const segments = projectPath.split('/');
|
|
68
|
+
|
|
69
|
+
return segments[1];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const getImportLayer = (value) => {
|
|
73
|
+
const importPath = alias ? value.replace(`${alias}/`, '') : value;
|
|
74
|
+
|
|
75
|
+
const segments = importPath?.split('/');
|
|
76
|
+
|
|
77
|
+
return segments?.[0];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
ImportDeclaration(node) {
|
|
83
|
+
const importPath = node.source.value;
|
|
84
|
+
|
|
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: node, message: 'Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
};
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview absolute imports allowed only from public api file (index.ts)
|
|
3
|
-
* @author laygrd
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
const { isPathRelative } = require('../helpers');
|
|
7
|
-
const micromatch = require('micromatch');
|
|
8
|
-
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
// Rule Definition
|
|
11
|
-
//------------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
/** @type {import('eslint').Rule.RuleModule} */
|
|
14
|
-
module.exports = {
|
|
15
|
-
meta: {
|
|
16
|
-
// eslint-disable-next-line eslint-plugin/require-meta-type
|
|
17
|
-
type: null, // `problem`, `suggestion`, or `layout`
|
|
18
|
-
docs: {
|
|
19
|
-
category: "fsd",
|
|
20
|
-
description: "absolute imports allowed only from public api file (index.ts)",
|
|
21
|
-
recommended: false,
|
|
22
|
-
url: null, // URL to the documentation page for this rule
|
|
23
|
-
},
|
|
24
|
-
fixable: null, // Or `code` or `whitespace`
|
|
25
|
-
schema: [
|
|
26
|
-
{
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
alias: {
|
|
30
|
-
type: 'string'
|
|
31
|
-
},
|
|
32
|
-
testFilesPatterns: {
|
|
33
|
-
type: 'array'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
], // Add a schema if the rule has options
|
|
38
|
-
messages: {}, // Add messageId and message
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
create(context) {
|
|
42
|
-
const { alias = '', testFilesPatterns = [] } = context.options[0] || {};
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
ImportDeclaration(node) {
|
|
46
|
-
const value = node.source.value;
|
|
47
|
-
|
|
48
|
-
// import from '@/features/Button/Button' --> import from 'features/Button/Button'
|
|
49
|
-
const importSrc = alias ? value.replace(`${alias}/`, '') : value;
|
|
50
|
-
|
|
51
|
-
// skipping relative paths like '../ui/Button/Button'
|
|
52
|
-
if (isPathRelative(importSrc)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const segments = importSrc.split('/');
|
|
57
|
-
|
|
58
|
-
// "import {...} from 'entities/article'" -> ['entities', 'article'] -> true
|
|
59
|
-
// "import {...} from 'entities/article/ui/articleCard/articleCard'" -> ['entities', 'article', 'ui', 'articleCard', 'articleCard'] -> false
|
|
60
|
-
const isImportNotFromPublicApi = segments.length > 2;
|
|
61
|
-
|
|
62
|
-
// "import {...} from 'entities/article/testing'" -> ['entities', 'article', 'testing'] -> true
|
|
63
|
-
// "import {...} from 'entities/article/lib/mockData'" -> ['entities', 'article', 'lib', 'mockData'] -> fasle
|
|
64
|
-
const isImportFromTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
65
|
-
|
|
66
|
-
// check only declared layers from project root
|
|
67
|
-
const layer = segments[0];
|
|
68
|
-
if (!layersToCheck[layer]) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isImportNotFromPublicApi && !isImportFromTestingPublicApi) {
|
|
73
|
-
context.report({node: node, message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (isImportFromTestingPublicApi) {
|
|
77
|
-
const currentFilePath = context.getFilename();
|
|
78
|
-
|
|
79
|
-
const isCurrentFileTesting = testFilesPatterns.some(
|
|
80
|
-
pattern => micromatch.isMatch( currentFilePath, pattern )
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
if (!isCurrentFileTesting) {
|
|
84
|
-
context.report({node: node, message: 'Test data can only be imported into test files via the testing public API (testing.ts, testing.js). '})
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const layersToCheck = {
|
|
93
|
-
'pages':'pages',
|
|
94
|
-
'widgets':'widgets',
|
|
95
|
-
'features':'features',
|
|
96
|
-
'entities':'entities',
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview absolute imports allowed only from public api file (index.ts)
|
|
3
|
+
* @author laygrd
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
const { isPathRelative, normalizePathSeparators } = require('../helpers');
|
|
7
|
+
const micromatch = require('micromatch');
|
|
8
|
+
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
// Rule Definition
|
|
11
|
+
//------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
14
|
+
module.exports = {
|
|
15
|
+
meta: {
|
|
16
|
+
// eslint-disable-next-line eslint-plugin/require-meta-type
|
|
17
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
18
|
+
docs: {
|
|
19
|
+
category: "fsd",
|
|
20
|
+
description: "absolute imports allowed only from public api file (index.ts)",
|
|
21
|
+
recommended: false,
|
|
22
|
+
url: null, // URL to the documentation page for this rule
|
|
23
|
+
},
|
|
24
|
+
fixable: null, // Or `code` or `whitespace`
|
|
25
|
+
schema: [
|
|
26
|
+
{
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
alias: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
testFilesPatterns: {
|
|
33
|
+
type: 'array'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
], // Add a schema if the rule has options
|
|
38
|
+
messages: {}, // Add messageId and message
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
create(context) {
|
|
42
|
+
const { alias = '', testFilesPatterns = [] } = context.options[0] || {};
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
ImportDeclaration(node) {
|
|
46
|
+
const value = node.source.value;
|
|
47
|
+
|
|
48
|
+
// import from '@/features/Button/Button' --> import from 'features/Button/Button'
|
|
49
|
+
const importSrc = alias ? value.replace(`${alias}/`, '') : value;
|
|
50
|
+
|
|
51
|
+
// skipping relative paths like '../ui/Button/Button'
|
|
52
|
+
if (isPathRelative(importSrc)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const segments = importSrc.split('/');
|
|
57
|
+
|
|
58
|
+
// "import {...} from 'entities/article'" -> ['entities', 'article'] -> true
|
|
59
|
+
// "import {...} from 'entities/article/ui/articleCard/articleCard'" -> ['entities', 'article', 'ui', 'articleCard', 'articleCard'] -> false
|
|
60
|
+
const isImportNotFromPublicApi = segments.length > 2;
|
|
61
|
+
|
|
62
|
+
// "import {...} from 'entities/article/testing'" -> ['entities', 'article', 'testing'] -> true
|
|
63
|
+
// "import {...} from 'entities/article/lib/mockData'" -> ['entities', 'article', 'lib', 'mockData'] -> fasle
|
|
64
|
+
const isImportFromTestingPublicApi = segments[2] === 'testing' && segments.length < 4;
|
|
65
|
+
|
|
66
|
+
// check only declared layers from project root
|
|
67
|
+
const layer = segments[0];
|
|
68
|
+
if (!layersToCheck[layer]) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isImportNotFromPublicApi && !isImportFromTestingPublicApi) {
|
|
73
|
+
context.report({node: node, message: 'Absolute imports should be only from module`s Public API (index.ts, index.js). '});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isImportFromTestingPublicApi) {
|
|
77
|
+
const currentFilePath = normalizePathSeparators(context.getFilename());
|
|
78
|
+
|
|
79
|
+
const isCurrentFileTesting = testFilesPatterns.some(
|
|
80
|
+
pattern => micromatch.isMatch( currentFilePath, pattern )
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if (!isCurrentFileTesting) {
|
|
84
|
+
context.report({node: node, message: 'Test data can only be imported into test files via the testing public API (testing.ts, testing.js). '})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const layersToCheck = {
|
|
93
|
+
'pages':'pages',
|
|
94
|
+
'widgets':'widgets',
|
|
95
|
+
'features':'features',
|
|
96
|
+
'entities':'entities',
|
|
97
97
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview checks imports from layer to layer according to fsd rules (you cant't import into lower layer from higher)
|
|
3
|
+
* @author laygrd
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const rule = require("../../../lib/rules/layer-imports"),
|
|
12
|
+
RuleTester = require("eslint").RuleTester;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Tests
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
const ruleTester = new RuleTester({
|
|
20
|
+
parserOptions: { ecmaVersion: 6, sourceType: 'module' }
|
|
21
|
+
});
|
|
22
|
+
ruleTester.run("layer-imports", rule, {
|
|
23
|
+
valid: [
|
|
24
|
+
{
|
|
25
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating.tsx',
|
|
26
|
+
code: "import { Button } from 'shared/ui/Button/Button.tsx'",
|
|
27
|
+
errors: [],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\features\\rateArticle\\ui\\ArticleRating.tsx',
|
|
31
|
+
code: "import { Article } from 'entities/Article'",
|
|
32
|
+
errors: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Profile\\ui\\ProfileCard.tsx',
|
|
36
|
+
code: "import { Popup } from '@/shared/ui/Popup'",
|
|
37
|
+
options: [{ alias: '@' }],
|
|
38
|
+
errors: []
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\ui\\Article.tsx',
|
|
42
|
+
code: "import { StoreProvider } from 'app/providers/StoreProvider'",
|
|
43
|
+
options: [{ ignoreImportPatterns: ['**/StoreProvider'] }],
|
|
44
|
+
errors: []
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\ui\\Textarea\\Textarea.tsx',
|
|
48
|
+
code: "import { useRef } from 'react'",
|
|
49
|
+
errors: []
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
|
|
53
|
+
invalid: [
|
|
54
|
+
{
|
|
55
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Rating.tsx',
|
|
56
|
+
code: "import { RatingCard } from 'features/rateArticle'",
|
|
57
|
+
errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\features\\rateArticle\\ui\\ArticleRating.tsx',
|
|
61
|
+
code: "import { ErrorBoundaryProvider } from 'app/providers/ErrorBoundary'",
|
|
62
|
+
errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\shared\\ui\\Popup.tsx',
|
|
66
|
+
code: "import { UserCard } from '@/entities/User'",
|
|
67
|
+
options: [{ alias: '@' }],
|
|
68
|
+
errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.']
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
filename: 'C:\\Users\\Desktop\\Projects\\blog_app\\src\\entities\\Article\\ui\\Article.tsx',
|
|
72
|
+
code: "import { SomeProvider } from 'app/providers/SomeProvider'",
|
|
73
|
+
options: [{ ignoreImportPatterns: ['**/StoreProvider'] }],
|
|
74
|
+
errors: ['Importing from higher-level layers into lower-level layers is prohibited according to the FSD.']
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|