eslint-plugin-import-path-correct 0.0.1 → 0.0.2
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 +34 -6
- package/package.json +1 -1
|
@@ -12,24 +12,44 @@ module.exports = {
|
|
|
12
12
|
url: null, // URL to the documentation page for this rule
|
|
13
13
|
},
|
|
14
14
|
fixable: null, // Or `code` or `whitespace`
|
|
15
|
-
schema: [
|
|
16
|
-
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: { alias: { type: "string", description: "some" } },
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
], // Add a schema if the rule has options
|
|
22
|
+
defaultOptions: [
|
|
23
|
+
{
|
|
24
|
+
// Add this property
|
|
25
|
+
alias: "", // Default value for alias
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
messages: {
|
|
29
|
+
relativePathRequired:
|
|
30
|
+
"В рамках одного слайса все пути должны быть относительными",
|
|
31
|
+
}, // Add messageId and message
|
|
17
32
|
},
|
|
18
33
|
|
|
19
34
|
create(context) {
|
|
35
|
+
const options = context.options[0] || {};
|
|
36
|
+
const alias = options.alias || "";
|
|
37
|
+
|
|
38
|
+
console.log("ALIAS", alias);
|
|
20
39
|
return {
|
|
21
40
|
ImportDeclaration(node) {
|
|
22
41
|
// app/entities/Article
|
|
23
|
-
const
|
|
42
|
+
const value = node.source.value;
|
|
43
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
24
44
|
|
|
25
45
|
// example C:\Users\mivanov...\... .ts
|
|
26
46
|
const fromFilename = context.filename;
|
|
27
47
|
|
|
28
48
|
if (shouldBeRelative(fromFilename, importTo)) {
|
|
29
|
-
context.report(
|
|
49
|
+
context.report({
|
|
30
50
|
node,
|
|
31
|
-
|
|
32
|
-
);
|
|
51
|
+
messageId: "relativePathRequired",
|
|
52
|
+
});
|
|
33
53
|
}
|
|
34
54
|
},
|
|
35
55
|
};
|
|
@@ -70,3 +90,11 @@ function shouldBeRelative(from, to) {
|
|
|
70
90
|
|
|
71
91
|
return fromSlice === toSlice && toLayer === fromLayer;
|
|
72
92
|
}
|
|
93
|
+
|
|
94
|
+
console.log(
|
|
95
|
+
shouldBeRelative(
|
|
96
|
+
"C:/User/src/pages/ArticlePage/ui/ArticlesPage",
|
|
97
|
+
|
|
98
|
+
"pages/ArticlePage/model/selectors/articlesPageSelector",
|
|
99
|
+
),
|
|
100
|
+
);
|