@code-pushup/eslint-plugin 0.55.0 → 0.56.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.
package/index.js CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  // packages/plugin-eslint/package.json
6
6
  var name = "@code-pushup/eslint-plugin";
7
- var version = "0.55.0";
7
+ var version = "0.56.0";
8
8
 
9
9
  // packages/plugin-eslint/src/lib/config.ts
10
10
  import { z as z17 } from "zod";
@@ -1263,24 +1263,73 @@ function filterProjectGraph(projectGraph, exclude = []) {
1263
1263
 
1264
1264
  // packages/plugin-eslint/src/lib/nx/utils.ts
1265
1265
  import { join as join5 } from "node:path";
1266
- async function findCodePushupEslintrc(project) {
1267
- const name2 = "code-pushup.eslintrc";
1268
- const extensions = ["json", "js", "cjs", "yml", "yaml"];
1269
- for (const ext of extensions) {
1270
- const filename = `./${project.root}/${name2}.${ext}`;
1271
- if (await fileExists(join5(process.cwd(), filename))) {
1272
- return filename;
1273
- }
1274
- }
1275
- return null;
1266
+ var ESLINT_CONFIG_EXTENSIONS = {
1267
+ // https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-formats
1268
+ flat: ["js", "mjs", "cjs"],
1269
+ // https://eslint.org/docs/latest/use/configure/configuration-files-deprecated
1270
+ legacy: ["json", "js", "cjs", "yml", "yaml"]
1271
+ };
1272
+ var ESLINT_CONFIG_NAMES = {
1273
+ // https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-formats
1274
+ flat: ["eslint.config"],
1275
+ // https://eslint.org/docs/latest/use/configure/configuration-files-deprecated
1276
+ legacy: [".eslintrc"]
1277
+ };
1278
+ var CP_ESLINT_CONFIG_NAMES = {
1279
+ flat: [
1280
+ "code-pushup.eslint.config",
1281
+ "eslint.code-pushup.config",
1282
+ "eslint.config.code-pushup",
1283
+ "eslint.strict.config",
1284
+ "eslint.config.strict"
1285
+ ],
1286
+ legacy: ["code-pushup.eslintrc", ".eslintrc.code-pushup", ".eslintrc.strict"]
1287
+ };
1288
+ async function findCodePushupEslintConfig(project, format) {
1289
+ return findProjectFile(project, {
1290
+ names: CP_ESLINT_CONFIG_NAMES[format],
1291
+ extensions: ESLINT_CONFIG_EXTENSIONS[format]
1292
+ });
1276
1293
  }
1277
- function getLintFilePatterns(project) {
1294
+ async function findEslintConfig(project, format) {
1278
1295
  const options = project.targets?.["lint"]?.options;
1279
- return options?.lintFilePatterns == null ? [`${project.root}/**/*`] : toArray(options.lintFilePatterns);
1296
+ return options?.eslintConfig ?? await findProjectFile(project, {
1297
+ names: ESLINT_CONFIG_NAMES[format],
1298
+ extensions: ESLINT_CONFIG_EXTENSIONS[format]
1299
+ });
1280
1300
  }
1281
- function getEslintConfig(project) {
1301
+ function getLintFilePatterns(project, format) {
1282
1302
  const options = project.targets?.["lint"]?.options;
1283
- return options?.eslintConfig ?? `./${project.root}/.eslintrc.json`;
1303
+ const defaultPatterns = format === "legacy" ? `${project.root}/**/*` : project.root;
1304
+ const patterns = options?.lintFilePatterns == null ? [defaultPatterns] : toArray(options.lintFilePatterns);
1305
+ if (format === "legacy") {
1306
+ return [
1307
+ ...patterns,
1308
+ // HACK: ESLint.calculateConfigForFile won't find rules included only for subsets of *.ts when globs used
1309
+ // so we explicitly provide additional patterns used by @code-pushup/eslint-config to ensure those rules are included
1310
+ // this workaround is only necessary for legacy configs (rules are detected more reliably in flat configs)
1311
+ `${project.root}/*.spec.ts`,
1312
+ // jest/* and vitest/* rules
1313
+ `${project.root}/*.cy.ts`,
1314
+ // cypress/* rules
1315
+ `${project.root}/*.stories.ts`,
1316
+ // storybook/* rules
1317
+ `${project.root}/.storybook/main.ts`
1318
+ // storybook/no-uninstalled-addons rule
1319
+ ];
1320
+ }
1321
+ return patterns;
1322
+ }
1323
+ async function findProjectFile(project, file) {
1324
+ for (const name2 of file.names) {
1325
+ for (const ext of file.extensions) {
1326
+ const filename = `./${project.root}/${name2}.${ext}`;
1327
+ if (await fileExists(join5(process.cwd(), filename))) {
1328
+ return filename;
1329
+ }
1330
+ }
1331
+ }
1332
+ return void 0;
1284
1333
  }
1285
1334
 
1286
1335
  // packages/plugin-eslint/src/lib/nx/projects-to-config.ts
@@ -1288,24 +1337,12 @@ async function nxProjectsToConfig(projectGraph, predicate = () => true) {
1288
1337
  const { readProjectsConfigurationFromProjectGraph } = await import("@nx/devkit");
1289
1338
  const projectsConfiguration = readProjectsConfigurationFromProjectGraph(projectGraph);
1290
1339
  const projects = Object.values(projectsConfiguration.projects).filter((project) => "lint" in (project.targets ?? {})).filter(predicate).sort((a, b) => a.root.localeCompare(b.root));
1340
+ const format = await detectConfigVersion();
1291
1341
  return Promise.all(
1292
1342
  projects.map(
1293
1343
  async (project) => ({
1294
- eslintrc: await findCodePushupEslintrc(project) ?? getEslintConfig(project),
1295
- patterns: [
1296
- ...getLintFilePatterns(project),
1297
- // HACK: ESLint.calculateConfigForFile won't find rules included only for subsets of *.ts when globs used
1298
- // so we explicitly provide additional patterns used by @code-pushup/eslint-config to ensure those rules are included
1299
- // this workaround won't be necessary once flat configs are stable (much easier to find all rules)
1300
- `${project.sourceRoot}/*.spec.ts`,
1301
- // jest/* and vitest/* rules
1302
- `${project.sourceRoot}/*.cy.ts`,
1303
- // cypress/* rules
1304
- `${project.sourceRoot}/*.stories.ts`,
1305
- // storybook/* rules
1306
- `${project.sourceRoot}/.storybook/main.ts`
1307
- // storybook/no-uninstalled-addons rule
1308
- ]
1344
+ eslintrc: await findCodePushupEslintConfig(project, format) ?? await findEslintConfig(project, format),
1345
+ patterns: getLintFilePatterns(project, format)
1309
1346
  })
1310
1347
  )
1311
1348
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/eslint-plugin",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "license": "MIT",
5
5
  "description": "Code PushUp plugin for detecting problems in source code using ESLint.📋",
6
6
  "homepage": "https://github.com/code-pushup/cli/tree/main/packages/plugin-eslint#readme",
@@ -40,8 +40,8 @@
40
40
  "main": "./index.js",
41
41
  "types": "./src/index.d.ts",
42
42
  "dependencies": {
43
- "@code-pushup/utils": "0.55.0",
44
- "@code-pushup/models": "0.55.0",
43
+ "@code-pushup/utils": "0.56.0",
44
+ "@code-pushup/models": "0.56.0",
45
45
  "zod": "^3.22.4"
46
46
  },
47
47
  "peerDependencies": {
@@ -1,5 +1,6 @@
1
1
  import type { Audit, Group } from '@code-pushup/models';
2
2
  import type { ESLintTarget } from '../config';
3
+ export { detectConfigVersion, type ConfigFormat } from './versions';
3
4
  export declare function listAuditsAndGroups(targets: ESLintTarget[]): Promise<{
4
5
  audits: Audit[];
5
6
  groups: Group[];
@@ -1,4 +1,5 @@
1
1
  import type { ProjectConfiguration } from '@nx/devkit';
2
- export declare function findCodePushupEslintrc(project: ProjectConfiguration): Promise<string | null>;
3
- export declare function getLintFilePatterns(project: ProjectConfiguration): string[];
4
- export declare function getEslintConfig(project: ProjectConfiguration): string | undefined;
2
+ import type { ConfigFormat } from '../meta';
3
+ export declare function findCodePushupEslintConfig(project: ProjectConfiguration, format: ConfigFormat): Promise<string | undefined>;
4
+ export declare function findEslintConfig(project: ProjectConfiguration, format: ConfigFormat): Promise<string | undefined>;
5
+ export declare function getLintFilePatterns(project: ProjectConfiguration, format: ConfigFormat): string[];