-
Notifications
You must be signed in to change notification settings - Fork 562
feat(build-tools): support ESLint 9 flat config detection and parsing #26147
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
feat(build-tools): support ESLint 9 flat config detection and parsing #26147
Conversation
The getEsLintConfigFilePath function now checks for ESLint 9 flat config files in addition to legacy .eslintrc files. This enables fluid-build to properly detect config files and generate done files for eslint tasks when packages migrate to ESLint 9. Supported flat config files (checked first): - eslint.config.mjs, eslint.config.mts - eslint.config.cjs, eslint.config.cts - eslint.config.js, eslint.config.ts Legacy files still supported for backwards compatibility: - .eslintrc.js, .eslintrc.cjs, .eslintrc.json, .eslintrc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the getEsLintConfigFilePath function to detect ESLint 9 flat config files in addition to legacy .eslintrc files. This enables fluid-build to locate config files for packages migrating to ESLint 9, preventing errors during incremental build tracking.
Key Changes
- Added detection for ESLint 9 flat config files (
.mjs,.mts,.cjs,.cts,.js,.tsvariants) - Maintained backwards compatibility with legacy eslintrc files
- Established precedence order with ESLint 9 configs checked first
Comments suppressed due to low confidence (1)
build-tools/packages/build-tools/src/fluidBuild/tasks/taskUtils.ts:41
- The function
getEsLintConfigFilePathlacks test coverage. Other utility functions in the same file (likeglobFnandglobWithGitignore) have comprehensive test coverage insrc/test/globPatterns.test.ts.
Consider adding tests to verify:
- Correct detection of ESLint 9 flat config files in the proper precedence order
- Correct detection of legacy eslintrc files
- Behavior when multiple config files exist (should return the first match based on precedence)
- Behavior when no config file exists (returns undefined)
export function getEsLintConfigFilePath(dir: string) {
// ESLint 9 flat config files (checked first as they take precedence)
// Then legacy eslintrc files for backwards compatibility
// TODO: we currently don't support .yaml and .yml, or config in package.json
const possibleConfig = [
// ESLint 9 flat config files
"eslint.config.mjs",
"eslint.config.mts",
"eslint.config.cjs",
"eslint.config.cts",
"eslint.config.js",
"eslint.config.ts",
// Legacy eslintrc files
".eslintrc.js",
".eslintrc.cjs",
".eslintrc.json",
".eslintrc",
];
for (const configFile of possibleConfig) {
const configFileFullPath = path.join(dir, configFile);
if (existsSync(configFileFullPath)) {
return configFileFullPath;
}
}
return undefined;
}
…encies
Replace manual config file parsing with ESLint's calculateConfigForFile API.
This properly supports:
- ESLint 9 flat config files (eslint.config.{js,mjs,cjs,ts,mts,cts})
- Legacy eslintrc files (.eslintrc.{js,cjs,json})
- TypeScript config files that require transpilation
- ESM config files
The ESLint API resolves extends/overrides and returns the effective
parserOptions.project value, which is used to determine tsc task dependencies.
Adds @types/eslint as a dev dependency for type safety.
Remove fallback for pre-8.57.0 ESLint versions since loadESLint API is required for proper flat config detection. Adds a clear error message if older ESLint is detected.
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Show resolved
Hide resolved
- Add proper types for ESLint computed config (ParserOptions, ComputedESLintConfig) instead of using 'any' casts - Add comment explaining why the dynamic import cast is safe - Remove 'null' from type annotations per codebase conventions
Rename ESLint flat config files from JavaScript (.mjs) to TypeScript (.mts) for consistency with PR microsoft#26070. Add jiti dependency to enable runtime transpilation of TypeScript config files. Also includes the ESLint 9 flat config detection fix from PR microsoft#26147.
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Outdated
Show resolved
Hide resolved
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Outdated
Show resolved
Hide resolved
…idBuildTasks.ts Co-authored-by: Joshua Smithrud <[email protected]>
build-tools/packages/build-cli/src/library/repoPolicyCheck/fluidBuildTasks.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Joshua Smithrud <[email protected]>
…idBuildTasks.ts Co-authored-by: Joshua Smithrud <[email protected]>
Description
Enables fluid-build to properly support ESLint 9 flat config files for incremental build tracking.
Changes
Config File Detection (
taskUtils.ts)Expands
getEsLintConfigFilePathto detect ESLint 9 flat config files:eslint.config.{mjs,mts,cjs,cts,js,ts}(checked first).eslintrc.{js,cjs,json}files (backwards compatibility)Config File Parsing (
fluidBuildTasks.ts)Replaces manual config file parsing with ESLint's
calculateConfigForFile()API to extractparserOptions.projectfor build task dependencies. This properly supports:languageOptions.parserOptions.project)parserOptions.project).mts,.cts,.ts).mjs)The previous manual parsing with
require()andJSON5.parse()couldn't handle ESLint 9's different config structure or TypeScript/ESM configs.Motivation
Without these changes, packages using ESLint 9 flat configs cannot have proper incremental build tracking - fluid-build couldn't detect the config files or parse them to determine tsc task dependencies.
Related: #26017