diff --git a/change/change-c213f895-ed17-4762-91fe-fc1225be29d6.json b/change/change-c213f895-ed17-4762-91fe-fc1225be29d6.json new file mode 100644 index 00000000..3c36acd3 --- /dev/null +++ b/change/change-c213f895-ed17-4762-91fe-fc1225be29d6.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "type": "patch", + "comment": "Add support for setting ESLINT_USE_FLAT_CONFIG to assist with upgrades to eslint v9", + "packageName": "just-scripts", + "email": "1581488+christiango@users.noreply.github.com", + "dependentChangeType": "patch" + } + ] +} diff --git a/packages/just-scripts/etc/just-scripts.api.md b/packages/just-scripts/etc/just-scripts.api.md index 01f0d4c0..a4a219a8 100644 --- a/packages/just-scripts/etc/just-scripts.api.md +++ b/packages/just-scripts/etc/just-scripts.api.md @@ -213,6 +213,7 @@ export interface EsLintTaskOptions { // (undocumented) resolvePluginsPath?: string; timing?: boolean; + useFlatConfig?: boolean; } // @public (undocumented) diff --git a/packages/just-scripts/src/tasks/eslintTask.ts b/packages/just-scripts/src/tasks/eslintTask.ts index d79056ec..93b79c93 100644 --- a/packages/just-scripts/src/tasks/eslintTask.ts +++ b/packages/just-scripts/src/tasks/eslintTask.ts @@ -28,6 +28,11 @@ export interface EsLintTaskOptions { format?: string; /** Prevents the logging & auto-fixing of warnings */ quiet?: boolean; + /** + * Can be set to force the flat config on or off, which can be helpful when migrating to ESLint v9. + * This will be passed as an environment variable to eslint with the value ESLINT_USE_FLAT_CONFIG (https://eslint.org/blog/2024/04/eslint-v9.0.0-released/#flat-config-is-now-the-default-and-has-some-changes). + */ + useFlatConfig?: boolean; } export function eslintTask(options: EsLintTaskOptions = {}): TaskFunction { @@ -47,6 +52,7 @@ export function eslintTask(options: EsLintTaskOptions = {}): TaskFunction { outputFile, format, quiet, + useFlatConfig, } = options; const eslintCmd = resolve('eslint/bin/eslint.js'); // Try all possible extensions in the order listed here: https://eslint.org/docs/user-guide/configuring#configuration-file-formats @@ -74,8 +80,18 @@ export function eslintTask(options: EsLintTaskOptions = {}): TaskFunction { '--color', ]; + const env: Record = {}; + + if (timing) { + env.TIMING = '1'; + } + + if (useFlatConfig !== undefined) { + env.ESLINT_USE_FLAT_CONFIG = JSON.stringify(useFlatConfig); + } + logger.info(encodeArgs(eslintArgs).join(' ')); - return spawn(process.execPath, eslintArgs, { stdio: 'inherit', ...(timing && { env: { TIMING: '1' } }) }); + return spawn(process.execPath, eslintArgs, { stdio: 'inherit', env }); } else { return Promise.resolve(); }