@nx/eslint-plugin 16.6.0 → 16.7.0-beta.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.7.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The eslint-plugin package is an ESLint plugin that contains a collection of recommended ESLint rule configurations which you can extend from in your own ESLint configs, as well as an Nx-specific lint rule called enforce-module-boundaries.",
|
|
6
6
|
"repository": {
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nrwl/eslint-plugin-nx": "16.
|
|
37
|
-
"@nx/devkit": "16.
|
|
38
|
-
"@nx/js": "16.
|
|
36
|
+
"@nrwl/eslint-plugin-nx": "16.7.0-beta.1",
|
|
37
|
+
"@nx/devkit": "16.7.0-beta.1",
|
|
38
|
+
"@nx/js": "16.7.0-beta.1",
|
|
39
39
|
"@typescript-eslint/type-utils": "^5.60.1",
|
|
40
40
|
"@typescript-eslint/utils": "^5.60.1",
|
|
41
41
|
"chalk": "^4.1.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"migrations": "./migrations.json"
|
|
52
52
|
},
|
|
53
53
|
"types": "./src/index.d.ts",
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "50a145bb64edcf76985184a9a83d1449dcd4f3d9"
|
|
55
55
|
}
|
|
@@ -189,7 +189,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
189
189
|
fix(fixer) {
|
|
190
190
|
// imp has form of @myorg/someproject/some/path
|
|
191
191
|
const indexTsPaths = (0, ast_utils_1.getBarrelEntryPointByImportScope)(imp);
|
|
192
|
-
if (indexTsPaths
|
|
192
|
+
if (indexTsPaths.length > 0) {
|
|
193
193
|
const specifiers = node.specifiers;
|
|
194
194
|
if (!specifiers || specifiers.length === 0) {
|
|
195
195
|
return;
|
|
@@ -206,10 +206,15 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
206
206
|
if (importPath) {
|
|
207
207
|
// resolve the import path
|
|
208
208
|
const relativePath = (0, path_1.relative)((0, path_1.dirname)(fileName), (0, path_1.dirname)(importPath));
|
|
209
|
+
// the string we receive from elsewhere might not have a leading './' here despite still being a relative path
|
|
210
|
+
// we'd like to ensure it's a normalized relative form starting from ./ or ../
|
|
211
|
+
const ensureRelativeForm = (path) => path.startsWith('./') || path.startsWith('../')
|
|
212
|
+
? path
|
|
213
|
+
: `./${path}`;
|
|
209
214
|
// if the string is empty, it's the current file
|
|
210
215
|
const importPathResolved = relativePath === ''
|
|
211
216
|
? `./${(0, path_1.basename)(importPath)}`
|
|
212
|
-
: (0, devkit_1.joinPathFragments)(relativePath, (0, path_1.basename)(importPath));
|
|
217
|
+
: ensureRelativeForm((0, devkit_1.joinPathFragments)(relativePath, (0, path_1.basename)(importPath)));
|
|
213
218
|
importsToRemap.push({
|
|
214
219
|
member: importMember,
|
|
215
220
|
// remove .ts or .tsx from the end of the file path
|
package/src/utils/ast-utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ProjectGraphProjectNode } from '@nx/devkit';
|
|
|
4
4
|
* @param importScope like `@myorg/somelib`
|
|
5
5
|
* @returns
|
|
6
6
|
*/
|
|
7
|
-
export declare function getBarrelEntryPointByImportScope(importScope: string): string[]
|
|
7
|
+
export declare function getBarrelEntryPointByImportScope(importScope: string): string[];
|
|
8
8
|
export declare function getBarrelEntryPointProjectNode(projectNode: ProjectGraphProjectNode): {
|
|
9
9
|
path: string;
|
|
10
10
|
importScope: string;
|
package/src/utils/ast-utils.js
CHANGED
|
@@ -23,8 +23,33 @@ function tryReadBaseJson() {
|
|
|
23
23
|
*/
|
|
24
24
|
function getBarrelEntryPointByImportScope(importScope) {
|
|
25
25
|
var _a;
|
|
26
|
+
const tryPaths = (paths, importScope) => {
|
|
27
|
+
// TODO check and warn that the entries of paths[importScope] have no wildcards; that'd be user misconfiguration
|
|
28
|
+
if (paths[importScope])
|
|
29
|
+
return paths[importScope];
|
|
30
|
+
// accommodate wildcards (it's not glob) https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
|
|
31
|
+
const result = new Set(); // set ensures there are no duplicates
|
|
32
|
+
for (const [alias, targets] of Object.entries(paths)) {
|
|
33
|
+
if (!alias.endsWith('*')) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const strippedAlias = alias.slice(0, -1); // remove asterisk
|
|
37
|
+
if (!importScope.startsWith(strippedAlias)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const dynamicPart = importScope.slice(strippedAlias.length);
|
|
41
|
+
targets.forEach((target) => {
|
|
42
|
+
result.add(target.replace('*', dynamicPart)); // add interpolated value
|
|
43
|
+
});
|
|
44
|
+
// we found the entry for importScope; an import scope not supposed and has no sense having > 1 Aliases; TODO warn on duplicated entries
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return Array.from(result);
|
|
48
|
+
};
|
|
26
49
|
const tsConfigBase = tryReadBaseJson();
|
|
27
|
-
|
|
50
|
+
if (!((_a = tsConfigBase === null || tsConfigBase === void 0 ? void 0 : tsConfigBase.compilerOptions) === null || _a === void 0 ? void 0 : _a.paths))
|
|
51
|
+
return [];
|
|
52
|
+
return tryPaths(tsConfigBase.compilerOptions.paths, importScope);
|
|
28
53
|
}
|
|
29
54
|
exports.getBarrelEntryPointByImportScope = getBarrelEntryPointByImportScope;
|
|
30
55
|
function getBarrelEntryPointProjectNode(projectNode) {
|
|
@@ -66,6 +91,15 @@ function getRelativeImportPath(exportedMember, filePath, basePath) {
|
|
|
66
91
|
return;
|
|
67
92
|
}
|
|
68
93
|
}
|
|
94
|
+
else if (!(0, fs_1.lstatSync)(filePath, {
|
|
95
|
+
throwIfNoEntry: false,
|
|
96
|
+
}) /*not folder, but probably not full file with an extension either*/) {
|
|
97
|
+
// try to find an extension that exists
|
|
98
|
+
const ext = ['.ts', '.tsx', '.js', '.jsx'].find((ext) => (0, fs_1.lstatSync)(filePath + ext, { throwIfNoEntry: false }));
|
|
99
|
+
if (ext) {
|
|
100
|
+
filePath += ext;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
69
103
|
const fileContent = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
70
104
|
// use the TypeScript AST to find the path to the file where exportedMember is defined
|
|
71
105
|
const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true);
|