eslint-plugin-zozu-plugin 0.0.0 → 0.0.1
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 +47 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
2
4
|
module.exports = {
|
|
3
5
|
meta: {
|
|
4
6
|
type: null, // `problem`, `suggestion`, or `layout`
|
|
@@ -21,8 +23,52 @@ module.exports = {
|
|
|
21
23
|
// example D:/Alexandr/projects/pet-projects/src/index.tsx
|
|
22
24
|
const fromFilename = context.getFilename();
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
if (shouldBeRelative(fromFilename, importTo)) {
|
|
27
|
+
context.report({node: node, message: 'В рамках одного слайса пути должны быть относительные'});
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
};
|
|
27
31
|
},
|
|
28
32
|
};
|
|
33
|
+
|
|
34
|
+
function isPathRelative(path) {
|
|
35
|
+
return path === '.' || path.startsWith('./') || path.startsWith('../')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const layers = {
|
|
39
|
+
'entities': 'entities',
|
|
40
|
+
'features': 'features',
|
|
41
|
+
'shared': 'shared',
|
|
42
|
+
'pages': 'pages',
|
|
43
|
+
'widgets': 'widgets',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function shouldBeRelative(from, to) {
|
|
47
|
+
if (isPathRelative(to)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const toArray = to.split('/');
|
|
52
|
+
const toLayer = toArray[0];
|
|
53
|
+
const toSlice = toArray[1];
|
|
54
|
+
|
|
55
|
+
if(!toLayer || !toSlice || !layers[toLayer]) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const normalizedPath = path.toNamespacedPath(from);
|
|
60
|
+
const projectFrom = normalizedPath.split('src')[1];
|
|
61
|
+
const fromArray = projectFrom.split('\\');
|
|
62
|
+
|
|
63
|
+
const fromLayer = fromArray[1];
|
|
64
|
+
const fromSlice = fromArray[2];
|
|
65
|
+
|
|
66
|
+
if(!fromLayer || !fromSlice || !layers[fromLayer]) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return fromSlice === toSlice && toLayer === fromLayer;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log(path.toNamespacedPath('C:/Users/tim'));
|
|
74
|
+
console.log(path.toNamespacedPath('C:\\Users\\tim'));
|