@dword-design/eslint-plugin-import-alias 8.1.2 → 8.1.4
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 +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/rules/prefer-alias.d.ts +3 -1
- package/dist/rules/prefer-alias.js +4 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Add the plugin to your ESLint config:
|
|
|
89
89
|
// eslint.config.ts
|
|
90
90
|
|
|
91
91
|
import { defineConfig } from 'eslint/config';
|
|
92
|
-
import importAlias from '@dword-design/import-alias';
|
|
92
|
+
import importAlias from '@dword-design/eslint-plugin-import-alias';
|
|
93
93
|
|
|
94
94
|
export default defineConfig([
|
|
95
95
|
importAlias.configs.recommended,
|
|
@@ -102,7 +102,7 @@ Options can be passed by setting them in the `prefer-alias` rule:
|
|
|
102
102
|
// eslint.config.ts
|
|
103
103
|
|
|
104
104
|
import { defineConfig } from 'eslint/config';
|
|
105
|
-
import importAlias from '@dword-design/import-alias';
|
|
105
|
+
import importAlias from '@dword-design/eslint-plugin-import-alias';
|
|
106
106
|
|
|
107
107
|
export default defineConfig([
|
|
108
108
|
importAlias.configs.recommended,
|
|
@@ -146,7 +146,7 @@ You can also just pass the aliases to the plugin as an option.
|
|
|
146
146
|
// eslint.config.ts
|
|
147
147
|
|
|
148
148
|
import { defineConfig } from 'eslint/config';
|
|
149
|
-
import importAlias from '@dword-design/import-alias';
|
|
149
|
+
import importAlias from '@dword-design/eslint-plugin-import-alias';
|
|
150
150
|
|
|
151
151
|
export default defineConfig([
|
|
152
152
|
importAlias.configs.recommended,
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ declare const _default: {
|
|
|
4
4
|
plugins: {
|
|
5
5
|
'@dword-design/import-alias': {
|
|
6
6
|
rules: {
|
|
7
|
-
'prefer-alias': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"parentImport" | "subpathImport", [import("./rules/prefer-alias").OptionsInput], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener
|
|
7
|
+
'prefer-alias': import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"parentImport" | "subpathImport", [import("./rules/prefer-alias").OptionsInput], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener> & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
8
10
|
};
|
|
9
11
|
};
|
|
10
12
|
};
|
|
@@ -22,5 +22,7 @@ export type OptionsInput = Omit<Partial<Options>, 'alias'> & {
|
|
|
22
22
|
alias?: Record<string, string>;
|
|
23
23
|
babelOptions?: BabelOptions;
|
|
24
24
|
};
|
|
25
|
-
declare const _default: ESLintUtils.RuleModule<"parentImport" | "subpathImport", [OptionsInput], unknown, ESLintUtils.RuleListener
|
|
25
|
+
declare const _default: ESLintUtils.RuleModule<"parentImport" | "subpathImport", [OptionsInput], unknown, ESLintUtils.RuleListener> & {
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
26
28
|
export default _default;
|
|
@@ -146,7 +146,10 @@ export default createRule({
|
|
|
146
146
|
return {
|
|
147
147
|
ImportDeclaration: node => {
|
|
148
148
|
const sourcePath = node.source.value;
|
|
149
|
-
const
|
|
149
|
+
const filteredAliases = Object.fromEntries(Object.entries(options.alias).flatMap(([aliasName, aliasInfos]) => aliasInfos.map(info => [aliasName, info])).filter(([, info]) => info.includePatterns.length > 0 ? micromatch.isMatch(pathLib.relative(info.configDir, context.filename), info.includePatterns, {
|
|
150
|
+
cwd: info.configDir
|
|
151
|
+
}) : true).map(([aliasName, info]) => [aliasName, info.path]));
|
|
152
|
+
const hasAlias = Object.keys(filteredAliases).some(alias => sourcePath.startsWith(`${alias}/`));
|
|
150
153
|
if (isParentImport(sourcePath)) {
|
|
151
154
|
const matchingAlias = findMatchingAlias(sourcePath, context.filename, pick(options, ["alias", "resolvePath"]), {
|
|
152
155
|
cwd: context.cwd
|
|
@@ -166,9 +169,6 @@ export default createRule({
|
|
|
166
169
|
node
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
|
-
const filteredAliases = Object.fromEntries(Object.entries(options.alias).flatMap(([aliasName, aliasInfos]) => aliasInfos.map(info => [aliasName, info])).filter(([, info]) => info.includePatterns.length > 0 ? micromatch.isMatch(pathLib.relative(info.configDir, context.filename), info.includePatterns, {
|
|
170
|
-
cwd: info.configDir
|
|
171
|
-
}) : true).map(([aliasName, info]) => [aliasName, info.path]));
|
|
172
172
|
const importWithoutAlias = options.resolvePath(sourcePath, context.filename, {
|
|
173
173
|
alias: filteredAliases,
|
|
174
174
|
cwd: options.cwd
|
|
@@ -184,7 +184,6 @@ export default createRule({
|
|
|
184
184
|
node
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
return;
|
|
188
187
|
}
|
|
189
188
|
};
|
|
190
189
|
},
|