eslint-plugin-path-checker-relative 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.
@@ -3,7 +3,7 @@
3
3
  * @author evgeniy
4
4
  */
5
5
  "use strict";
6
-
6
+ const path = require("path");
7
7
  //------------------------------------------------------------------------------
8
8
  // Rule Definition
9
9
  //------------------------------------------------------------------------------
@@ -28,10 +28,58 @@ module.exports = {
28
28
 
29
29
  const importTo = node.source.value;
30
30
 
31
- const getFilename = context.getFilename();
32
-
33
- context.report(node, 'Linter error !!!')
31
+ const fromFilename = context.getFilename();
32
+ if(shouldBeRelative(fromFilename, importTo)) {
33
+ context.report(node, 'В рамках одного слайса все пути должны быть относительными')
34
+ }
34
35
  }
35
36
  };
36
37
  },
37
38
  };
39
+
40
+
41
+ function isPathRelative(path) {
42
+ return path === '.' || path.startsWith('./') || path.startsWith('../');
43
+ }
44
+
45
+ const layers = {
46
+ 'entities': 'entities',
47
+ 'feature': 'feature',
48
+ 'pages': 'pages',
49
+ 'shared': 'shared',
50
+ 'widgets': 'widgets',
51
+ }
52
+
53
+ function shouldBeRelative(from, to) {
54
+
55
+ if(isPathRelative(to)) {
56
+ return false
57
+ }
58
+
59
+ const arrayTo = to.split('/');
60
+ const toLayer = arrayTo[0]; // entities
61
+ const toSlice = arrayTo[1]; // Article
62
+
63
+ if(!toLayer || !toSlice || !layers[toLayer]) {
64
+ return false
65
+ }
66
+
67
+ const normalizedPath = path.toNamespacedPath(from)
68
+ const projectFrom = normalizedPath.split('src')[1]
69
+
70
+ const fromArray = projectFrom.split('/')
71
+ const fromLayer = fromArray[1];
72
+ const fromSlice = fromArray[2];
73
+
74
+ if(!fromLayer || !fromSlice || !layers[fromSlice]) {
75
+ return false
76
+ }
77
+
78
+ return fromSlice === toSlice && toLayer === fromLayer
79
+
80
+ }
81
+
82
+ console.log(shouldBeRelative(
83
+ '/Users/shichkov.e.g/develop/AdvancedReact/src/features/AddCommentForm',
84
+ 'src/features/AddCommentForm'
85
+ ))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-path-checker-relative",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "plugin for production project",
5
5
  "keywords": [
6
6
  "eslint",