Replies: 5 comments 16 replies
-
Hi @yf-yang, before using the flat config, the common structure developers followed in monorepos was having a root With flat config you would need just one File structure:
You can use glob patterns in the // eslint.config.js
export default [
{
files: ["api/**/*.js"],
rules: {
"semi": "error",
"no-unused-vars": "error"
}
},
{
files: ["frontend/**/*.js"],
rules: {
"no-undef": "error",
"semi": "warn"
}
}
]; In this way ESLint will use the second config for linting any You can also have a config that would be used for every // eslint.config.js
export default [
{
files: ["**/*.js"],
rules: {
"no-unused-vars": "warn"
}
},
{
files: ["api/**/*.js"],
rules: {
"semi": "error",
"no-unused-vars": "error"
}
},
{
files: ["frontend/**/*.js"],
rules: {
"no-undef": "error",
"semi": "warn"
}
}
]; Note: Here ESLint will merge configs from top to bottom, so Note: ESLint uses minimatch based glob patterns to match files defined in the > const minimatch = require("minimatch")
> minimatch('api/index.js', 'api/**/*.js')
true
> minimatch('api/resolvers/index.js', 'api/**/*.js')
true
> minimatch('api/index.js', '**/*.js')
true
> minimatch('frontend/components/index.js', 'api/**/*.js')
false You can track the complete implementation of the flat config at #13481 The ESLint team is excited to see users using the new flat config system. Thanks for using ESLint. |
Beta Was this translation helpful? Give feedback.
-
In the following monorepo eslint-flat-vscode-playground, ESLint cannot properly find the ~/d/t/eslint-flat-vscode-playground main ❯ pnpm eslint . Oops! Something went wrong! :(
ESLint: 8.36.0
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
npm init @eslint/config
ESLint looked for configuration files in /Users/eliasaboukhalillanvin/dev/test/eslint-flat-vscode-playground/dist and its ancestors. If it found none, it then looked in your home directory.
If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat |
Beta Was this translation helpful? Give feedback.
-
@Rec0iL99 |
Beta Was this translation helpful? Give feedback.
-
I've encountered a scenario involving a sharable flat config in a monorepo, and if I understand correctly, this solution wouldn't work 100% (#16960 (comment)). With the new flat config, we can have many configuration objects cascading inside the array, and this is usually the case in a sharable config. For example: export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
rules: {
'some-rule': 'off',
},
},
eslintPluginPrettierRecommended,
]; In this specific scenario, I have 2 sharable configs ( This is the solution I'm using: import sharableConfig from 'custom-eslint-config';
const nodeConfig = sharableConfig.configs.node.map(configObject => ({ files: ['packages/package-a/**/*'], ...configObject }));
const reactConfig = sharableConfig.configs.react.map(configObject => ({ files: ['packages/package-b/**/*'], ...configObject }));
export default [...nodeConfig, ...reactConfig]; Does this make sense? I think this is not the best approach, and I would appreciate any suggestions for a better way to do this. I feel like I may be missing something. |
Beta Was this translation helpful? Give feedback.
-
Since flatconfigs are just plain JavaScript values exported from modules, does the following setup make sense for monorepo environments? We have export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
// project-wide configuration goes here
] Now, each package that needs eslint has import baseConfig from "our-eslint-config";
export default [
...baseConfig,
// package - specific configuration goes here
] Actual lint runs can be triggered from each package as local |
Beta Was this translation helpful? Give feedback.
-
I'm using eslint in a monorepo, where a full eslintrc is placed at the root directory and different packages contain their own eslintrc that extends the root and modify rules if they need to. In this way, whenever I want to change a rule setting, I can first consider if this rule should be generally applied, then navigate to the root config or package config and modify it.
However, when I'm switching to the new flat config system, I notice the blog post states:
Does it mean the recommended way is to move all the package-wise eslint config to the root? What is the recommended way in a monorepo scenario and why?
Beta Was this translation helpful? Give feedback.
All reactions