@nx/eslint 18.0.0-canary.20240201-8762c38 → 18.0.0-canary.20240202-ea5befb

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",
3
- "version": "18.0.0-canary.20240201-8762c38",
3
+ "version": "18.0.0-canary.20240202-ea5befb",
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": {
@@ -33,12 +33,12 @@
33
33
  "js-yaml": "4.1.0"
34
34
  },
35
35
  "dependencies": {
36
- "@nx/devkit": "18.0.0-canary.20240201-8762c38",
37
- "@nx/js": "18.0.0-canary.20240201-8762c38",
36
+ "@nx/devkit": "18.0.0-canary.20240202-ea5befb",
37
+ "@nx/js": "18.0.0-canary.20240202-ea5befb",
38
38
  "eslint": "^8.0.0",
39
39
  "tslib": "^2.3.0",
40
40
  "typescript": "~5.3.2",
41
- "@nx/linter": "18.0.0-canary.20240201-8762c38"
41
+ "@nx/linter": "18.0.0-canary.20240202-ea5befb"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "js-yaml": {
@@ -118,14 +118,6 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
118
118
  lintResults = ESLint.getErrorResults(lintResults);
119
119
  }
120
120
  const formatter = await eslint.loadFormatter(normalizedOptions.format);
121
- let totalErrors = 0;
122
- let totalWarnings = 0;
123
- for (const result of lintResults) {
124
- if (result.errorCount || result.warningCount) {
125
- totalErrors += result.errorCount;
126
- totalWarnings += result.warningCount;
127
- }
128
- }
129
121
  const formattedResults = await formatter.format(lintResults);
130
122
  if (normalizedOptions.outputFile) {
131
123
  const pathToOutputFile = (0, devkit_1.joinPathFragments)(context.root, normalizedOptions.outputFile);
@@ -135,20 +127,48 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
135
127
  else {
136
128
  console.info(formattedResults);
137
129
  }
138
- if (totalWarnings > 0 && printInfo) {
139
- console.warn('Lint warnings found in the listed files.\n');
140
- }
141
- if (totalErrors > 0 && printInfo) {
142
- console.error('Lint errors found in the listed files.\n');
143
- }
144
- if (totalWarnings === 0 && totalErrors === 0 && printInfo) {
145
- console.info('All files pass linting.\n');
130
+ const totals = getTotals(lintResults);
131
+ if (printInfo) {
132
+ outputPrintInfo(totals);
146
133
  }
147
134
  return {
148
135
  success: normalizedOptions.force ||
149
- (totalErrors === 0 &&
136
+ (totals.errors === 0 &&
150
137
  (normalizedOptions.maxWarnings === -1 ||
151
- totalWarnings <= normalizedOptions.maxWarnings)),
138
+ totals.warnings <= normalizedOptions.maxWarnings)),
152
139
  };
153
140
  }
154
141
  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
+ }
@@ -46,7 +46,8 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
46
46
  const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
47
47
  if (eslintFile && !eslintFile.endsWith('.js')) {
48
48
  if (projectConfig.targets) {
49
- const eslintTargets = Object.keys(projectConfig.targets || {}).filter((t) => projectConfig.targets[t].executor === '@nx/eslint:lint');
49
+ const eslintTargets = Object.keys(projectConfig.targets || {}).filter((t) => projectConfig.targets[t].executor === '@nx/eslint:lint' ||
50
+ projectConfig.targets[t].command?.includes('eslint'));
50
51
  let ignorePath;
51
52
  for (const target of eslintTargets) {
52
53
  // remove any obsolete `eslintConfig` options pointing to the old config file
@@ -59,10 +60,14 @@ function convertProjectToFlatConfig(tree, project, projectConfig, nxJson, eslint
59
60
  }
60
61
  (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
61
62
  }
62
- const nxHasLintTargets = Object.keys(nxJson.targetDefaults || {}).some((t) => (t === '@nx/eslint:lint' ||
63
- nxJson.targetDefaults[t].executor === '@nx/eslint:lint') &&
63
+ const nxHasEsLintTargets = Object.keys(nxJson.targetDefaults || {}).some((t) => (t === '@nx/eslint:lint' ||
64
+ nxJson.targetDefaults[t].executor === '@nx/eslint:lint' ||
65
+ nxJson.targetDefaults[t].command?.includes('eslint')) &&
64
66
  projectConfig.targets?.[t]);
65
- if (nxHasLintTargets || eslintTargets.length > 0) {
67
+ const nxHasEsLintPlugin = (nxJson.plugins || []).some((p) => typeof p === 'string'
68
+ ? p === '@nx/eslint/plugin'
69
+ : p.plugin === '@nx/eslint/plugin');
70
+ if (nxHasEsLintTargets || nxHasEsLintPlugin || eslintTargets.length > 0) {
66
71
  convertConfigToFlatConfig(tree, projectConfig.root, eslintFile, 'eslint.config.js', ignorePath);
67
72
  eslintIgnoreFiles.add(`${projectConfig.root}/.eslintignore`);
68
73
  if (ignorePath) {