eslint-plugin-path-checker-new 0.0.2 → 0.0.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.
- package/lib/rules/path-checker.js +32 -16
- package/package.json +1 -1
|
@@ -16,15 +16,29 @@ module.exports = {
|
|
|
16
16
|
url: null, // URL to the documentation page for this rule
|
|
17
17
|
},
|
|
18
18
|
fixable: null, // Or `code` or `whitespace`
|
|
19
|
-
schema: [
|
|
19
|
+
schema: [
|
|
20
|
+
{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
alias: {
|
|
24
|
+
type: "string",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
], // Add a schema if the rule has options
|
|
20
29
|
messages: {}, // Add messageId and message
|
|
21
30
|
},
|
|
22
31
|
|
|
23
32
|
create(context) {
|
|
33
|
+
const alias = context.options[0]?.alias || "";
|
|
34
|
+
|
|
35
|
+
console.log("alias", alias);
|
|
36
|
+
|
|
24
37
|
return {
|
|
25
38
|
ImportDeclaration(node) {
|
|
26
39
|
//example app/entities/Article
|
|
27
|
-
const
|
|
40
|
+
const value = node.source.value;
|
|
41
|
+
const importTo = alias ? value.replace(`${alias}/`, "") : value;
|
|
28
42
|
|
|
29
43
|
// example C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article'
|
|
30
44
|
const fromFilename = context.filename;
|
|
@@ -58,21 +72,23 @@ function shouldBeRelative(from, to) {
|
|
|
58
72
|
return false;
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
// example entities/Article'
|
|
62
75
|
const toArray = to.split("/");
|
|
63
|
-
const toLayer = toArray[0];
|
|
64
|
-
const toSlice = toArray[1];
|
|
76
|
+
const toLayer = toArray[0];
|
|
77
|
+
const toSlice = toArray[1];
|
|
65
78
|
|
|
66
79
|
if (!toLayer || !toSlice || !layers[toLayer]) {
|
|
67
80
|
return false;
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
const normalizedPath =
|
|
71
|
-
const projectFrom = normalizedPath.split("src")[1];
|
|
72
|
-
|
|
83
|
+
const normalizedPath = from.replace(/\\/g, "/");
|
|
84
|
+
const projectFrom = normalizedPath.split("/src/")[1];
|
|
85
|
+
|
|
86
|
+
if (!projectFrom) return false;
|
|
87
|
+
|
|
88
|
+
const fromArray = projectFrom.split("/");
|
|
73
89
|
|
|
74
|
-
const fromLayer = fromArray[
|
|
75
|
-
const fromSlice = fromArray[
|
|
90
|
+
const fromLayer = fromArray[0];
|
|
91
|
+
const fromSlice = fromArray[1];
|
|
76
92
|
|
|
77
93
|
if (!fromLayer || !fromSlice || !layers[fromLayer]) {
|
|
78
94
|
return false;
|
|
@@ -81,12 +97,12 @@ function shouldBeRelative(from, to) {
|
|
|
81
97
|
return fromSlice === toSlice && toLayer === fromLayer;
|
|
82
98
|
}
|
|
83
99
|
|
|
84
|
-
console.log(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
100
|
+
// console.log(
|
|
101
|
+
// shouldBeRelative(
|
|
102
|
+
// "C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article",
|
|
103
|
+
// "entities/Article/fasfasfas",
|
|
104
|
+
// ),
|
|
105
|
+
// );
|
|
90
106
|
// console.log(
|
|
91
107
|
// shouldBeRelative(
|
|
92
108
|
// "C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article",
|