@dword-design/eslint-plugin-import-alias 5.0.2 → 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 +8 -0
- package/dist/rules/prefer-alias.js +5 -1
- package/package.json +1 -1
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
|
|
|
@@ -66,7 +66,7 @@ export default {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
const importWithoutAlias = resolvePath(sourcePath, currentFile, options);
|
|
69
|
-
if (!(_importWithoutAlias = importWithoutAlias, isParentImport(_importWithoutAlias)) && hasAlias) {
|
|
69
|
+
if (!(_importWithoutAlias = importWithoutAlias, isParentImport(_importWithoutAlias)) && hasAlias && !options.allowSubpathWithAlias) {
|
|
70
70
|
return context.report({
|
|
71
71
|
fix: fixer => fixer.replaceTextRange([node.source.range[0] + 1, node.source.range[1] - 1], importWithoutAlias),
|
|
72
72
|
message: `Unexpected subpath import via alias '${sourcePath}'. Use '${importWithoutAlias}' instead`,
|
|
@@ -84,6 +84,10 @@ export default {
|
|
|
84
84
|
properties: {
|
|
85
85
|
alias: {
|
|
86
86
|
type: 'object'
|
|
87
|
+
},
|
|
88
|
+
aliasForSubpaths: {
|
|
89
|
+
default: false,
|
|
90
|
+
type: 'boolean'
|
|
87
91
|
}
|
|
88
92
|
},
|
|
89
93
|
type: 'object'
|