Skip to content

Commit

Permalink
feat(plugin-eslint): detect version of config format
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Nov 23, 2024
1 parent e9edf0c commit a618bf2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/plugin-eslint/src/lib/meta/versions/detect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import { ESLint } from 'eslint';
import { fileExists } from '@code-pushup/utils';
import type { ConfigFormat } from './formats';

// relevant ESLint docs:
// - https://eslint.org/docs/latest/use/configure/configuration-files
// - https://eslint.org/docs/latest/use/configure/configuration-files-deprecated
// - https://eslint.org/docs/v8.x/use/configure/configuration-files-new

export async function detectConfigVersion(): Promise<ConfigFormat> {
// TODO: detect flat config
return 'legacy';
if (process.env['ESLINT_USE_FLAT_CONFIG'] === 'true') {
return 'flat';
}
if (process.env['ESLINT_USE_FLAT_CONFIG'] === 'false') {
return 'legacy';
}
if (ESLint.version.startsWith('8.')) {
if (await fileExists('eslint.config.js')) {
return 'flat';
}
return 'legacy';
}
return 'flat';
}

0 comments on commit a618bf2

Please sign in to comment.