@nx/eslint 23.0.0 → 23.1.0-beta.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.
Files changed (27) hide show
  1. package/README.md +1 -2
  2. package/dist/src/executors/lint/lint.impl.js +0 -5
  3. package/dist/src/executors/lint/schema.d.ts +1 -14
  4. package/dist/src/executors/lint/schema.json +1 -15
  5. package/dist/src/executors/lint/utility/eslint-utils.js +7 -5
  6. package/dist/src/generators/convert-to-flat-config/generator.js +42 -19
  7. package/dist/src/generators/convert-to-flat-config/schema.d.ts +3 -0
  8. package/dist/src/generators/convert-to-flat-config/schema.json +6 -0
  9. package/dist/src/generators/init/global-eslint-config.d.ts +1 -1
  10. package/dist/src/generators/utils/eslint-file.js +20 -28
  11. package/dist/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +1 -7
  12. package/dist/src/generators/workspace-rule/workspace-rule.js +4 -15
  13. package/dist/src/migrations/update-23-1-0/convert-to-flat-config.d.ts +15 -0
  14. package/dist/src/migrations/update-23-1-0/convert-to-flat-config.js +283 -0
  15. package/dist/src/migrations/update-23-1-0/convert-to-flat-config.md +286 -0
  16. package/dist/src/plugins/plugin.js +8 -11
  17. package/dist/src/utils/assert-supported-eslint-version.js +0 -4
  18. package/dist/src/utils/config-file.js +1 -8
  19. package/dist/src/utils/deprecation.d.ts +0 -2
  20. package/dist/src/utils/deprecation.js +1 -11
  21. package/dist/src/utils/flat-config.d.ts +1 -0
  22. package/dist/src/utils/flat-config.js +20 -18
  23. package/dist/src/utils/resolve-eslint-class.js +11 -17
  24. package/dist/src/utils/versions.d.ts +3 -4
  25. package/dist/src/utils/versions.js +5 -16
  26. package/migrations.json +121 -0
  27. package/package.json +7 -7
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ESLINT_V8_DEPRECATION_MESSAGE = exports.ESLINT_EXECUTOR_DEPRECATION_MESSAGE = void 0;
3
+ exports.ESLINT_EXECUTOR_DEPRECATION_MESSAGE = void 0;
4
4
  exports.warnEslintExecutorDeprecation = warnEslintExecutorDeprecation;
5
5
  exports.warnEslintExecutorGenerating = warnEslintExecutorGenerating;
6
- exports.warnEslintV8Deprecation = warnEslintV8Deprecation;
7
6
  const devkit_1 = require("@nx/devkit");
8
7
  // TODO(v24): Remove the @nx/eslint:lint executor. The inferred plugin
9
8
  // (@nx/eslint/plugin) and the convert-to-inferred generator stay supported.
@@ -14,12 +13,3 @@ function warnEslintExecutorDeprecation() {
14
13
  function warnEslintExecutorGenerating() {
15
14
  devkit_1.logger.warn('Generating a target that uses the deprecated `@nx/eslint:lint` executor. The executor will be removed in Nx v24. Run `nx g @nx/eslint:convert-to-inferred` next to migrate this target to the `@nx/eslint/plugin` inferred plugin and prevent future generators from emitting executor targets. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.');
16
15
  }
17
- // TODO(v24): Remove ESLint v8 support. Concrete removals:
18
- // - Raise `minSupportedEslintVersion` to '9.0.0' in versions.ts.
19
- // - Delete `versionMap[8]` and the `CompatVersions` type alias.
20
- // - Delete this constant + `warnEslintV8Deprecation` and their call sites.
21
- // - Drop the v8 branch in the workspace-rule generator/template.
22
- exports.ESLINT_V8_DEPRECATION_MESSAGE = 'Support for ESLint v8 is deprecated and will be removed in Nx v24. Please upgrade to ESLint v9.';
23
- function warnEslintV8Deprecation() {
24
- devkit_1.logger.warn(exports.ESLINT_V8_DEPRECATION_MESSAGE);
25
- }
@@ -1,5 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  export declare const eslintFlatConfigFilenames: string[];
3
3
  export declare const baseEslintConfigFilenames: string[];
4
+ export declare const eslintrcFilenames: string[];
4
5
  export declare function getRootESLintFlatConfigFilename(tree: Tree): string;
5
6
  export declare function useFlatConfig(tree?: Tree): boolean;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseEslintConfigFilenames = exports.eslintFlatConfigFilenames = void 0;
3
+ exports.eslintrcFilenames = exports.baseEslintConfigFilenames = exports.eslintFlatConfigFilenames = void 0;
4
4
  exports.getRootESLintFlatConfigFilename = getRootESLintFlatConfigFilename;
5
5
  exports.useFlatConfig = useFlatConfig;
6
- const semver_1 = require("semver");
7
6
  exports.eslintFlatConfigFilenames = [
8
7
  'eslint.config.cjs',
9
8
  'eslint.config.js',
@@ -22,6 +21,14 @@ exports.baseEslintConfigFilenames = [
22
21
  'eslint.base.config.ts',
23
22
  'eslint.base.config.mts',
24
23
  ];
24
+ exports.eslintrcFilenames = [
25
+ '.eslintrc',
26
+ '.eslintrc.js',
27
+ '.eslintrc.cjs',
28
+ '.eslintrc.yaml',
29
+ '.eslintrc.yml',
30
+ '.eslintrc.json',
31
+ ];
25
32
  function getRootESLintFlatConfigFilename(tree) {
26
33
  for (const file of exports.eslintFlatConfigFilenames) {
27
34
  if (tree.exists(file)) {
@@ -31,30 +38,25 @@ function getRootESLintFlatConfigFilename(tree) {
31
38
  throw new Error('Could not find root flat config file');
32
39
  }
33
40
  function useFlatConfig(tree) {
34
- // Prioritize taking ESLint's own environment variable into account when determining if we should use flat config
35
- // If it is not defined, then default to true.
41
+ // ESLint's own environment variable wins when set.
36
42
  if (process.env.ESLINT_USE_FLAT_CONFIG === 'true') {
37
43
  return true;
38
44
  }
39
45
  else if (process.env.ESLINT_USE_FLAT_CONFIG === 'false') {
40
46
  return false;
41
47
  }
42
- // If we find an existing flat config file in the root of the provided tree, we should use flat config
43
48
  if (tree) {
44
- const hasRootFlatConfig = exports.eslintFlatConfigFilenames.some((filename) => tree.exists(filename));
45
- if (hasRootFlatConfig) {
49
+ // An existing flat config at the root means the workspace is on flat config.
50
+ if (exports.eslintFlatConfigFilenames.some((filename) => tree.exists(filename))) {
46
51
  return true;
47
52
  }
53
+ // An existing eslintrc config means the workspace is still on eslintrc, which
54
+ // we keep supporting; don't force it onto flat config.
55
+ if (exports.eslintrcFilenames.some((filename) => tree.exists(filename))) {
56
+ return false;
57
+ }
48
58
  }
49
- // Otherwise fallback to checking the installed eslint version
50
- try {
51
- const { ESLint } = require('eslint');
52
- // Default to any v8 version to compare against in this case as it implies a much older version of ESLint was found (and gte() requires a valid version)
53
- const eslintVersion = ESLint.version || '8.0.0';
54
- return (0, semver_1.gte)(eslintVersion, '9.0.0');
55
- }
56
- catch {
57
- // Default to assuming flat config in case ESLint is not yet installed
58
- return true;
59
- }
59
+ // Nothing to go on: default to flat config, the default for every supported
60
+ // ESLint version (v9+).
61
+ return true;
60
62
  }
@@ -3,26 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveESLintClass = resolveESLintClass;
4
4
  const flat_config_1 = require("../utils/flat-config");
5
5
  async function resolveESLintClass(opts) {
6
+ const shouldESLintUseFlatConfig = typeof opts?.useFlatConfigOverrideVal === 'boolean'
7
+ ? opts.useFlatConfigOverrideVal
8
+ : (0, flat_config_1.useFlatConfig)();
9
+ // `loadESLint` (added in eslint 8.57.0) resolves the correct ESLint class
10
+ // for flat vs eslintrc config; it exists in every supported version (v9+).
11
+ let eslintModule;
12
+ // Only a failed import means eslint is missing; let loadESLint errors surface.
6
13
  try {
7
- const shouldESLintUseFlatConfig = typeof opts?.useFlatConfigOverrideVal === 'boolean'
8
- ? opts.useFlatConfigOverrideVal
9
- : (0, flat_config_1.useFlatConfig)();
10
- // In eslint 8.57.0 (the final v8 version), a dedicated API was added for resolving the correct ESLint class.
11
- const eslintModule = (await import('eslint'));
12
- if (typeof eslintModule.loadESLint === 'function') {
13
- return (await eslintModule.loadESLint({
14
- useFlatConfig: shouldESLintUseFlatConfig,
15
- }));
16
- }
17
- // Explicitly use the FlatESLint and LegacyESLint classes here because the ESLint class points at a different one based on ESLint v8 vs ESLint v9
18
- // But the decision on which one to use is not just based on the major version of ESLint.
19
- const { LegacyESLint, FlatESLint } = await import('eslint/use-at-your-own-risk');
20
- // LegacyESLint's type no longer structurally matches the flat ESLint class
21
- // in v9 type defs (new static members like defaultConfig, fromOptionsModule),
22
- // but at runtime either class is an appropriate return value here.
23
- return (shouldESLintUseFlatConfig ? FlatESLint : LegacyESLint);
14
+ eslintModule = (await import('eslint'));
24
15
  }
25
16
  catch {
26
17
  throw new Error('Unable to find `eslint`. Ensure a valid `eslint` version is installed.');
27
18
  }
19
+ return (await eslintModule.loadESLint({
20
+ useFlatConfig: shouldESLintUseFlatConfig,
21
+ }));
28
22
  }
@@ -1,17 +1,16 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare const nxVersion: any;
3
- export declare const minSupportedEslintVersion = "8.0.0";
3
+ export declare const minSupportedEslintVersion = "9.0.0";
4
4
  export declare const eslintConfigPrettierVersion = "^10.0.0";
5
- export declare const eslintrcVersion = "^2.1.1";
5
+ export declare const eslintrcVersion = "^3.0.0";
6
6
  export declare const jsoncEslintParserVersion = "^2.1.0";
7
7
  export declare const eslintCompat = "^1.1.1";
8
8
  export declare const eslintVersion = "^9.8.0";
9
- export declare const typescriptESLintVersion = "^8.40.0";
9
+ export declare const typescriptESLintVersion = "^8.58.0";
10
10
  type EslintVersions = {
11
11
  eslintVersion: string;
12
12
  typescriptESLintVersion: string;
13
13
  };
14
14
  export declare function versions(tree: Tree): EslintVersions;
15
15
  export declare function getInstalledEslintVersion(tree?: Tree): string | null;
16
- export declare function getInstalledEslintMajorVersion(tree?: Tree): number | null;
17
16
  export {};
@@ -3,27 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typescriptESLintVersion = exports.eslintVersion = exports.eslintCompat = exports.jsoncEslintParserVersion = exports.eslintrcVersion = exports.eslintConfigPrettierVersion = exports.minSupportedEslintVersion = exports.nxVersion = void 0;
4
4
  exports.versions = versions;
5
5
  exports.getInstalledEslintVersion = getInstalledEslintVersion;
6
- exports.getInstalledEslintMajorVersion = getInstalledEslintMajorVersion;
7
6
  const internal_1 = require("@nx/devkit/internal");
8
7
  const path_1 = require("path");
9
8
  const semver_1 = require("semver");
10
9
  exports.nxVersion = require((0, path_1.join)('@nx/eslint', 'package.json')).version;
11
- exports.minSupportedEslintVersion = '8.0.0';
10
+ exports.minSupportedEslintVersion = '9.0.0';
12
11
  exports.eslintConfigPrettierVersion = '^10.0.0';
13
- exports.eslintrcVersion = '^2.1.1';
12
+ exports.eslintrcVersion = '^3.0.0';
14
13
  exports.jsoncEslintParserVersion = '^2.1.0';
15
14
  exports.eslintCompat = '^1.1.1';
16
15
  exports.eslintVersion = '^9.8.0';
17
- exports.typescriptESLintVersion = '^8.40.0';
16
+ exports.typescriptESLintVersion = '^8.58.0';
18
17
  const latestVersions = {
19
18
  eslintVersion: exports.eslintVersion,
20
19
  typescriptESLintVersion: exports.typescriptESLintVersion,
21
20
  };
22
21
  const versionMap = {
23
- 8: {
24
- eslintVersion: '~8.57.0',
25
- typescriptESLintVersion: '^8.40.0',
26
- },
22
+ 9: { eslintVersion: '^9.8.0', typescriptESLintVersion: '^8.58.0' },
27
23
  };
28
24
  function versions(tree) {
29
25
  const installedEslintVersion = getInstalledEslintVersion(tree);
@@ -31,10 +27,7 @@ function versions(tree) {
31
27
  const eslintMajorVersion = (0, semver_1.major)(installedEslintVersion);
32
28
  return versionMap[eslintMajorVersion] ?? latestVersions;
33
29
  }
34
- // No ESLint declared yet fresh installs always go to the latest supported
35
- // ESLint stack (v9 + typescript-eslint v8). The eslintrc config shape is
36
- // still respected at the config-file level when `useFlatConfig(tree)` is
37
- // false; only the installed package versions move forward.
30
+ // No ESLint declared yet, so fresh installs go to the latest supported stack.
38
31
  return latestVersions;
39
32
  }
40
33
  function getInstalledEslintVersion(tree) {
@@ -43,7 +36,3 @@ function getInstalledEslintVersion(tree) {
43
36
  }
44
37
  return (0, internal_1.getDeclaredPackageVersion)(tree, 'eslint');
45
38
  }
46
- function getInstalledEslintMajorVersion(tree) {
47
- const installedEslintVersion = getInstalledEslintVersion(tree);
48
- return installedEslintVersion ? (0, semver_1.major)(installedEslintVersion) : null;
49
- }
package/migrations.json CHANGED
@@ -15,6 +15,15 @@
15
15
  "description": "Rename imports of `createNodesV2` from `@nx/eslint/plugin` to the canonical `createNodes` export.",
16
16
  "implementation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes",
17
17
  "documentation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md"
18
+ },
19
+ "update-23-1-0-convert-to-flat-config": {
20
+ "version": "23.1.0-beta.0",
21
+ "requires": {
22
+ "eslint": ">=9.0.0"
23
+ },
24
+ "description": "Convert remaining ESLint configs to flat config for ESLint v9 and keep the workspace lint-passing, disabling rules whose preset defaults changed.",
25
+ "implementation": "./dist/src/migrations/update-23-1-0/convert-to-flat-config",
26
+ "prompt": "./dist/src/migrations/update-23-1-0/convert-to-flat-config.md"
18
27
  }
19
28
  },
20
29
  "packageJsonUpdates": {
@@ -145,6 +154,118 @@
145
154
  "alwaysAddToPackageJson": false
146
155
  }
147
156
  }
157
+ },
158
+ "23.1.0": {
159
+ "version": "23.1.0-beta.0",
160
+ "requires": {
161
+ "eslint": ">=8.0.0 <9.0.0"
162
+ },
163
+ "packages": {
164
+ "eslint": {
165
+ "version": "^9.8.0",
166
+ "alwaysAddToPackageJson": false
167
+ },
168
+ "typescript-eslint": {
169
+ "version": "^8.40.0",
170
+ "alwaysAddToPackageJson": false
171
+ },
172
+ "@typescript-eslint/eslint-plugin": {
173
+ "version": "^8.40.0",
174
+ "alwaysAddToPackageJson": false
175
+ },
176
+ "@typescript-eslint/parser": {
177
+ "version": "^8.40.0",
178
+ "alwaysAddToPackageJson": false
179
+ },
180
+ "@typescript-eslint/utils": {
181
+ "version": "^8.40.0",
182
+ "alwaysAddToPackageJson": false
183
+ },
184
+ "@typescript-eslint/type-utils": {
185
+ "version": "^8.40.0",
186
+ "alwaysAddToPackageJson": false
187
+ },
188
+ "@typescript-eslint/rule-tester": {
189
+ "version": "^8.40.0",
190
+ "alwaysAddToPackageJson": false
191
+ },
192
+ "@typescript-eslint/scope-manager": {
193
+ "version": "^8.40.0",
194
+ "alwaysAddToPackageJson": false
195
+ },
196
+ "@typescript-eslint/typescript-estree": {
197
+ "version": "^8.40.0",
198
+ "alwaysAddToPackageJson": false
199
+ },
200
+ "eslint-config-prettier": {
201
+ "version": "^10.0.0",
202
+ "alwaysAddToPackageJson": false
203
+ }
204
+ }
205
+ },
206
+ "23.1.0-typescript-eslint": {
207
+ "version": "23.1.0-beta.0",
208
+ "requires": {
209
+ "typescript-eslint": ">8.0.0 <8.58.0"
210
+ },
211
+ "packages": {
212
+ "typescript-eslint": {
213
+ "version": "^8.58.0"
214
+ },
215
+ "@typescript-eslint/eslint-plugin": {
216
+ "version": "^8.58.0"
217
+ },
218
+ "@typescript-eslint/parser": {
219
+ "version": "^8.58.0"
220
+ },
221
+ "@typescript-eslint/utils": {
222
+ "version": "^8.58.0"
223
+ },
224
+ "@typescript-eslint/rule-tester": {
225
+ "version": "^8.58.0",
226
+ "alwaysAddToPackageJson": false
227
+ },
228
+ "@typescript-eslint/scope-manager": {
229
+ "version": "^8.58.0",
230
+ "alwaysAddToPackageJson": false
231
+ },
232
+ "@typescript-eslint/typescript-estree": {
233
+ "version": "^8.58.0",
234
+ "alwaysAddToPackageJson": false
235
+ }
236
+ }
237
+ },
238
+ "23.1.0-@typescript-eslint": {
239
+ "version": "23.1.0-beta.0",
240
+ "requires": {
241
+ "@typescript-eslint/eslint-plugin": ">8.0.0 <8.58.0"
242
+ },
243
+ "packages": {
244
+ "typescript-eslint": {
245
+ "version": "^8.58.0"
246
+ },
247
+ "@typescript-eslint/eslint-plugin": {
248
+ "version": "^8.58.0"
249
+ },
250
+ "@typescript-eslint/parser": {
251
+ "version": "^8.58.0"
252
+ },
253
+ "@typescript-eslint/utils": {
254
+ "version": "^8.58.0"
255
+ },
256
+ "@typescript-eslint/rule-tester": {
257
+ "version": "^8.58.0",
258
+ "alwaysAddToPackageJson": false
259
+ },
260
+ "@typescript-eslint/scope-manager": {
261
+ "version": "^8.58.0",
262
+ "alwaysAddToPackageJson": false
263
+ },
264
+ "@typescript-eslint/typescript-estree": {
265
+ "version": "^8.58.0",
266
+ "alwaysAddToPackageJson": false
267
+ }
268
+ }
148
269
  }
149
270
  }
150
271
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "23.0.0",
3
+ "version": "23.1.0-beta.0",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -72,18 +72,18 @@
72
72
  },
73
73
  "peerDependencies": {
74
74
  "@zkochan/js-yaml": "0.0.7",
75
- "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0",
76
- "@nx/jest": "23.0.0"
75
+ "eslint": "^9.0.0 || ^10.0.0",
76
+ "@nx/jest": "23.1.0-beta.0"
77
77
  },
78
78
  "dependencies": {
79
79
  "semver": "^7.6.3",
80
80
  "tslib": "^2.3.0",
81
- "typescript": "~5.9.2",
82
- "@nx/devkit": "23.0.0",
83
- "@nx/js": "23.0.0"
81
+ "typescript": "~6.0.3",
82
+ "@nx/devkit": "23.1.0-beta.0",
83
+ "@nx/js": "23.1.0-beta.0"
84
84
  },
85
85
  "devDependencies": {
86
- "nx": "23.0.0"
86
+ "nx": "23.1.0-beta.0"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@nx/jest": {