@angular-eslint/builder 19.5.1-alpha.7 → 19.5.1-alpha.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"lint.impl.d.ts","sourceRoot":"","sources":["../src/lint.impl.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;;AAMvC,wBA8LE"}
1
+ {"version":3,"file":"lint.impl.d.ts","sourceRoot":"","sources":["../src/lint.impl.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;;AAMvC,wBA0ME"}
package/dist/lint.impl.js CHANGED
@@ -5,135 +5,147 @@ const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const eslint_utils_1 = require("./utils/eslint-utils");
7
7
  exports.default = (0, architect_1.createBuilder)(async (options, context) => {
8
- const systemRoot = context.workspaceRoot;
9
- // eslint resolves files relative to the current working directory.
10
- // We want these paths to always be resolved relative to the workspace
11
- // root to be able to run the lint executor from any subfolder.
12
- process.chdir(systemRoot);
13
- const projectName = context.target?.project ?? '<???>';
14
- const printInfo = options.format && !options.silent;
15
- if (printInfo) {
16
- console.info(`\nLinting ${JSON.stringify(projectName)}...`);
17
- }
18
- const eslintConfigPath = options.eslintConfig
19
- ? (0, path_1.resolve)(systemRoot, options.eslintConfig)
20
- : undefined;
21
- options.cacheLocation = options.cacheLocation
22
- ? (0, path_1.join)(options.cacheLocation, projectName)
23
- : null;
24
- /**
25
- * Until ESLint v9 is released and the new so called flat config is the default
26
- * we only want to support it if the user has explicitly opted into it by converting
27
- * their root ESLint config to use a supported flat config file name.
28
- */
29
- const useFlatConfig = eslint_utils_1.supportedFlatConfigNames.some((name) => (0, fs_1.existsSync)((0, path_1.join)(systemRoot, name)));
30
- const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, options, useFlatConfig);
31
- const version = ESLint?.version?.split('.');
32
- if (!version ||
33
- version.length < 2 ||
34
- Number(version[0]) < 7 ||
35
- (Number(version[0]) === 7 && Number(version[1]) < 6)) {
36
- throw new Error('ESLint must be version 7.6 or higher.');
37
- }
38
- let lintResults = [];
39
8
  try {
40
- lintResults = await eslint.lintFiles(options.lintFilePatterns);
41
- }
42
- catch (err) {
43
- if (err instanceof Error &&
44
- err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
45
- let eslintConfigPathForError = `for ${projectName}`;
46
- const projectMetadata = await context.getProjectMetadata(projectName);
47
- if (projectMetadata?.root) {
48
- const { root } = projectMetadata;
49
- eslintConfigPathForError =
50
- resolveESLintConfigPath(root) ?? '';
51
- }
52
- console.error(`
9
+ const systemRoot = context.workspaceRoot;
10
+ // eslint resolves files relative to the current working directory.
11
+ // We want these paths to always be resolved relative to the workspace
12
+ // root to be able to run the lint executor from any subfolder.
13
+ process.chdir(systemRoot);
14
+ const projectName = context.target?.project ?? '<???>';
15
+ const printInfo = options.format && !options.silent;
16
+ if (printInfo) {
17
+ console.info(`\nLinting ${JSON.stringify(projectName)}...`);
18
+ }
19
+ const eslintConfigPath = options.eslintConfig
20
+ ? (0, path_1.resolve)(systemRoot, options.eslintConfig)
21
+ : undefined;
22
+ options.cacheLocation = options.cacheLocation
23
+ ? (0, path_1.join)(options.cacheLocation, projectName)
24
+ : null;
25
+ /**
26
+ * Until ESLint v9 is released and the new so called flat config is the default
27
+ * we only want to support it if the user has explicitly opted into it by converting
28
+ * their root ESLint config to use a supported flat config file name.
29
+ */
30
+ const useFlatConfig = eslint_utils_1.supportedFlatConfigNames.some((name) => (0, fs_1.existsSync)((0, path_1.join)(systemRoot, name)));
31
+ const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, options, useFlatConfig);
32
+ const version = ESLint?.version?.split('.');
33
+ if (!version ||
34
+ version.length < 2 ||
35
+ Number(version[0]) < 7 ||
36
+ (Number(version[0]) === 7 && Number(version[1]) < 6)) {
37
+ throw new Error('ESLint must be version 7.6 or higher.');
38
+ }
39
+ let lintResults = [];
40
+ try {
41
+ lintResults = await eslint.lintFiles(options.lintFilePatterns);
42
+ }
43
+ catch (err) {
44
+ if (err instanceof Error &&
45
+ err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
46
+ let eslintConfigPathForError = `for ${projectName}`;
47
+ const projectMetadata = await context.getProjectMetadata(projectName);
48
+ if (projectMetadata?.root) {
49
+ const { root } = projectMetadata;
50
+ eslintConfigPathForError =
51
+ resolveESLintConfigPath(root) ?? '';
52
+ }
53
+ console.error(`
53
54
  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}
54
55
 
55
56
  For full guidance on how to resolve this issue, please see https://github.com/angular-eslint/angular-eslint/blob/main/docs/RULES_REQUIRING_TYPE_INFORMATION.md
56
57
  `);
57
- return {
58
- success: false,
59
- };
58
+ return {
59
+ success: false,
60
+ };
61
+ }
62
+ // If some unexpected error, rethrow
63
+ throw err;
60
64
  }
61
- // If some unexpected error, rethrow
62
- throw err;
63
- }
64
- if (lintResults.length === 0) {
65
- const ignoredPatterns = (await Promise.all(options.lintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
66
- .filter((pattern) => !!pattern)
67
- .map((pattern) => `- '${pattern}'`);
68
- if (ignoredPatterns.length) {
69
- throw new Error(`All files matching the following patterns are ignored:\n${ignoredPatterns.join('\n')}\n\nPlease check your '.eslintignore' file.`);
65
+ if (lintResults.length === 0) {
66
+ const ignoredPatterns = (await Promise.all(options.lintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
67
+ .filter((pattern) => !!pattern)
68
+ .map((pattern) => `- '${pattern}'`);
69
+ if (ignoredPatterns.length) {
70
+ throw new Error(`All files matching the following patterns are ignored:\n${ignoredPatterns.join('\n')}\n\nPlease check your '.eslintignore' file.`);
71
+ }
72
+ throw new Error('Invalid lint configuration. Nothing to lint. Please check your lint target pattern(s).');
70
73
  }
71
- throw new Error('Invalid lint configuration. Nothing to lint. Please check your lint target pattern(s).');
72
- }
73
- // output fixes to disk, if applicable based on the options
74
- await ESLint.outputFixes(lintResults);
75
- const formatter = await eslint.loadFormatter(options.format);
76
- let totalErrors = 0;
77
- let totalWarnings = 0;
78
- const reportOnlyErrors = options.quiet;
79
- const maxWarnings = options.maxWarnings;
80
- /**
81
- * Depending on user configuration we may not want to report on all the
82
- * results, so we need to adjust them before formatting.
83
- */
84
- const finalLintResults = lintResults
85
- .map((result) => {
86
- totalErrors += result.errorCount;
87
- totalWarnings += result.warningCount;
88
- if (result.errorCount || (result.warningCount && !reportOnlyErrors)) {
89
- if (reportOnlyErrors) {
90
- // Collect only errors (Linter.Severity === 2)
91
- result.messages = result.messages.filter(({ severity }) => severity === 2);
74
+ // output fixes to disk, if applicable based on the options
75
+ await ESLint.outputFixes(lintResults);
76
+ const formatter = await eslint.loadFormatter(options.format);
77
+ let totalErrors = 0;
78
+ let totalWarnings = 0;
79
+ const reportOnlyErrors = options.quiet;
80
+ const maxWarnings = options.maxWarnings;
81
+ /**
82
+ * Depending on user configuration we may not want to report on all the
83
+ * results, so we need to adjust them before formatting.
84
+ */
85
+ const finalLintResults = lintResults
86
+ .map((result) => {
87
+ totalErrors += result.errorCount;
88
+ totalWarnings += result.warningCount;
89
+ if (result.errorCount || (result.warningCount && !reportOnlyErrors)) {
90
+ if (reportOnlyErrors) {
91
+ // Collect only errors (Linter.Severity === 2)
92
+ result.messages = result.messages.filter(({ severity }) => severity === 2);
93
+ }
94
+ return result;
92
95
  }
93
- return result;
96
+ return null;
97
+ })
98
+ // Filter out the null values
99
+ .filter(Boolean);
100
+ const hasWarningsToPrint = totalWarnings > 0 && !reportOnlyErrors;
101
+ const hasErrorsToPrint = totalErrors > 0;
102
+ /**
103
+ * It's important that we format all results together so that custom
104
+ * formatters, such as checkstyle, can provide a valid output for the
105
+ * whole project being linted.
106
+ *
107
+ * Additionally, apart from when outputting to a file, we want to always
108
+ * log (even when no results) because different formatters handled the
109
+ * "no results" case differently.
110
+ */
111
+ const formattedResults = await formatter.format(finalLintResults);
112
+ if (options.outputFile) {
113
+ const pathToOutputFile = (0, path_1.join)(systemRoot, options.outputFile);
114
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(pathToOutputFile), { recursive: true });
115
+ (0, fs_1.writeFileSync)(pathToOutputFile, formattedResults);
94
116
  }
95
- return null;
96
- })
97
- // Filter out the null values
98
- .filter(Boolean);
99
- const hasWarningsToPrint = totalWarnings > 0 && !reportOnlyErrors;
100
- const hasErrorsToPrint = totalErrors > 0;
101
- /**
102
- * It's important that we format all results together so that custom
103
- * formatters, such as checkstyle, can provide a valid output for the
104
- * whole project being linted.
105
- *
106
- * Additionally, apart from when outputting to a file, we want to always
107
- * log (even when no results) because different formatters handled the
108
- * "no results" case differently.
109
- */
110
- const formattedResults = await formatter.format(finalLintResults);
111
- if (options.outputFile) {
112
- const pathToOutputFile = (0, path_1.join)(systemRoot, options.outputFile);
113
- (0, fs_1.mkdirSync)((0, path_1.dirname)(pathToOutputFile), { recursive: true });
114
- (0, fs_1.writeFileSync)(pathToOutputFile, formattedResults);
115
- }
116
- else {
117
- console.info(formattedResults);
118
- }
119
- if (hasWarningsToPrint && printInfo) {
120
- console.warn('Lint warnings found in the listed files.\n');
121
- }
122
- if (hasErrorsToPrint && printInfo) {
123
- console.error('Lint errors found in the listed files.\n');
124
- }
125
- if ((totalWarnings === 0 || reportOnlyErrors) &&
126
- totalErrors === 0 &&
127
- printInfo) {
128
- console.info('All files pass linting.\n');
117
+ else {
118
+ console.info(formattedResults);
119
+ }
120
+ if (hasWarningsToPrint && printInfo) {
121
+ console.warn('Lint warnings found in the listed files.\n');
122
+ }
123
+ if (hasErrorsToPrint && printInfo) {
124
+ console.error('Lint errors found in the listed files.\n');
125
+ }
126
+ if ((totalWarnings === 0 || reportOnlyErrors) &&
127
+ totalErrors === 0 &&
128
+ printInfo) {
129
+ console.info('All files pass linting.\n');
130
+ }
131
+ const tooManyWarnings = maxWarnings >= 0 && totalWarnings > maxWarnings;
132
+ if (tooManyWarnings && printInfo) {
133
+ console.error(`Found ${totalWarnings} warnings, which exceeds your configured limit (${options.maxWarnings}). Either increase your maxWarnings limit or fix some of the lint warnings.`);
134
+ }
135
+ return {
136
+ success: options.force || (totalErrors === 0 && !tooManyWarnings),
137
+ };
129
138
  }
130
- const tooManyWarnings = maxWarnings >= 0 && totalWarnings > maxWarnings;
131
- if (tooManyWarnings && printInfo) {
132
- console.error(`Found ${totalWarnings} warnings, which exceeds your configured limit (${options.maxWarnings}). Either increase your maxWarnings limit or fix some of the lint warnings.`);
139
+ catch (err) {
140
+ let errorMessage = 'Unknown error';
141
+ if (err instanceof Error) {
142
+ errorMessage = `Error when running ESLint: ${err.message}`;
143
+ }
144
+ return {
145
+ success: false,
146
+ error: String(errorMessage),
147
+ };
133
148
  }
134
- return {
135
- success: options.force || (totalErrors === 0 && !tooManyWarnings),
136
- };
137
149
  });
138
150
  function resolveESLintConfigPath(projectRoot) {
139
151
  const rcPath = (0, path_1.join)(projectRoot, '.eslintrc.json');
@@ -1 +1 @@
1
- {"version":3,"file":"eslint-utils.d.ts","sourceRoot":"","sources":["../../src/utils/eslint-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,eAAO,MAAM,wBAAwB,UAIpC,CAAC;AAuBF,wBAAsB,2BAA2B,CAC/C,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,MAAM,EACf,aAAa,UAAQ;;;GA6FtB"}
1
+ {"version":3,"file":"eslint-utils.d.ts","sourceRoot":"","sources":["../../src/utils/eslint-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,eAAO,MAAM,wBAAwB,UAOpC,CAAC;AAsBF,wBAAsB,2BAA2B,CAC/C,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,MAAM,EACf,aAAa,UAAQ;;;GA6FtB"}
@@ -6,6 +6,9 @@ exports.supportedFlatConfigNames = [
6
6
  'eslint.config.js',
7
7
  'eslint.config.mjs',
8
8
  'eslint.config.cjs',
9
+ 'eslint.config.ts',
10
+ 'eslint.config.mts',
11
+ 'eslint.config.cts',
9
12
  ];
10
13
  async function resolveESLintClass(useFlatConfig = false) {
11
14
  try {
@@ -18,7 +21,6 @@ async function resolveESLintClass(useFlatConfig = false) {
18
21
  if (!useFlatConfig) {
19
22
  return eslint.ESLint;
20
23
  }
21
- // eslint-disable-next-line @typescript-eslint/no-var-requires
22
24
  const { FlatESLint } = require('eslint/use-at-your-own-risk');
23
25
  return FlatESLint;
24
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/builder",
3
- "version": "19.5.1-alpha.7",
3
+ "version": "19.5.1-alpha.9",
4
4
  "description": "Angular CLI builder for ESLint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",