eslint-plugin-import-path-correct 0.0.6 → 0.0.7

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.
@@ -12,7 +12,7 @@ module.exports = {
12
12
  recommended: false,
13
13
  url: null, // URL to the documentation page for this rule
14
14
  },
15
- fixable: null, // Or `code` or `whitespace`
15
+ fixable: "code", // Or `code` or `whitespace`
16
16
  schema: [
17
17
  {
18
18
  type: "object",
@@ -50,6 +50,21 @@ module.exports = {
50
50
  context.report({
51
51
  node,
52
52
  messageId: "relativePathRequired",
53
+ fix: (fixer) => {
54
+ const normalizedPath = getNormalizedCurrentFilePath(fromFilename)
55
+ .split("/")
56
+ .slice(0, -1)
57
+ .join("/");
58
+ let relativePath = path
59
+ .relative(normalizedPath, `/${importTo}`)
60
+ .split("\\")
61
+ .join("/");
62
+
63
+ if (relativePath.startsWith(".")) {
64
+ relativePath = "./" + relativePath;
65
+ }
66
+ return fixer.replaceText(node.source, relativePath);
67
+ },
53
68
  });
54
69
  }
55
70
  },
@@ -65,6 +80,12 @@ const layers = {
65
80
  widgets: "widgets",
66
81
  };
67
82
 
83
+ function getNormalizedCurrentFilePath(currentFilePath) {
84
+ const normalizedPath = path.toNamespacedPath(currentFilePath);
85
+ const projectFrom = normalizedPath.split("src")[1];
86
+ return projectFrom.split("\\").join("/");
87
+ }
88
+
68
89
  function shouldBeRelative(from, to) {
69
90
  if (isPathRelative(to)) {
70
91
  return false;
@@ -76,9 +97,8 @@ function shouldBeRelative(from, to) {
76
97
 
77
98
  if (!toLayer || !toSlice || !layers[toLayer]) return false;
78
99
 
79
- const normalizedPath = path.toNamespacedPath(from);
80
- const projectFrom = normalizedPath.split("src")[1];
81
- const fromArray = projectFrom.split("\\");
100
+ const projectFrom = getNormalizedCurrentFilePath(from);
101
+ const fromArray = projectFrom.split("/");
82
102
 
83
103
  const fromLayer = fromArray[1];
84
104
  const fromSlice = fromArray[2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-import-path-correct",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "plugin for paths",
5
5
  "keywords": [
6
6
  "eslint",