@nx/eslint 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +69 -112
- package/package.json +6 -7
- package/src/executors/lint/utility/eslint-utils.js +6 -0
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +10 -18
- package/src/generators/convert-to-flat-config/generator.js +18 -17
- package/src/generators/convert-to-flat-config/schema.d.ts +2 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +2 -1
- package/src/generators/init/global-eslint-config.d.ts +1 -1
- package/src/generators/init/global-eslint-config.js +17 -6
- package/src/generators/init/init-migration.d.ts +1 -1
- package/src/generators/init/init-migration.js +18 -13
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +31 -6
- package/src/generators/lint-project/lint-project.d.ts +1 -0
- package/src/generators/lint-project/lint-project.js +37 -15
- package/src/generators/lint-project/setup-root-eslint.d.ts +1 -0
- package/src/generators/lint-project/setup-root-eslint.js +2 -1
- package/src/generators/utils/eslint-file.d.ts +3 -2
- package/src/generators/utils/eslint-file.js +160 -28
- package/src/generators/utils/flat-config/ast-utils.d.ts +12 -4
- package/src/generators/utils/flat-config/ast-utils.js +412 -63
- package/src/generators/utils/linter.d.ts +3 -0
- package/src/generators/utils/linter.js +2 -2
- package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -2
- package/src/generators/workspace-rule/workspace-rule.d.ts +2 -2
- package/src/generators/workspace-rule/workspace-rule.js +11 -3
- package/src/generators/workspace-rules-project/workspace-rules-project.js +4 -1
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +2 -0
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +23 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +2 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +49 -0
- package/src/plugins/plugin.js +21 -10
- package/src/utils/config-file.d.ts +3 -1
- package/src/utils/config-file.js +5 -2
- package/src/utils/flat-config.d.ts +1 -0
- package/src/utils/flat-config.js +9 -3
- package/src/utils/version-utils.d.ts +1 -0
- package/src/utils/version-utils.js +13 -9
- package/src/utils/versions.d.ts +3 -2
- package/src/utils/versions.js +4 -3
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +0 -2
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +0 -44
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +0 -2
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +0 -47
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +0 -107
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://circleci.com/gh/nrwl/nx)
|
|
11
11
|
[]()
|
|
12
|
-
[](https://www.npmjs.com/package/nx)
|
|
13
13
|
[]()
|
|
14
14
|
[](http://commitizen.github.io/cz-cli/)
|
|
15
15
|
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
package/migrations.json
CHANGED
|
@@ -1,155 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generators": {
|
|
3
|
-
"update-
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
3
|
+
"update-typescript-eslint-v8.13.0": {
|
|
4
|
+
"version": "20.2.0-beta.5",
|
|
5
|
+
"description": "Update TypeScript ESLint packages to v8.13.0 if they are already on v8",
|
|
6
|
+
"implementation": "./src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0"
|
|
8
7
|
},
|
|
9
|
-
"
|
|
10
|
-
"version": "
|
|
11
|
-
"description": "
|
|
12
|
-
"implementation": "./src/migrations/update-
|
|
13
|
-
},
|
|
14
|
-
"update-17-0-0-rename-to-eslint": {
|
|
15
|
-
"version": "17.0.0-beta.7",
|
|
16
|
-
"description": "update-17-0-0-rename-to-eslint",
|
|
17
|
-
"implementation": "./src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint"
|
|
18
|
-
},
|
|
19
|
-
"update-typescript-eslint": {
|
|
20
|
-
"version": "17.1.0-beta.1",
|
|
21
|
-
"description": "Updates for @typescript-utils/utils v6.9.1+",
|
|
22
|
-
"implementation": "./src/migrations/update-17-1-0/update-typescript-eslint"
|
|
23
|
-
},
|
|
24
|
-
"simplify-eslint-patterns": {
|
|
25
|
-
"version": "17.2.0-beta.0",
|
|
26
|
-
"description": "Simplify eslintFilePatterns",
|
|
27
|
-
"implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
|
|
28
|
-
},
|
|
29
|
-
"move-options-to-target-defaults": {
|
|
30
|
-
"version": "17.2.9",
|
|
31
|
-
"description": "Move executor options to target defaults",
|
|
32
|
-
"implementation": "./src/migrations/update-17-2-9/move-options-to-target-defaults"
|
|
8
|
+
"add-file-extensions-to-overrides": {
|
|
9
|
+
"version": "20.3.0-beta.1",
|
|
10
|
+
"description": "Update ESLint flat config to include .cjs, .mjs, .cts, and .mts files in overrides (if needed)",
|
|
11
|
+
"implementation": "./src/migrations/update-20-3-0/add-file-extensions-to-overrides"
|
|
33
12
|
}
|
|
34
13
|
},
|
|
35
14
|
"packageJsonUpdates": {
|
|
36
|
-
"
|
|
37
|
-
"version": "
|
|
15
|
+
"19.5.0": {
|
|
16
|
+
"version": "19.5.0-beta.1",
|
|
38
17
|
"packages": {
|
|
39
18
|
"@typescript-eslint/parser": {
|
|
40
|
-
"version": "^
|
|
19
|
+
"version": "^7.16.0"
|
|
41
20
|
},
|
|
42
21
|
"@typescript-eslint/eslint-plugin": {
|
|
43
|
-
"version": "^
|
|
22
|
+
"version": "^7.16.0"
|
|
44
23
|
},
|
|
45
24
|
"@typescript-eslint/utils": {
|
|
46
|
-
"version": "^
|
|
25
|
+
"version": "^7.16.0"
|
|
26
|
+
},
|
|
27
|
+
"@typescript-eslint/rule-tester": {
|
|
28
|
+
"version": "^7.16.0",
|
|
29
|
+
"alwaysAddToPackageJson": false
|
|
30
|
+
},
|
|
31
|
+
"@typescript-eslint/scope-manager": {
|
|
32
|
+
"version": "^7.16.0",
|
|
33
|
+
"alwaysAddToPackageJson": false
|
|
34
|
+
},
|
|
35
|
+
"@typescript-eslint/typescript-estree": {
|
|
36
|
+
"version": "^7.16.0",
|
|
37
|
+
"alwaysAddToPackageJson": false
|
|
47
38
|
}
|
|
48
39
|
}
|
|
49
40
|
},
|
|
50
|
-
"
|
|
51
|
-
"version": "
|
|
41
|
+
"20.4.0-typescript-eslint": {
|
|
42
|
+
"version": "20.4.0-beta.1",
|
|
43
|
+
"requires": {
|
|
44
|
+
"typescript-eslint": ">8.0.0 <8.19.0"
|
|
45
|
+
},
|
|
52
46
|
"packages": {
|
|
53
|
-
"
|
|
54
|
-
"version": "^
|
|
47
|
+
"typescript-eslint": {
|
|
48
|
+
"version": "^8.19.0"
|
|
55
49
|
},
|
|
56
50
|
"@typescript-eslint/eslint-plugin": {
|
|
57
|
-
"version": "^
|
|
51
|
+
"version": "^8.19.0"
|
|
52
|
+
},
|
|
53
|
+
"@typescript-eslint/parser": {
|
|
54
|
+
"version": "^8.19.0"
|
|
58
55
|
},
|
|
59
56
|
"@typescript-eslint/utils": {
|
|
60
|
-
"version": "^
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"16.7.0": {
|
|
65
|
-
"version": "16.7.0-beta.2",
|
|
66
|
-
"packages": {
|
|
67
|
-
"eslint": {
|
|
68
|
-
"version": "~8.46.0"
|
|
57
|
+
"version": "^8.19.0"
|
|
69
58
|
},
|
|
70
|
-
"@typescript-eslint/
|
|
71
|
-
"version": "^
|
|
59
|
+
"@typescript-eslint/rule-tester": {
|
|
60
|
+
"version": "^8.19.0",
|
|
61
|
+
"alwaysAddToPackageJson": false
|
|
72
62
|
},
|
|
73
|
-
"@typescript-eslint/
|
|
74
|
-
"version": "^
|
|
63
|
+
"@typescript-eslint/scope-manager": {
|
|
64
|
+
"version": "^8.19.0",
|
|
65
|
+
"alwaysAddToPackageJson": false
|
|
75
66
|
},
|
|
76
|
-
"@typescript-eslint/
|
|
77
|
-
"version": "^
|
|
67
|
+
"@typescript-eslint/typescript-estree": {
|
|
68
|
+
"version": "^8.19.0",
|
|
69
|
+
"alwaysAddToPackageJson": false
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
},
|
|
81
|
-
"
|
|
82
|
-
"version": "
|
|
73
|
+
"20.4.0-@typescript-eslint": {
|
|
74
|
+
"version": "20.4.0-beta.1",
|
|
75
|
+
"requires": {
|
|
76
|
+
"@typescript-eslint/eslint-plugin": ">8.0.0 <8.19.0"
|
|
77
|
+
},
|
|
83
78
|
"packages": {
|
|
84
|
-
"eslint
|
|
85
|
-
"version": "^
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
"17.1.0": {
|
|
90
|
-
"version": "17.1.0-beta.1",
|
|
91
|
-
"packages": {
|
|
92
|
-
"@typescript-eslint/parser": {
|
|
93
|
-
"version": "^6.9.1"
|
|
79
|
+
"typescript-eslint": {
|
|
80
|
+
"version": "^8.19.0"
|
|
94
81
|
},
|
|
95
82
|
"@typescript-eslint/eslint-plugin": {
|
|
96
|
-
"version": "^
|
|
83
|
+
"version": "^8.19.0"
|
|
97
84
|
},
|
|
98
|
-
"@typescript-eslint/utils": {
|
|
99
|
-
"version": "^6.9.1"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
"17.2.0": {
|
|
104
|
-
"version": "17.2.0-beta.2",
|
|
105
|
-
"packages": {
|
|
106
|
-
"eslint": {
|
|
107
|
-
"version": "~8.48.0"
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
"17.3.0": {
|
|
112
|
-
"version": "17.3.0-beta.0",
|
|
113
|
-
"packages": {
|
|
114
85
|
"@typescript-eslint/parser": {
|
|
115
|
-
"version": "^
|
|
116
|
-
},
|
|
117
|
-
"@typescript-eslint/eslint-plugin": {
|
|
118
|
-
"version": "^6.13.2"
|
|
86
|
+
"version": "^8.19.0"
|
|
119
87
|
},
|
|
120
88
|
"@typescript-eslint/utils": {
|
|
121
|
-
"version": "^
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
"18.2.0": {
|
|
126
|
-
"version": "18.2.0-beta.0",
|
|
127
|
-
"packages": {
|
|
128
|
-
"@typescript-eslint/parser": {
|
|
129
|
-
"version": "^7.3.0"
|
|
89
|
+
"version": "^8.19.0"
|
|
130
90
|
},
|
|
131
|
-
"@typescript-eslint/
|
|
132
|
-
"version": "^
|
|
91
|
+
"@typescript-eslint/rule-tester": {
|
|
92
|
+
"version": "^8.19.0",
|
|
93
|
+
"alwaysAddToPackageJson": false
|
|
133
94
|
},
|
|
134
|
-
"@typescript-eslint/
|
|
135
|
-
"version": "^
|
|
95
|
+
"@typescript-eslint/scope-manager": {
|
|
96
|
+
"version": "^8.19.0",
|
|
97
|
+
"alwaysAddToPackageJson": false
|
|
136
98
|
},
|
|
137
|
-
"eslint": {
|
|
138
|
-
"version": "
|
|
99
|
+
"@typescript-eslint/typescript-estree": {
|
|
100
|
+
"version": "^8.19.0",
|
|
101
|
+
"alwaysAddToPackageJson": false
|
|
139
102
|
}
|
|
140
103
|
}
|
|
141
104
|
},
|
|
142
|
-
"
|
|
143
|
-
"version": "
|
|
105
|
+
"20.7.0": {
|
|
106
|
+
"version": "20.7.0-beta.4",
|
|
144
107
|
"packages": {
|
|
145
|
-
"
|
|
146
|
-
"version": "^
|
|
147
|
-
},
|
|
148
|
-
"@typescript-eslint/eslint-plugin": {
|
|
149
|
-
"version": "^7.16.0"
|
|
150
|
-
},
|
|
151
|
-
"@typescript-eslint/utils": {
|
|
152
|
-
"version": "^7.16.0"
|
|
108
|
+
"eslint-config-prettier": {
|
|
109
|
+
"version": "^10.0.0"
|
|
153
110
|
}
|
|
154
111
|
}
|
|
155
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-31313-387cdca",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
|
|
6
6
|
"repository": {
|
|
@@ -35,12 +35,11 @@
|
|
|
35
35
|
"eslint": "^8.0.0 || ^9.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nx/devkit": "0.0.0-pr-
|
|
39
|
-
"@nx/js": "0.0.0-pr-
|
|
38
|
+
"@nx/devkit": "0.0.0-pr-31313-387cdca",
|
|
39
|
+
"@nx/js": "0.0.0-pr-31313-387cdca",
|
|
40
40
|
"semver": "^7.5.3",
|
|
41
41
|
"tslib": "^2.3.0",
|
|
42
|
-
"typescript": "~5.
|
|
43
|
-
"@nx/linter": "0.0.0-pr-31222-862e973"
|
|
42
|
+
"typescript": "~5.7.2"
|
|
44
43
|
},
|
|
45
44
|
"peerDependenciesMeta": {
|
|
46
45
|
"@zkochan/js-yaml": {
|
|
@@ -50,6 +49,6 @@
|
|
|
50
49
|
"publishConfig": {
|
|
51
50
|
"access": "public"
|
|
52
51
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
52
|
+
"types": "./index.d.ts",
|
|
53
|
+
"type": "commonjs"
|
|
55
54
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveAndInstantiateESLint = resolveAndInstantiateESLint;
|
|
4
|
+
const semver_1 = require("semver");
|
|
4
5
|
const config_file_1 = require("../../../utils/config-file");
|
|
5
6
|
const resolve_eslint_class_1 = require("../../../utils/resolve-eslint-class");
|
|
6
7
|
async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatConfig = false) {
|
|
@@ -12,6 +13,7 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
|
|
|
12
13
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
|
|
13
14
|
useFlatConfigOverrideVal: useFlatConfig,
|
|
14
15
|
});
|
|
16
|
+
// ruleFilter exist only in eslint 9+, remove this type when eslint 8 support dropped
|
|
15
17
|
const eslintOptions = {
|
|
16
18
|
overrideConfigFile: eslintConfigPath,
|
|
17
19
|
fix: !!options.fix,
|
|
@@ -57,6 +59,10 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
|
|
|
57
59
|
eslintOptions.reportUnusedDisableDirectives =
|
|
58
60
|
options.reportUnusedDisableDirectives || undefined;
|
|
59
61
|
}
|
|
62
|
+
// pass --quiet to eslint 9+ directly: filter only errors
|
|
63
|
+
if (options.quiet && (0, semver_1.gte)(ESLint.version, '9.0.0')) {
|
|
64
|
+
eslintOptions.ruleFilter = (rule) => rule.severity === 2;
|
|
65
|
+
}
|
|
60
66
|
const eslint = new ESLint(eslintOptions);
|
|
61
67
|
return {
|
|
62
68
|
ESLint,
|
|
@@ -4,7 +4,7 @@ import { ESLint } from 'eslint';
|
|
|
4
4
|
* Converts an ESLint JSON config to a flat config.
|
|
5
5
|
* Deletes the original file along with .eslintignore if it exists.
|
|
6
6
|
*/
|
|
7
|
-
export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, config: ESLint.ConfigData, ignorePaths: string[]): {
|
|
7
|
+
export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, config: ESLint.ConfigData, ignorePaths: string[], format: 'cjs' | 'mjs'): {
|
|
8
8
|
content: string;
|
|
9
9
|
addESLintRC: boolean;
|
|
10
10
|
addESLintJS: boolean;
|
|
@@ -10,15 +10,19 @@ const path_utils_1 = require("../../utils/flat-config/path-utils");
|
|
|
10
10
|
* Converts an ESLint JSON config to a flat config.
|
|
11
11
|
* Deletes the original file along with .eslintignore if it exists.
|
|
12
12
|
*/
|
|
13
|
-
function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
|
|
13
|
+
function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths, format) {
|
|
14
14
|
const importsMap = new Map();
|
|
15
15
|
const exportElements = [];
|
|
16
16
|
let isFlatCompatNeeded = false;
|
|
17
17
|
let isESLintJSNeeded = false;
|
|
18
18
|
let combinedConfig = [];
|
|
19
19
|
let languageOptions = [];
|
|
20
|
+
// exclude dist and eslint config from being linted, which matches the default for new workspaces
|
|
21
|
+
exportElements.push((0, ast_utils_1.generateAst)({
|
|
22
|
+
ignores: ['**/dist'],
|
|
23
|
+
}));
|
|
20
24
|
if (config.extends) {
|
|
21
|
-
const extendsResult = addExtends(importsMap, exportElements, config);
|
|
25
|
+
const extendsResult = addExtends(importsMap, exportElements, config, format);
|
|
22
26
|
isFlatCompatNeeded = extendsResult.isFlatCompatNeeded;
|
|
23
27
|
isESLintJSNeeded = extendsResult.isESLintJSNeeded;
|
|
24
28
|
}
|
|
@@ -70,19 +74,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
|
|
|
70
74
|
override.parser) {
|
|
71
75
|
isFlatCompatNeeded = true;
|
|
72
76
|
}
|
|
73
|
-
exportElements.push((0, ast_utils_1.generateFlatOverride)(override));
|
|
74
|
-
// eslint-plugin-import cannot be used with ESLint v9 yet
|
|
75
|
-
// TODO(jack): Once v9 support is released, remove this block.
|
|
76
|
-
// See: https://github.com/import-js/eslint-plugin-import/pull/2996
|
|
77
|
-
if (override.extends === 'plugin:@nx/react') {
|
|
78
|
-
exportElements.push((0, ast_utils_1.generateFlatOverride)({
|
|
79
|
-
rules: {
|
|
80
|
-
'import/first': 'off',
|
|
81
|
-
'import/no-amd': 'off',
|
|
82
|
-
'import/no-webpack-loader-syntax': 'off',
|
|
83
|
-
},
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
77
|
+
exportElements.push((0, ast_utils_1.generateFlatOverride)(override, format));
|
|
86
78
|
});
|
|
87
79
|
}
|
|
88
80
|
if (config.ignorePatterns) {
|
|
@@ -108,7 +100,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
|
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
102
|
// create the node list and print it to new file
|
|
111
|
-
const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements);
|
|
103
|
+
const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements, format);
|
|
112
104
|
let content = (0, ast_utils_1.stringifyNodeList)(nodeList);
|
|
113
105
|
if (isFlatCompatNeeded) {
|
|
114
106
|
content = (0, ast_utils_1.addFlatCompatToFlatConfig)(content);
|
|
@@ -120,7 +112,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
|
|
|
120
112
|
};
|
|
121
113
|
}
|
|
122
114
|
// add parsed extends to export blocks and add import statements
|
|
123
|
-
function addExtends(importsMap, configBlocks, config) {
|
|
115
|
+
function addExtends(importsMap, configBlocks, config, format) {
|
|
124
116
|
let isFlatCompatNeeded = false;
|
|
125
117
|
let isESLintJSNeeded = false;
|
|
126
118
|
const extendsConfig = Array.isArray(config.extends)
|
|
@@ -134,7 +126,7 @@ function addExtends(importsMap, configBlocks, config) {
|
|
|
134
126
|
if (imp.match(/\.eslintrc(.base)?\.json$/)) {
|
|
135
127
|
const localName = index ? `baseConfig${index}` : 'baseConfig';
|
|
136
128
|
configBlocks.push((0, ast_utils_1.generateSpreadElement)(localName));
|
|
137
|
-
const newImport = imp.replace(/^(.*)\.eslintrc(.base)?\.json$/,
|
|
129
|
+
const newImport = imp.replace(/^(.*)\.eslintrc(.base)?\.json$/, `$1eslint$2.config.${format}`);
|
|
138
130
|
importsMap.set(newImport, localName);
|
|
139
131
|
}
|
|
140
132
|
else {
|
|
@@ -14,20 +14,21 @@ async function convertToFlatConfigGenerator(tree, options) {
|
|
|
14
14
|
if (eslintFile.endsWith('.js')) {
|
|
15
15
|
throw new Error('Only json and yaml eslint config files are supported for conversion');
|
|
16
16
|
}
|
|
17
|
+
options.eslintConfigFormat ??= 'mjs';
|
|
17
18
|
const eslintIgnoreFiles = new Set(['.eslintignore']);
|
|
18
|
-
// convert root eslint config to eslint.config.
|
|
19
|
-
convertRootToFlatConfig(tree, eslintFile);
|
|
20
|
-
// convert project eslint files to eslint.config.
|
|
19
|
+
// convert root eslint config to eslint.config.cjs or eslint.base.config.mjs based on eslintConfigFormat
|
|
20
|
+
convertRootToFlatConfig(tree, eslintFile, options.eslintConfigFormat);
|
|
21
|
+
// convert project eslint files to eslint.config.cjs
|
|
21
22
|
const projects = (0, devkit_1.getProjects)(tree);
|
|
22
23
|
for (const [project, projectConfig] of projects) {
|
|
23
|
-
convertProjectToFlatConfig(tree, project, projectConfig, (0, devkit_1.readNxJson)(tree), eslintIgnoreFiles);
|
|
24
|
+
convertProjectToFlatConfig(tree, project, projectConfig, (0, devkit_1.readNxJson)(tree), eslintIgnoreFiles, options.eslintConfigFormat);
|
|
24
25
|
}
|
|
25
26
|
// delete all .eslintignore files
|
|
26
27
|
for (const ignoreFile of eslintIgnoreFiles) {
|
|
27
28
|
tree.delete(ignoreFile);
|
|
28
29
|
}
|
|
29
30
|
// replace references in nx.json
|
|
30
|
-
updateNxJsonConfig(tree);
|
|
31
|
+
updateNxJsonConfig(tree, options.eslintConfigFormat);
|
|
31
32
|
// install missing packages
|
|
32
33
|
if (!options.skipFormat) {
|
|
33
34
|
await (0, devkit_1.formatFiles)(tree);
|
|
@@ -35,13 +36,13 @@ async function convertToFlatConfigGenerator(tree, options) {
|
|
|
35
36
|
return () => (0, devkit_1.installPackagesTask)(tree);
|
|
36
37
|
}
|
|
37
38
|
exports.default = convertToFlatConfigGenerator;
|
|
38
|
-
function convertRootToFlatConfig(tree, eslintFile) {
|
|
39
|
+
function convertRootToFlatConfig(tree, eslintFile, format) {
|
|
39
40
|
if (/\.base\.(js|json|yml|yaml)$/.test(eslintFile)) {
|
|
40
|
-
convertConfigToFlatConfig(tree, '', eslintFile,
|
|
41
|
+
convertConfigToFlatConfig(tree, '', eslintFile, `eslint.base.config.${format}`, format);
|
|
41
42
|
}
|
|
42
|
-
convertConfigToFlatConfig(tree, '', eslintFile.replace('.base.', '.'),
|
|
43
|
+
convertConfigToFlatConfig(tree, '', eslintFile.replace('.base.', '.'), `eslint.config.${format}`, format);
|
|
43
44
|
}
|
|
44
|
-
function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles) {
|
|
45
|
+
function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslintIgnoreFiles, format) {
|
|
45
46
|
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
|
|
46
47
|
if (eslintFile && !eslintFile.endsWith('.js')) {
|
|
47
48
|
if (projectConfig.targets) {
|
|
@@ -67,7 +68,7 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
|
|
|
67
68
|
? p === '@nx/eslint/plugin'
|
|
68
69
|
: p.plugin === '@nx/eslint/plugin');
|
|
69
70
|
if (nxHasEsLintTargets || nxHasEsLintPlugin || eslintTargets.length > 0) {
|
|
70
|
-
convertConfigToFlatConfig(tree, projectConfig.root, eslintFile,
|
|
71
|
+
convertConfigToFlatConfig(tree, projectConfig.root, eslintFile, `eslint.config.${format}`, format, ignorePath);
|
|
71
72
|
eslintIgnoreFiles.add(`${projectConfig.root}/.eslintignore`);
|
|
72
73
|
if (ignorePath) {
|
|
73
74
|
eslintIgnoreFiles.add(ignorePath);
|
|
@@ -78,35 +79,35 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
|
|
|
78
79
|
}
|
|
79
80
|
// update names of eslint files in nx.json
|
|
80
81
|
// and remove eslintignore
|
|
81
|
-
function updateNxJsonConfig(tree) {
|
|
82
|
+
function updateNxJsonConfig(tree, format) {
|
|
82
83
|
if (tree.exists('nx.json')) {
|
|
83
84
|
(0, devkit_1.updateJson)(tree, 'nx.json', (json) => {
|
|
84
85
|
if (json.targetDefaults?.lint?.inputs) {
|
|
85
86
|
const inputSet = new Set(json.targetDefaults.lint.inputs);
|
|
86
|
-
inputSet.add(
|
|
87
|
+
inputSet.add(`{workspaceRoot}/eslint.config.${format}`);
|
|
87
88
|
json.targetDefaults.lint.inputs = Array.from(inputSet);
|
|
88
89
|
}
|
|
89
90
|
if (json.targetDefaults?.['@nx/eslint:lint']?.inputs) {
|
|
90
91
|
const inputSet = new Set(json.targetDefaults['@nx/eslint:lint'].inputs);
|
|
91
|
-
inputSet.add(
|
|
92
|
+
inputSet.add(`{workspaceRoot}/eslint.config.${format}`);
|
|
92
93
|
json.targetDefaults['@nx/eslint:lint'].inputs = Array.from(inputSet);
|
|
93
94
|
}
|
|
94
95
|
if (json.namedInputs?.production) {
|
|
95
96
|
const inputSet = new Set(json.namedInputs.production);
|
|
96
|
-
inputSet.add(
|
|
97
|
+
inputSet.add(`!{projectRoot}/eslint.config.${format}`);
|
|
97
98
|
json.namedInputs.production = Array.from(inputSet);
|
|
98
99
|
}
|
|
99
100
|
return json;
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
function convertConfigToFlatConfig(tree, root, source, target, ignorePath) {
|
|
104
|
+
function convertConfigToFlatConfig(tree, root, source, target, format, ignorePath) {
|
|
104
105
|
const ignorePaths = ignorePath
|
|
105
106
|
? [ignorePath, `${root}/.eslintignore`]
|
|
106
107
|
: [`${root}/.eslintignore`];
|
|
107
108
|
if (source.endsWith('.json')) {
|
|
108
109
|
const config = (0, devkit_1.readJson)(tree, `${root}/${source}`);
|
|
109
|
-
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths);
|
|
110
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths, format);
|
|
110
111
|
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
111
112
|
}
|
|
112
113
|
if (source.endsWith('.yaml') || source.endsWith('.yml')) {
|
|
@@ -116,7 +117,7 @@ function convertConfigToFlatConfig(tree, root, source, target, ignorePath) {
|
|
|
116
117
|
json: true,
|
|
117
118
|
filename: source,
|
|
118
119
|
});
|
|
119
|
-
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths);
|
|
120
|
+
const conversionResult = (0, json_converter_1.convertEslintJsonToFlatConfig)(tree, root, config, ignorePaths, format);
|
|
120
121
|
return processConvertedConfig(tree, root, source, target, conversionResult);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
@@ -33,7 +33,8 @@ function postTargetTransformer(target, tree, projectDetails, inferredTargetConfi
|
|
|
33
33
|
'default',
|
|
34
34
|
'{workspaceRoot}/.eslintrc.json',
|
|
35
35
|
'{workspaceRoot}/.eslintignore',
|
|
36
|
-
'{workspaceRoot}/eslint.config.
|
|
36
|
+
'{workspaceRoot}/eslint.config.cjs',
|
|
37
|
+
'{workspaceRoot}/eslint.config.mjs',
|
|
37
38
|
].includes(input));
|
|
38
39
|
if (inputs.length === 0) {
|
|
39
40
|
delete target.inputs;
|
|
@@ -26,4 +26,4 @@ export declare const javaScriptOverride: {
|
|
|
26
26
|
rules: {};
|
|
27
27
|
};
|
|
28
28
|
export declare const getGlobalEsLintConfiguration: (unitTestRunner?: string, rootProject?: boolean) => Linter.Config;
|
|
29
|
-
export declare const getGlobalFlatEslintConfiguration: (rootProject?: boolean) => string;
|
|
29
|
+
export declare const getGlobalFlatEslintConfiguration: (format: "cjs" | "mjs", rootProject?: boolean) => string;
|
|
@@ -78,14 +78,16 @@ const getGlobalEsLintConfiguration = (unitTestRunner, rootProject) => {
|
|
|
78
78
|
return config;
|
|
79
79
|
};
|
|
80
80
|
exports.getGlobalEsLintConfiguration = getGlobalEsLintConfiguration;
|
|
81
|
-
const getGlobalFlatEslintConfiguration = (rootProject) => {
|
|
82
|
-
const nodeList = (0, ast_utils_1.createNodeList)(new Map(), []);
|
|
81
|
+
const getGlobalFlatEslintConfiguration = (format, rootProject) => {
|
|
82
|
+
const nodeList = (0, ast_utils_1.createNodeList)(new Map(), [], format);
|
|
83
83
|
let content = (0, ast_utils_1.stringifyNodeList)(nodeList);
|
|
84
84
|
content = (0, ast_utils_1.addImportToFlatConfig)(content, 'nx', '@nx/eslint-plugin');
|
|
85
85
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/base'), { insertAtTheEnd: false });
|
|
86
86
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/typescript'));
|
|
87
87
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/javascript'));
|
|
88
|
-
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
88
|
+
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
89
|
+
ignores: ['**/dist'],
|
|
90
|
+
}, format));
|
|
89
91
|
if (!rootProject) {
|
|
90
92
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
91
93
|
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
@@ -105,12 +107,21 @@ const getGlobalFlatEslintConfiguration = (rootProject) => {
|
|
|
105
107
|
},
|
|
106
108
|
],
|
|
107
109
|
},
|
|
108
|
-
}));
|
|
110
|
+
}, format));
|
|
109
111
|
}
|
|
110
112
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
111
|
-
files: [
|
|
113
|
+
files: [
|
|
114
|
+
'**/*.ts',
|
|
115
|
+
'**/*.tsx',
|
|
116
|
+
'**/*.cts',
|
|
117
|
+
'**/*.mts',
|
|
118
|
+
'**/*.js',
|
|
119
|
+
'**/*.jsx',
|
|
120
|
+
'**/*.cjs',
|
|
121
|
+
'**/*.mjs',
|
|
122
|
+
],
|
|
112
123
|
rules: {},
|
|
113
|
-
}));
|
|
124
|
+
}, format));
|
|
114
125
|
return content;
|
|
115
126
|
};
|
|
116
127
|
exports.getGlobalFlatEslintConfiguration = getGlobalFlatEslintConfiguration;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GeneratorCallback, ProjectConfiguration, TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
-
export declare function migrateConfigToMonorepoStyle(projects: ProjectConfiguration[], tree: Tree, unitTestRunner: string, keepExistingVersions?: boolean): GeneratorCallback;
|
|
2
|
+
export declare function migrateConfigToMonorepoStyle(projects: ProjectConfiguration[], tree: Tree, unitTestRunner: string, eslintConfigFormat: 'mjs' | 'cjs', keepExistingVersions?: boolean): GeneratorCallback;
|
|
3
3
|
export declare function findLintTarget(project: ProjectConfiguration): TargetConfiguration;
|
|
@@ -11,9 +11,19 @@ const versions_1 = require("../../utils/versions");
|
|
|
11
11
|
const ast_utils_1 = require("../utils/flat-config/ast-utils");
|
|
12
12
|
const plugin_1 = require("../utils/plugin");
|
|
13
13
|
const config_file_1 = require("../../utils/config-file");
|
|
14
|
-
function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, keepExistingVersions) {
|
|
14
|
+
function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, eslintConfigFormat, keepExistingVersions) {
|
|
15
15
|
const rootEslintConfig = (0, eslint_file_1.findEslintFile)(tree);
|
|
16
16
|
let skipCleanup = false;
|
|
17
|
+
if (rootEslintConfig) {
|
|
18
|
+
// We do not want to mix the formats
|
|
19
|
+
const fileExtension = (0, path_1.extname)(rootEslintConfig);
|
|
20
|
+
if (fileExtension === '.mjs' || fileExtension === '.cjs') {
|
|
21
|
+
eslintConfigFormat = fileExtension.slice(1);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
eslintConfigFormat = (0, eslint_file_1.determineEslintConfigFormat)(tree.read(rootEslintConfig, 'utf-8'));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
17
27
|
if (rootEslintConfig?.match(/\.base\./) &&
|
|
18
28
|
!projects.some((p) => p.root === '.')) {
|
|
19
29
|
// if the migration has been run already, we need to rename the base config
|
|
@@ -27,9 +37,9 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, keepExisti
|
|
|
27
37
|
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
28
38
|
'@eslint/js': versions_1.eslintVersion,
|
|
29
39
|
}, undefined, keepExistingVersions);
|
|
30
|
-
tree.write(tree.exists(
|
|
31
|
-
?
|
|
32
|
-
:
|
|
40
|
+
tree.write(tree.exists(`eslint.config.${eslintConfigFormat}`)
|
|
41
|
+
? `eslint.base.config.${eslintConfigFormat}`
|
|
42
|
+
: `eslint.config.${eslintConfigFormat}`, (0, global_eslint_config_1.getGlobalFlatEslintConfiguration)(eslintConfigFormat));
|
|
33
43
|
}
|
|
34
44
|
else {
|
|
35
45
|
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, '.');
|
|
@@ -71,8 +81,7 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, keepExisti
|
|
|
71
81
|
}
|
|
72
82
|
function findLintTarget(project) {
|
|
73
83
|
return Object.values(project.targets ?? {}).find((target) => target.executor === '@nx/eslint:lint' ||
|
|
74
|
-
target.executor === '@nx/linter:eslint'
|
|
75
|
-
target.executor === '@nrwl/linter:eslint');
|
|
84
|
+
target.executor === '@nx/linter:eslint');
|
|
76
85
|
}
|
|
77
86
|
function migrateEslintFile(projectEslintPath, tree) {
|
|
78
87
|
const baseFile = (0, eslint_file_1.findEslintFile)(tree);
|
|
@@ -81,15 +90,13 @@ function migrateEslintFile(projectEslintPath, tree) {
|
|
|
81
90
|
let config = tree.read(projectEslintPath, 'utf-8');
|
|
82
91
|
// remove @nx plugin
|
|
83
92
|
config = (0, ast_utils_1.removePlugin)(config, '@nx', '@nx/eslint-plugin-nx');
|
|
84
|
-
//
|
|
93
|
+
// if base config is cjs, we will need to import it using async import
|
|
85
94
|
config = (0, ast_utils_1.addImportToFlatConfig)(config, 'baseConfig', `${(0, devkit_1.offsetFromRoot)((0, path_1.dirname)(projectEslintPath))}${baseFile}`);
|
|
86
95
|
config = (0, ast_utils_1.addBlockToFlatConfigExport)(config, (0, ast_utils_1.generateSpreadElement)('baseConfig'), { insertAtTheEnd: false });
|
|
87
96
|
// cleanup file extends
|
|
88
97
|
config = (0, ast_utils_1.removeCompatExtends)(config, [
|
|
89
98
|
'plugin:@nx/typescript',
|
|
90
99
|
'plugin:@nx/javascript',
|
|
91
|
-
'plugin:@nrwl/typescript',
|
|
92
|
-
'plugin:@nrwl/javascript',
|
|
93
100
|
]);
|
|
94
101
|
config = (0, ast_utils_1.removePredefinedConfigs)(config, '@nx/eslint-plugin', 'nx', [
|
|
95
102
|
'flat/base',
|
|
@@ -104,7 +111,7 @@ function migrateEslintFile(projectEslintPath, tree) {
|
|
|
104
111
|
delete json.root;
|
|
105
112
|
// remove nrwl/nx plugins
|
|
106
113
|
if (json.plugins) {
|
|
107
|
-
json.plugins = json.plugins.filter((p) => p !== '@nx'
|
|
114
|
+
json.plugins = json.plugins.filter((p) => p !== '@nx');
|
|
108
115
|
if (json.plugins.length === 0) {
|
|
109
116
|
delete json.plugins;
|
|
110
117
|
}
|
|
@@ -124,9 +131,7 @@ function migrateEslintFile(projectEslintPath, tree) {
|
|
|
124
131
|
json.overrides.forEach((override) => {
|
|
125
132
|
if (override.extends) {
|
|
126
133
|
override.extends = override.extends.filter((ext) => ext !== 'plugin:@nx/typescript' &&
|
|
127
|
-
ext !== 'plugin:@
|
|
128
|
-
ext !== 'plugin:@nx/javascript' &&
|
|
129
|
-
ext !== 'plugin:@nrwl/nx/javascript');
|
|
134
|
+
ext !== 'plugin:@nx/javascript');
|
|
130
135
|
if (override.extends.length === 0) {
|
|
131
136
|
delete override.extends;
|
|
132
137
|
}
|