eslint-plugin-path-checker-relative 0.0.5 → 0.0.7
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.
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
const path = require("path");
|
|
8
|
+
|
|
8
9
|
const isPathRelative = require("../helpers");
|
|
10
|
+
const micromatch = require("micromatch");
|
|
9
11
|
|
|
10
12
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
11
13
|
module.exports = {
|
|
@@ -24,23 +26,27 @@ module.exports = {
|
|
|
24
26
|
alias: {
|
|
25
27
|
type: "string",
|
|
26
28
|
},
|
|
29
|
+
testFilesPattern: {
|
|
30
|
+
type: "array",
|
|
31
|
+
},
|
|
27
32
|
},
|
|
28
33
|
},
|
|
29
34
|
],
|
|
30
35
|
messages: {
|
|
31
36
|
"Абсолютный импорт разрешен только из Public API (index.ts)":
|
|
32
37
|
"Абсолютный импорт разрешен только из Public API (index.ts)",
|
|
38
|
+
"Тестовые данные необходимо импортировать из publicApi/testing.ts":
|
|
39
|
+
"Тестовые данные необходимо импортировать из publicApi/testing.ts",
|
|
33
40
|
},
|
|
34
41
|
},
|
|
35
42
|
|
|
36
43
|
create(context) {
|
|
37
|
-
const alias = context.options[0]
|
|
44
|
+
const { alias = "", testFilesPattern = [] } = context.options[0] ?? {};
|
|
38
45
|
|
|
39
46
|
const checkingLayers = {
|
|
40
47
|
entities: "entities",
|
|
41
48
|
feature: "feature",
|
|
42
49
|
pages: "pages",
|
|
43
|
-
shared: "shared",
|
|
44
50
|
widgets: "widgets",
|
|
45
51
|
};
|
|
46
52
|
|
|
@@ -55,21 +61,40 @@ module.exports = {
|
|
|
55
61
|
|
|
56
62
|
const segment = importTo.split("/");
|
|
57
63
|
|
|
58
|
-
const layer = segment[0]
|
|
64
|
+
const layer = segment[0];
|
|
59
65
|
|
|
60
|
-
if(!checkingLayers[layer]) {
|
|
66
|
+
if (!checkingLayers[layer]) {
|
|
61
67
|
return;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
const isImportNotFromPublicApi = segment.length > 2;
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
const isTestingPublicApi =
|
|
73
|
+
segment[2] === "testing" && segment.length < 4;
|
|
74
|
+
|
|
75
|
+
if (isImportNotFromPublicApi && !isTestingPublicApi) {
|
|
67
76
|
context.report({
|
|
68
77
|
node,
|
|
69
78
|
messageId:
|
|
70
79
|
"Абсолютный импорт разрешен только из Public API (index.ts)",
|
|
71
80
|
});
|
|
72
81
|
}
|
|
82
|
+
|
|
83
|
+
if (isTestingPublicApi) {
|
|
84
|
+
const currentFilePath = context.filename;
|
|
85
|
+
|
|
86
|
+
const isCurrentFileTesting = testFilesPattern.some((pattern) =>
|
|
87
|
+
micromatch.isMatch(currentFilePath, pattern)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (!isCurrentFileTesting) {
|
|
91
|
+
context.report({
|
|
92
|
+
node,
|
|
93
|
+
messageId:
|
|
94
|
+
"Тестовые данные необходимо импортировать из publicApi/testing.ts",
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
73
98
|
},
|
|
74
99
|
};
|
|
75
100
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-path-checker-relative",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "plugin for production project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -21,6 +21,7 @@
|
|
|
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": {
|