@nx/eslint 17.0.4 → 17.0.6

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 (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +0 -6
  4. package/migrations.json +0 -68
  5. package/package.json +8 -9
  6. package/src/executors/lint/hasher.js +1 -1
  7. package/src/executors/lint/lint.impl.js +33 -67
  8. package/src/executors/lint/schema.d.ts +0 -1
  9. package/src/executors/lint/schema.json +3 -7
  10. package/src/executors/lint/utility/eslint-utils.js +1 -5
  11. package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -6
  12. package/src/generators/convert-to-flat-config/converters/json-converter.js +33 -28
  13. package/src/generators/convert-to-flat-config/generator.js +17 -73
  14. package/src/generators/convert-to-flat-config/schema.json +1 -1
  15. package/src/generators/init/global-eslint-config.js +5 -9
  16. package/src/generators/init/init-migration.d.ts +1 -1
  17. package/src/generators/init/init-migration.js +14 -53
  18. package/src/generators/init/init.d.ts +5 -5
  19. package/src/generators/init/init.js +35 -63
  20. package/src/generators/lint-project/lint-project.d.ts +3 -9
  21. package/src/generators/lint-project/lint-project.js +40 -76
  22. package/src/generators/utils/eslint-file.d.ts +5 -2
  23. package/src/generators/utils/eslint-file.js +30 -37
  24. package/src/generators/utils/flat-config/ast-utils.d.ts +5 -4
  25. package/src/generators/utils/flat-config/ast-utils.js +38 -35
  26. package/src/generators/utils/flat-config/path-utils.d.ts +1 -2
  27. package/src/generators/utils/flat-config/path-utils.js +12 -9
  28. package/src/generators/workspace-rule/files/__name__.ts__tmpl__ +2 -2
  29. package/src/generators/workspace-rule/schema.json +1 -1
  30. package/src/generators/workspace-rule/workspace-rule.js +2 -7
  31. package/src/generators/workspace-rules-project/files/tsconfig.json__tmpl__ +1 -2
  32. package/src/generators/workspace-rules-project/schema.json +1 -1
  33. package/src/generators/workspace-rules-project/workspace-rules-project.d.ts +2 -3
  34. package/src/generators/workspace-rules-project/workspace-rules-project.js +9 -11
  35. package/src/migrations/update-15-0-0/add-eslint-inputs.js +2 -2
  36. package/src/migrations/update-15-7-1/add-eslint-ignore.js +2 -2
  37. package/src/utils/versions.d.ts +2 -2
  38. package/src/utils/versions.js +2 -2
  39. package/plugin.d.ts +0 -1
  40. package/plugin.js +0 -5
  41. package/src/generators/init/schema.json +0 -28
  42. package/src/generators/lint-project/setup-root-eslint.d.ts +0 -7
  43. package/src/generators/lint-project/setup-root-eslint.js +0 -33
  44. package/src/generators/utils/plugin.d.ts +0 -2
  45. package/src/generators/utils/plugin.js +0 -11
  46. package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
  47. package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
  48. package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
  49. package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
  50. package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
  51. package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +0 -107
  52. package/src/plugins/plugin.d.ts +0 -6
  53. package/src/plugins/plugin.js +0 -117
  54. package/src/utils/config-file.d.ts +0 -4
  55. package/src/utils/config-file.js +0 -18
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,9 +1,4 @@
1
- <p style="text-align: center;">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
- <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
- </picture>
6
- </p>
1
+ <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
7
2
 
8
3
  <div style="text-align: center;">
9
4
 
@@ -20,9 +15,9 @@
20
15
 
21
16
  <hr>
22
17
 
23
- # Nx: Smart Monorepos · Fast CI
18
+ # Nx: Smart, Fast and Extensible Build System
24
19
 
25
- Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
20
+ Nx is a next generation build system with first class monorepo support and powerful integrations.
26
21
 
27
22
  ## Getting Started
28
23
 
@@ -62,5 +57,5 @@ npx nx@latest init
62
57
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
63
58
 
64
59
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
65
- width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
60
+ width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
66
61
 
package/generators.json CHANGED
@@ -2,12 +2,6 @@
2
2
  "name": "nx/eslint",
3
3
  "version": "0.1",
4
4
  "generators": {
5
- "init": {
6
- "factory": "./src/generators/init/init#initEsLint",
7
- "schema": "./src/generators/init/schema.json",
8
- "description": "Set up the ESLint plugin.",
9
- "hidden": true
10
- },
11
5
  "workspace-rules-project": {
12
6
  "factory": "./src/generators/workspace-rules-project/workspace-rules-project#lintWorkspaceRulesProjectGenerator",
13
7
  "schema": "./src/generators/workspace-rules-project/schema.json",
package/migrations.json CHANGED
@@ -27,21 +27,6 @@
27
27
  "version": "17.0.0-beta.7",
28
28
  "description": "update-17-0-0-rename-to-eslint",
29
29
  "implementation": "./src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint"
30
- },
31
- "update-typescript-eslint": {
32
- "version": "17.1.0-beta.1",
33
- "description": "Updates for @typescript-utils/utils v6.9.1+",
34
- "implementation": "./src/migrations/update-17-1-0/update-typescript-eslint"
35
- },
36
- "simplify-eslint-patterns": {
37
- "version": "17.2.0-beta.0",
38
- "description": "Simplify eslintFilePatterns",
39
- "implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
40
- },
41
- "move-options-to-target-defaults": {
42
- "version": "17.2.9",
43
- "description": "Move executor options to target defaults",
44
- "implementation": "./src/migrations/update-17-2-9/move-options-to-target-defaults"
45
30
  }
46
31
  },
47
32
  "packageJsonUpdates": {
@@ -97,59 +82,6 @@
97
82
  "version": "^9.0.0"
98
83
  }
99
84
  }
100
- },
101
- "17.1.0": {
102
- "version": "17.1.0-beta.1",
103
- "packages": {
104
- "@typescript-eslint/parser": {
105
- "version": "^6.9.1"
106
- },
107
- "@typescript-eslint/eslint-plugin": {
108
- "version": "^6.9.1"
109
- },
110
- "@typescript-eslint/utils": {
111
- "version": "^6.9.1"
112
- }
113
- }
114
- },
115
- "17.2.0": {
116
- "version": "17.2.0-beta.2",
117
- "packages": {
118
- "eslint": {
119
- "version": "~8.48.0"
120
- }
121
- }
122
- },
123
- "17.3.0": {
124
- "version": "17.3.0-beta.0",
125
- "packages": {
126
- "@typescript-eslint/parser": {
127
- "version": "^6.13.2"
128
- },
129
- "@typescript-eslint/eslint-plugin": {
130
- "version": "^6.13.2"
131
- },
132
- "@typescript-eslint/utils": {
133
- "version": "^6.13.2"
134
- }
135
- }
136
- },
137
- "18.2.0": {
138
- "version": "18.2.0-beta.0",
139
- "packages": {
140
- "@typescript-eslint/parser": {
141
- "version": "^7.3.0"
142
- },
143
- "@typescript-eslint/eslint-plugin": {
144
- "version": "^7.3.0"
145
- },
146
- "@typescript-eslint/utils": {
147
- "version": "^7.3.0"
148
- },
149
- "eslint": {
150
- "version": "~8.57.0"
151
- }
152
- }
153
85
  }
154
86
  }
155
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "17.0.4",
3
+ "version": "v17.0.6",
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": {
@@ -27,21 +27,20 @@
27
27
  "requirements": {},
28
28
  "migrations": "./migrations.json"
29
29
  },
30
- "generators": "./generators.json",
31
30
  "executors": "./executors.json",
31
+ "generators": "./generators.json",
32
32
  "peerDependencies": {
33
- "js-yaml": "4.1.0"
33
+ "eslint": "^8.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@nx/devkit": "17.0.4",
37
- "@nx/js": "17.0.4",
38
- "eslint": "^8.0.0",
39
36
  "tslib": "^2.3.0",
40
- "typescript": "~5.4.2",
41
- "@nx/linter": "17.0.4"
37
+ "@nx/devkit": "v17.0.6",
38
+ "@nx/js": "v17.0.6",
39
+ "typescript": "~5.1.3",
40
+ "@nx/linter": "v17.0.6"
42
41
  },
43
42
  "peerDependenciesMeta": {
44
- "js-yaml": {
43
+ "eslint": {
45
44
  "optional": true
46
45
  }
47
46
  },
@@ -17,7 +17,7 @@ async function run(task, context) {
17
17
  }
18
18
  const nodes = {};
19
19
  const hashes = [];
20
- for (const d of Object.keys(res.details.nodes).sort()) {
20
+ for (const d of Object.keys(res.details.nodes)) {
21
21
  if (d.indexOf('$fileset') === -1) {
22
22
  nodes[d] = res.details.nodes[d];
23
23
  hashes.push(res.details.nodes[d]);
@@ -4,7 +4,6 @@ const devkit_1 = require("@nx/devkit");
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const eslint_utils_1 = require("./utility/eslint-utils");
7
- const utils_1 = require("nx/src/tasks-runner/utils");
8
7
  async function run(options, context) {
9
8
  // this is only used for the hasher
10
9
  delete options.hasTypeAwareRules;
@@ -14,36 +13,31 @@ async function run(options, context) {
14
13
  // root to be able to run the lint executor from any subfolder.
15
14
  process.chdir(systemRoot);
16
15
  const projectName = context.projectName || '<???>';
17
- const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
18
16
  const printInfo = options.format && !options.silent;
19
17
  if (printInfo) {
20
18
  console.info(`\nLinting ${JSON.stringify(projectName)}...`);
21
19
  }
20
+ /**
21
+ * We want users to have the option of not specifying the config path, and let
22
+ * eslint automatically resolve the `.eslintrc.json` files in each folder.
23
+ */
24
+ let eslintConfigPath = options.eslintConfig
25
+ ? (0, path_1.resolve)(systemRoot, options.eslintConfig)
26
+ : undefined;
22
27
  options.cacheLocation = options.cacheLocation
23
28
  ? (0, devkit_1.joinPathFragments)(options.cacheLocation, projectName)
24
29
  : undefined;
25
- const { printConfig, errorOnUnmatchedPattern, ...normalizedOptions } = options;
30
+ const { printConfig, ...normalizedOptions } = options;
26
31
  /**
27
32
  * Until ESLint v9 is released and the new so called flat config is the default
28
33
  * we only want to support it if the user has explicitly opted into it by converting
29
34
  * their root ESLint config to use eslint.config.js
30
35
  */
31
36
  const hasFlatConfig = (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'eslint.config.js'));
32
- // while standard eslint uses by default closest config to the file, if otherwise not specified,
33
- // the flat config would always use the root config, so we need to explicitly set it to the local one
34
- if (hasFlatConfig && !normalizedOptions.eslintConfig) {
35
- const eslintConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'eslint.config.js');
36
- if ((0, fs_1.existsSync)(eslintConfigPath)) {
37
- normalizedOptions.eslintConfig = eslintConfigPath;
38
- }
37
+ if (!eslintConfigPath && hasFlatConfig) {
38
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
39
+ eslintConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'eslint.config.js');
39
40
  }
40
- /**
41
- * We want users to have the option of not specifying the config path, and let
42
- * eslint automatically resolve the `.eslintrc.json` files in each folder.
43
- */
44
- let eslintConfigPath = normalizedOptions.eslintConfig
45
- ? (0, path_1.resolve)(systemRoot, normalizedOptions.eslintConfig)
46
- : undefined;
47
41
  const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, normalizedOptions, hasFlatConfig);
48
42
  const version = ESLint.version?.split('.');
49
43
  if (!version ||
@@ -68,26 +62,18 @@ async function run(options, context) {
68
62
  }
69
63
  }
70
64
  let lintResults = [];
71
- const normalizedLintFilePatterns = normalizedOptions.lintFilePatterns.map((pattern) => {
72
- return (0, utils_1.interpolate)(pattern, {
73
- workspaceRoot: '',
74
- projectRoot,
75
- projectName: context.projectName,
76
- });
77
- });
78
65
  try {
79
- lintResults = await eslint.lintFiles(normalizedLintFilePatterns);
66
+ lintResults = await eslint.lintFiles(normalizedOptions.lintFilePatterns);
80
67
  }
81
68
  catch (err) {
82
69
  if (err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
83
- const ruleName = err.message.match(/rule '([^']+)':/)?.[1];
84
70
  let eslintConfigPathForError = `for ${projectName}`;
85
71
  if (context.projectsConfigurations?.projects?.[projectName]?.root) {
86
72
  const { root } = context.projectsConfigurations.projects[projectName];
87
73
  eslintConfigPathForError = `\`${root}/.eslintrc.json\``;
88
74
  }
89
75
  console.error(`
90
- Error: You have attempted to use ${ruleName ? `the lint rule ${ruleName}` : 'a lint rule'} which requires the full TypeScript type-checker to be available, but you do not have \`parserOptions.project\` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config ${eslintConfigPath || eslintConfigPathForError}
76
+ Error: You have attempted to use a lint rule which requires the full TypeScript type-checker to be available, but you do not have \`parserOptions.project\` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config ${eslintConfigPath || eslintConfigPathForError}
91
77
 
92
78
  Please see https://nx.dev/guides/eslint for full guidance on how to resolve this issue.
93
79
  `);
@@ -98,8 +84,8 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
98
84
  // If some unexpected error, rethrow
99
85
  throw err;
100
86
  }
101
- if (lintResults.length === 0 && errorOnUnmatchedPattern) {
102
- const ignoredPatterns = (await Promise.all(normalizedLintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
87
+ if (lintResults.length === 0) {
88
+ const ignoredPatterns = (await Promise.all(normalizedOptions.lintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
103
89
  .filter((pattern) => !!pattern)
104
90
  .map((pattern) => `- '${pattern}'`);
105
91
  if (ignoredPatterns.length) {
@@ -118,6 +104,14 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
118
104
  lintResults = ESLint.getErrorResults(lintResults);
119
105
  }
120
106
  const formatter = await eslint.loadFormatter(normalizedOptions.format);
107
+ let totalErrors = 0;
108
+ let totalWarnings = 0;
109
+ for (const result of lintResults) {
110
+ if (result.errorCount || result.warningCount) {
111
+ totalErrors += result.errorCount;
112
+ totalWarnings += result.warningCount;
113
+ }
114
+ }
121
115
  const formattedResults = await formatter.format(lintResults);
122
116
  if (normalizedOptions.outputFile) {
123
117
  const pathToOutputFile = (0, devkit_1.joinPathFragments)(context.root, normalizedOptions.outputFile);
@@ -127,48 +121,20 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
127
121
  else {
128
122
  console.info(formattedResults);
129
123
  }
130
- const totals = getTotals(lintResults);
131
- if (printInfo) {
132
- outputPrintInfo(totals);
124
+ if (totalWarnings > 0 && printInfo) {
125
+ console.warn('Lint warnings found in the listed files.\n');
126
+ }
127
+ if (totalErrors > 0 && printInfo) {
128
+ console.error('Lint errors found in the listed files.\n');
129
+ }
130
+ if (totalWarnings === 0 && totalErrors === 0 && printInfo) {
131
+ console.info('All files pass linting.\n');
133
132
  }
134
133
  return {
135
134
  success: normalizedOptions.force ||
136
- (totals.errors === 0 &&
135
+ (totalErrors === 0 &&
137
136
  (normalizedOptions.maxWarnings === -1 ||
138
- totals.warnings <= normalizedOptions.maxWarnings)),
137
+ totalWarnings <= normalizedOptions.maxWarnings)),
139
138
  };
140
139
  }
141
140
  exports.default = run;
142
- function getTotals(lintResults) {
143
- let errors = 0;
144
- let warnings = 0;
145
- let fixableErrors = 0;
146
- let fixableWarnings = 0;
147
- for (const result of lintResults) {
148
- errors += result.errorCount || 0;
149
- warnings += result.warningCount || 0;
150
- fixableErrors += result.fixableErrorCount || 0;
151
- fixableWarnings += result.fixableWarningCount || 0;
152
- }
153
- return {
154
- errors,
155
- warnings,
156
- fixableErrors,
157
- fixableWarnings,
158
- };
159
- }
160
- function pluralizedOutput(word, count) {
161
- return `${count} ${word}${count === 1 ? '' : 's'}`;
162
- }
163
- function outputPrintInfo({ errors, warnings, fixableErrors, fixableWarnings, }) {
164
- const total = warnings + errors;
165
- const totalFixable = fixableErrors + fixableWarnings;
166
- if (total <= 0) {
167
- console.info('\u2714 All files pass linting\n');
168
- return;
169
- }
170
- console.info(`\u2716 ${pluralizedOutput('problem', total)} (${pluralizedOutput('error', errors)}, ${pluralizedOutput('warning', warnings)})\n`);
171
- if (totalFixable <= 0)
172
- return;
173
- console.info(` ${pluralizedOutput('error', fixableErrors)} and ${pluralizedOutput('warning', fixableWarnings)} are potentially fixable with the \`--fix\` option.\n`);
174
- }
@@ -21,7 +21,6 @@ export interface Schema extends JsonObject {
21
21
  resolvePluginsRelativeTo: string | null;
22
22
  reportUnusedDisableDirectives: Linter.StringSeverity | null;
23
23
  printConfig?: string | null;
24
- errorOnUnmatchedPattern?: boolean;
25
24
  }
26
25
 
27
26
  type Formatter =
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 2,
3
3
  "outputCapture": "direct-nodejs",
4
- "$schema": "https://json-schema.org/schema",
4
+ "$schema": "http://json-schema.org/schema",
5
5
  "title": "ESLint Lint Target",
6
6
  "description": "ESLint Lint Target.",
7
7
  "cli": "nx",
@@ -17,7 +17,7 @@
17
17
  "lintFilePatterns": {
18
18
  "type": "array",
19
19
  "description": "One or more files/dirs/globs to pass directly to ESLint's `lintFiles()` method.",
20
- "default": ["{projectRoot}"],
20
+ "default": [],
21
21
  "items": {
22
22
  "type": "string"
23
23
  }
@@ -137,12 +137,8 @@
137
137
  "type": "string",
138
138
  "description": "The equivalent of the `--print-config` flag on the ESLint CLI.",
139
139
  "x-completion-type": "file"
140
- },
141
- "errorOnUnmatchedPattern": {
142
- "type": "boolean",
143
- "description": "When set to false, equivalent of the `--no-error-on-unmatched-pattern` flag on the ESLint CLI.",
144
- "default": true
145
140
  }
146
141
  },
142
+ "required": ["lintFilePatterns"],
147
143
  "examplesFile": "../../../docs/eslint-examples.md"
148
144
  }
@@ -38,6 +38,7 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
38
38
  * not be any html files in the project, so keeping it true would break linting every time
39
39
  */
40
40
  errorOnUnmatchedPattern: false,
41
+ reportUnusedDisableDirectives: options.reportUnusedDisableDirectives || undefined,
41
42
  };
42
43
  if (useFlatConfig) {
43
44
  if (typeof options.useEslintrc !== 'undefined') {
@@ -49,9 +50,6 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
49
50
  if (options.ignorePath !== undefined) {
50
51
  throw new Error('For Flat Config, ESLint removed `ignorePath` and so it is not supported as an option. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
51
52
  }
52
- if (options.reportUnusedDisableDirectives) {
53
- throw new Error('For Flat Config, ESLint removed `reportedUnusedDisableDirectives` and so it is not supported as an option. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
54
- }
55
53
  }
56
54
  else {
57
55
  eslintOptions.rulePaths = options.rulesdir || [];
@@ -63,8 +61,6 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
63
61
  * merge the provided config with others it finds automatically.
64
62
  */
65
63
  eslintOptions.useEslintrc = !options.noEslintrc;
66
- eslintOptions.reportUnusedDisableDirectives =
67
- options.reportUnusedDisableDirectives || undefined;
68
64
  }
69
65
  const eslint = new ESLint(eslintOptions);
70
66
  return {
@@ -1,11 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
- import { ESLint } from 'eslint';
3
2
  /**
4
3
  * Converts an ESLint JSON config to a flat config.
5
4
  * Deletes the original file along with .eslintignore if it exists.
6
5
  */
7
- export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, config: ESLint.ConfigData, ignorePaths: string[]): {
8
- content: string;
9
- addESLintRC: boolean;
10
- addESLintJS: boolean;
11
- };
6
+ export declare function convertEslintJsonToFlatConfig(tree: Tree, root: string, sourceFile: string, destinationFile: string): void;
@@ -2,25 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertEslintJsonToFlatConfig = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
5
6
  const ts = require("typescript");
7
+ const versions_1 = require("../../../utils/versions");
6
8
  const ast_utils_1 = require("../../utils/flat-config/ast-utils");
7
9
  const eslint_file_1 = require("../../utils/eslint-file");
8
- const path_utils_1 = require("../../utils/flat-config/path-utils");
9
10
  /**
10
11
  * Converts an ESLint JSON config to a flat config.
11
12
  * Deletes the original file along with .eslintignore if it exists.
12
13
  */
13
- function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
14
+ function convertEslintJsonToFlatConfig(tree, root, sourceFile, destinationFile) {
14
15
  const importsMap = new Map();
15
16
  const exportElements = [];
16
17
  let isFlatCompatNeeded = false;
17
- let isESLintJSNeeded = false;
18
18
  let combinedConfig = [];
19
19
  let languageOptions = [];
20
+ // read original config
21
+ const config = (0, devkit_1.readJson)(tree, `${root}/${sourceFile}`);
20
22
  if (config.extends) {
21
- const extendsResult = addExtends(importsMap, exportElements, config);
22
- isFlatCompatNeeded = extendsResult.isFlatCompatNeeded;
23
- isESLintJSNeeded = extendsResult.isESLintJSNeeded;
23
+ isFlatCompatNeeded = addExtends(importsMap, exportElements, config, tree);
24
24
  }
25
25
  if (config.plugins) {
26
26
  addPlugins(importsMap, exportElements, config);
@@ -70,7 +70,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
70
70
  override.parser) {
71
71
  isFlatCompatNeeded = true;
72
72
  }
73
- exportElements.push((0, ast_utils_1.generateFlatOverride)(override));
73
+ exportElements.push((0, ast_utils_1.generateFlatOverride)(override, root));
74
74
  });
75
75
  }
76
76
  if (config.ignorePatterns) {
@@ -79,35 +79,36 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
79
79
  : [config.ignorePatterns]).filter((pattern) => !['**/*', '!**/*', 'node_modules'].includes(pattern)); // these are useless in a flat config
80
80
  if (patterns.length > 0) {
81
81
  exportElements.push((0, ast_utils_1.generateAst)({
82
- ignores: patterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
82
+ ignores: patterns.map((path) => (0, ast_utils_1.mapFilePath)(path, root)),
83
83
  }));
84
84
  }
85
85
  }
86
- for (const ignorePath of ignorePaths) {
87
- if (tree.exists(ignorePath)) {
88
- const patterns = tree
89
- .read(ignorePath, 'utf-8')
90
- .split('\n')
91
- .filter((line) => line.length > 0 && line !== 'node_modules')
92
- .map((path) => (0, path_utils_1.mapFilePath)(path));
93
- if (patterns.length > 0) {
94
- exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
95
- }
86
+ if (tree.exists(`${root}/.eslintignore`)) {
87
+ const patterns = tree
88
+ .read(`${root}/.eslintignore`, 'utf-8')
89
+ .split('\n')
90
+ .filter((line) => line.length > 0 && line !== 'node_modules')
91
+ .map((path) => (0, ast_utils_1.mapFilePath)(path, root));
92
+ if (patterns.length > 0) {
93
+ exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
96
94
  }
97
95
  }
96
+ tree.delete((0, path_1.join)(root, sourceFile));
97
+ tree.delete((0, path_1.join)(root, '.eslintignore'));
98
98
  // create the node list and print it to new file
99
99
  const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements, isFlatCompatNeeded);
100
- return {
101
- content: (0, ast_utils_1.stringifyNodeList)(nodeList),
102
- addESLintRC: isFlatCompatNeeded,
103
- addESLintJS: isESLintJSNeeded,
104
- };
100
+ const content = (0, ast_utils_1.stringifyNodeList)(nodeList, root, destinationFile);
101
+ tree.write((0, path_1.join)(root, destinationFile), content);
102
+ if (isFlatCompatNeeded) {
103
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
104
+ '@eslint/eslintrc': versions_1.eslintrcVersion,
105
+ });
106
+ }
105
107
  }
106
108
  exports.convertEslintJsonToFlatConfig = convertEslintJsonToFlatConfig;
107
109
  // add parsed extends to export blocks and add import statements
108
- function addExtends(importsMap, configBlocks, config) {
110
+ function addExtends(importsMap, configBlocks, config, tree) {
109
111
  let isFlatCompatNeeded = false;
110
- let isESLintJSNeeded = false;
111
112
  const extendsConfig = Array.isArray(config.extends)
112
113
  ? config.extends
113
114
  : [config.extends];
@@ -136,7 +137,9 @@ function addExtends(importsMap, configBlocks, config) {
136
137
  }
137
138
  });
138
139
  if (eslintPluginExtends.length) {
139
- isESLintJSNeeded = true;
140
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
141
+ '@eslint/js': versions_1.eslintVersion,
142
+ });
140
143
  importsMap.set('@eslint/js', 'js');
141
144
  eslintPluginExtends.forEach((plugin) => {
142
145
  configBlocks.push(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier('js'), ts.factory.createIdentifier('configs')), ts.factory.createIdentifier(plugin.slice(7)) // strip 'eslint:' prefix
@@ -146,10 +149,12 @@ function addExtends(importsMap, configBlocks, config) {
146
149
  }
147
150
  if (eslintrcConfigs.length) {
148
151
  isFlatCompatNeeded = true;
149
- isESLintJSNeeded = true;
152
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
153
+ '@eslint/js': versions_1.eslintVersion,
154
+ });
150
155
  configBlocks.push((0, ast_utils_1.generatePluginExtendsElement)(eslintrcConfigs));
151
156
  }
152
- return { isFlatCompatNeeded, isESLintJSNeeded };
157
+ return isFlatCompatNeeded;
153
158
  }
154
159
  function addPlugins(importsMap, configBlocks, config) {
155
160
  const mappedPlugins = [];