@sj_lk/eslint-plugin-sj-plugin 0.1.3 → 0.1.4
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.
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
4
4
|
|
|
5
5
|
const { isPathRelative } = require('../helpers')
|
|
6
|
+
const micromatch = require('micromatch')
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
meta: {
|
|
@@ -20,17 +21,22 @@ module.exports = {
|
|
|
20
21
|
alias: {
|
|
21
22
|
type: 'string',
|
|
22
23
|
description: 'alias for the rule',
|
|
24
|
+
},
|
|
25
|
+
testFilesPatterns: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
description: 'patterns to match test files',
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
}
|
|
26
31
|
], defaultOptions: [{alias: ''}],
|
|
27
32
|
messages: {
|
|
28
|
-
importProblem: 'Абсолютный импорт разрешен только из Public API (index.ts)'
|
|
33
|
+
importProblem: 'Абсолютный импорт разрешен только из Public API (index.ts)',
|
|
34
|
+
testImportProblem: 'Тестовые данные необходимо импортировать из publicAPI (testing.ts)'
|
|
29
35
|
},
|
|
30
36
|
},
|
|
31
37
|
|
|
32
38
|
create(context) {
|
|
33
|
-
const alias = context.options[0]
|
|
39
|
+
const { alias = '', testFilesPatterns = []} = context.options[0] ?? {}
|
|
34
40
|
|
|
35
41
|
const allowedLayers = {
|
|
36
42
|
'entities': 'entities',
|
|
@@ -48,6 +54,7 @@ module.exports = {
|
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
56
|
const segments = importTo.split('/')
|
|
57
|
+
|
|
51
58
|
const layer = segments[0]
|
|
52
59
|
|
|
53
60
|
if(!allowedLayers[layer]) {
|
|
@@ -55,14 +62,24 @@ module.exports = {
|
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
const isImportNotFromPublicApi = segments.length > 2
|
|
65
|
+
const isTestingPublicApi = segments[2] === 'testing' && segments.length < 4
|
|
58
66
|
|
|
59
|
-
if(isImportNotFromPublicApi) {
|
|
67
|
+
if(isImportNotFromPublicApi && !isTestingPublicApi) {
|
|
60
68
|
context.report({
|
|
61
69
|
node,
|
|
62
70
|
messageId: 'importProblem',
|
|
63
71
|
})
|
|
64
72
|
}
|
|
73
|
+
|
|
74
|
+
if(isTestingPublicApi) {
|
|
75
|
+
const currentFilePath = context.filename
|
|
76
|
+
const isCurrentFileTesting = testFilesPatterns.some(pattern => micromatch.isMatch(currentFilePath, pattern))
|
|
77
|
+
|
|
78
|
+
if(!isCurrentFileTesting) {
|
|
79
|
+
context.report({node, messageId: 'testImportProblem'})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
65
82
|
}
|
|
66
|
-
}
|
|
83
|
+
}
|
|
67
84
|
},
|
|
68
85
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sj_lk/eslint-plugin-sj-plugin",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "add import validation for testing files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslintplugin",
|
|
@@ -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": "^10.0.0",
|
|
28
28
|
"@eslint/js": "^10.0.1",
|
|
29
|
+
"eslint": "^10.0.0",
|
|
29
30
|
"eslint-doc-generator": "^2.0.0",
|
|
30
31
|
"eslint-plugin-eslint-plugin": "^7.3.2",
|
|
31
32
|
"eslint-plugin-n": "^17.0.0",
|