@angular-eslint/builder 18.3.2-alpha.9 → 18.4.1-alpha.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.
@@ -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;;AAGvC,wBAgME"}
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"}
package/dist/lint.impl.js CHANGED
@@ -15,10 +15,6 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
15
15
  if (printInfo) {
16
16
  console.info(`\nLinting ${JSON.stringify(projectName)}...`);
17
17
  }
18
- /**
19
- * We want users to have the option of not specifying the config path, and let
20
- * eslint automatically resolve the `.eslintrc.json` files in each folder.
21
- */
22
18
  const eslintConfigPath = options.eslintConfig
23
19
  ? (0, path_1.resolve)(systemRoot, options.eslintConfig)
24
20
  : undefined;
@@ -28,9 +24,9 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
28
24
  /**
29
25
  * Until ESLint v9 is released and the new so called flat config is the default
30
26
  * we only want to support it if the user has explicitly opted into it by converting
31
- * their root ESLint config to use eslint.config.js
27
+ * their root ESLint config to use a supported flat config file name.
32
28
  */
33
- const useFlatConfig = (0, fs_1.existsSync)((0, path_1.join)(systemRoot, 'eslint.config.js'));
29
+ const useFlatConfig = eslint_utils_1.supportedFlatConfigNames.some((name) => (0, fs_1.existsSync)((0, path_1.join)(systemRoot, name)));
34
30
  const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, options, useFlatConfig);
35
31
  const version = ESLint?.version?.split('.');
36
32
  if (!version ||
@@ -50,7 +46,8 @@ exports.default = (0, architect_1.createBuilder)(async (options, context) => {
50
46
  const projectMetadata = await context.getProjectMetadata(projectName);
51
47
  if (projectMetadata?.root) {
52
48
  const { root } = projectMetadata;
53
- eslintConfigPathForError = `\`${root}/.eslintrc.json\``;
49
+ eslintConfigPathForError =
50
+ resolveESLintConfigPath(root) ?? '';
54
51
  }
55
52
  console.error(`
56
53
  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}
@@ -110,7 +107,6 @@ For full guidance on how to resolve this issue, please see https://github.com/an
110
107
  * log (even when no results) because different formatters handled the
111
108
  * "no results" case differently.
112
109
  */
113
- // @ts-expect-error - TODO: investigate this new rules meta argument to this function in ESLint v9
114
110
  const formattedResults = await formatter.format(finalLintResults);
115
111
  if (options.outputFile) {
116
112
  const pathToOutputFile = (0, path_1.join)(systemRoot, options.outputFile);
@@ -139,3 +135,22 @@ For full guidance on how to resolve this issue, please see https://github.com/an
139
135
  success: options.force || (totalErrors === 0 && !tooManyWarnings),
140
136
  };
141
137
  });
138
+ function resolveESLintConfigPath(projectRoot) {
139
+ const rcPath = (0, path_1.join)(projectRoot, '.eslintrc.json');
140
+ if ((0, fs_1.existsSync)(rcPath)) {
141
+ return rcPath;
142
+ }
143
+ const jsPath = (0, path_1.join)(projectRoot, 'eslint.config.js');
144
+ if ((0, fs_1.existsSync)(jsPath)) {
145
+ return jsPath;
146
+ }
147
+ const mjsPath = (0, path_1.join)(projectRoot, 'eslint.config.mjs');
148
+ if ((0, fs_1.existsSync)(mjsPath)) {
149
+ return mjsPath;
150
+ }
151
+ const cjsPath = (0, path_1.join)(projectRoot, 'eslint.config.cjs');
152
+ if ((0, fs_1.existsSync)(cjsPath)) {
153
+ return cjsPath;
154
+ }
155
+ return null;
156
+ }
package/dist/schema.json CHANGED
@@ -91,7 +91,12 @@
91
91
  },
92
92
  "noEslintrc": {
93
93
  "type": "boolean",
94
- "description": "The equivalent of the `--no-eslintrc` flag on the ESLint CLI, it is false by default",
94
+ "description": "NOTE: eslintrc config only. The equivalent of the `--no-eslintrc` flag on the ESLint CLI, it is false by default",
95
+ "default": false
96
+ },
97
+ "noConfigLookup": {
98
+ "type": "boolean",
99
+ "description": "NOTE: flat config only. The equivalent of the `--no-config-lookup` flag on the ESLint CLI, it is false by default",
95
100
  "default": false
96
101
  },
97
102
  "rulesdir": {
@@ -1,5 +1,6 @@
1
1
  import type { ESLint } from 'eslint';
2
2
  import type { Schema } from '../schema';
3
+ export declare const supportedFlatConfigNames: string[];
3
4
  export declare function resolveAndInstantiateESLint(eslintConfigPath: string | undefined, options: Schema, useFlatConfig?: boolean): Promise<{
4
5
  ESLint: typeof import("eslint").ESLint;
5
6
  eslint: ESLint;
@@ -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;AAuBxC,wBAAsB,2BAA2B,CAC/C,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,MAAM,EACf,aAAa,UAAQ;;;GA0EtB"}
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;;;GAyFtB"}
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.supportedFlatConfigNames = void 0;
3
4
  exports.resolveAndInstantiateESLint = resolveAndInstantiateESLint;
5
+ exports.supportedFlatConfigNames = [
6
+ 'eslint.config.js',
7
+ 'eslint.config.mjs',
8
+ 'eslint.config.cjs',
9
+ ];
4
10
  async function resolveESLintClass(useFlatConfig = false) {
5
11
  try {
6
12
  // In eslint 8.57.0 (the final v8 version), a dedicated API was added for resolving the correct ESLint class.
@@ -23,12 +29,11 @@ async function resolveESLintClass(useFlatConfig = false) {
23
29
  async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatConfig = false) {
24
30
  if (useFlatConfig &&
25
31
  eslintConfigPath &&
26
- !eslintConfigPath?.endsWith('eslint.config.js')) {
27
- throw new Error('When using the new Flat Config with ESLint, all configs must be named eslint.config.js and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
32
+ !exports.supportedFlatConfigNames.some((name) => eslintConfigPath.endsWith(name))) {
33
+ throw new Error(`When using the new Flat Config with ESLint, all configs must be named ${exports.supportedFlatConfigNames.join(' or ')}, and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files`);
28
34
  }
29
35
  const ESLint = await resolveESLintClass(useFlatConfig);
30
36
  const eslintOptions = {
31
- overrideConfigFile: eslintConfigPath,
32
37
  fix: !!options.fix,
33
38
  cache: !!options.cache,
34
39
  cacheLocation: options.cacheLocation || undefined,
@@ -58,8 +63,23 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
58
63
  if (options.reportUnusedDisableDirectives) {
59
64
  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');
60
65
  }
66
+ /**
67
+ * Adapted from https://github.com/eslint/eslint/blob/50f03a119e6827c03b1d6c86d3aa1f4820b609e8/lib/cli.js#L144
68
+ */
69
+ if (typeof options.noConfigLookup !== 'undefined') {
70
+ const configLookup = !options.noConfigLookup;
71
+ let overrideConfigFile = typeof eslintConfigPath === 'string' ? eslintConfigPath : !configLookup;
72
+ if (overrideConfigFile === false) {
73
+ overrideConfigFile = undefined;
74
+ }
75
+ eslintOptions.overrideConfigFile = overrideConfigFile;
76
+ }
77
+ else {
78
+ eslintOptions.overrideConfigFile = eslintConfigPath;
79
+ }
61
80
  }
62
81
  else {
82
+ eslintOptions.overrideConfigFile = eslintConfigPath;
63
83
  eslintOptions.rulePaths = options.rulesdir || [];
64
84
  eslintOptions.resolvePluginsRelativeTo =
65
85
  options.resolvePluginsRelativeTo || undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/builder",
3
- "version": "18.3.2-alpha.9",
3
+ "version": "18.4.1-alpha.0",
4
4
  "description": "Angular CLI builder for ESLint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",