Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting the eslint flat config option #751

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions change/change-c213f895-ed17-4762-91fe-fc1225be29d6.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"dependentChangeType": "patch"
}
]
}
1 change: 1 addition & 0 deletions packages/just-scripts/etc/just-scripts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export interface EsLintTaskOptions {
// (undocumented)
resolvePluginsPath?: string;
timing?: boolean;
useFlatConfig?: boolean;
}

// @public (undocumented)
Expand Down
15 changes: 14 additions & 1 deletion packages/just-scripts/src/tasks/eslintTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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) */
christiango marked this conversation as resolved.
Show resolved Hide resolved
useFlatConfig?: boolean;
}

export function eslintTask(options: EsLintTaskOptions = {}): TaskFunction {
Expand All @@ -47,6 +49,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
Expand Down Expand Up @@ -74,8 +77,18 @@ export function eslintTask(options: EsLintTaskOptions = {}): TaskFunction {
'--color',
];

const env: Record<string, string> = {};

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();
}
Expand Down
Loading