eslint-plugin-import-path-correct 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.
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ const path = require("path");
4
+
3
5
  /** @type {import('eslint').Rule.RuleModule} */
4
6
  module.exports = {
5
7
  meta: {
@@ -23,8 +25,48 @@ module.exports = {
23
25
  // example C:\Users\mivanov...\... .ts
24
26
  const fromFilename = context.filename;
25
27
 
26
- context.report(node, "ЛИНТЕР РУГАЕТСЯ!!!");
28
+ if (shouldBeRelative(fromFilename, importTo)) {
29
+ context.report(
30
+ node,
31
+ "В рамках одного слайса все пути должны быть относительными",
32
+ );
33
+ }
27
34
  },
28
35
  };
29
36
  },
30
37
  };
38
+
39
+ const layers = {
40
+ entities: "entities",
41
+ features: "features",
42
+ shared: "shared",
43
+ pages: "pages",
44
+ widgets: "widgets",
45
+ };
46
+
47
+ function isPathRelative(path) {
48
+ return path === "." || path.startsWith("./") || path.startsWith("../");
49
+ }
50
+
51
+ function shouldBeRelative(from, to) {
52
+ if (isPathRelative(to)) {
53
+ return false;
54
+ }
55
+
56
+ const toArray = to.split("/");
57
+ const toLayer = toArray[0];
58
+ const toSlice = toArray[1];
59
+
60
+ if (!toLayer || !toSlice || !layers[toLayer]) return false;
61
+
62
+ const normalizedPath = path.toNamespacedPath(from);
63
+ const projectFrom = normalizedPath.split("src")[1];
64
+ const fromArray = projectFrom.split("\\");
65
+
66
+ const fromLayer = fromArray[1];
67
+ const fromSlice = fromArray[2];
68
+
69
+ if (!fromSlice || !fromLayer || !layers[fromLayer]) return false;
70
+
71
+ return fromSlice === toSlice && toLayer === fromLayer;
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-import-path-correct",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "plugin for paths",
5
5
  "keywords": [
6
6
  "eslint",