@dword-design/eslint-plugin-import-alias 5.0.1 → 5.1.0

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/README.md CHANGED
@@ -125,6 +125,14 @@ If you have a special project setup that does not have a babel config in the pro
125
125
  }
126
126
  ```
127
127
 
128
+ By default, the plugin will convert parent paths to aliases (like `../model/foo`), but will keep subpath imports relative. You can change that to also convert subpaths to aliased imports by passing the `aliasForSubpaths` option to the rule like so:
129
+
130
+ ```json
131
+ "rules": {
132
+ "@dword-design/import-alias/prefer-alias": ["error", { "aliasForSubpaths": true }]
133
+ }
134
+ ```
135
+
128
136
  <!-- LICENSE/ -->
129
137
  ## Contribute
130
138
 
@@ -49,6 +49,7 @@ export default {
49
49
  var _sourcePath;
50
50
  return _sourcePath = sourcePath, startsWith(`${alias}/`)(_sourcePath);
51
51
  })(_ref));
52
+
52
53
  // relative parent
53
54
  if (_sourcePath2 = sourcePath, isParentImport(_sourcePath2)) {
54
55
  var _P$relative;
@@ -65,7 +66,7 @@ export default {
65
66
  });
66
67
  }
67
68
  const importWithoutAlias = resolvePath(sourcePath, currentFile, options);
68
- if (!(_importWithoutAlias = importWithoutAlias, isParentImport(_importWithoutAlias)) && hasAlias) {
69
+ if (!(_importWithoutAlias = importWithoutAlias, isParentImport(_importWithoutAlias)) && hasAlias && !options.allowSubpathWithAlias) {
69
70
  return context.report({
70
71
  fix: fixer => fixer.replaceTextRange([node.source.range[0] + 1, node.source.range[1] - 1], importWithoutAlias),
71
72
  message: `Unexpected subpath import via alias '${sourcePath}'. Use '${importWithoutAlias}' instead`,
@@ -83,6 +84,10 @@ export default {
83
84
  properties: {
84
85
  alias: {
85
86
  type: 'object'
87
+ },
88
+ aliasForSubpaths: {
89
+ default: false,
90
+ type: 'boolean'
86
91
  }
87
92
  },
88
93
  type: 'object'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dword-design/eslint-plugin-import-alias",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "An ESLint plugin that enforces the use of import aliases. Also supports autofixing.",
5
5
  "keywords": [
6
6
  "alias",
@@ -55,7 +55,7 @@
55
55
  "@dword-design/tester-plugin-tmp-dir": "^2.1.26",
56
56
  "depcheck-package-name": "^3.0.1",
57
57
  "eslint": "^8.0.0",
58
- "execa": "^8.0.0",
58
+ "execa": "^9.3.1",
59
59
  "fs-extra": "^11.1.1",
60
60
  "in-folder": "^1.0.3",
61
61
  "output-files": "^2.0.0"