We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
pnpm dlx @whoj/eslint-config@latest
If you prefer to set up manually:
pnpm i -D eslint @whoj/eslint-config
And create eslint.config.mjs
in your project root:
// eslint.config.mjs
import whoj from '@whoj/eslint-config';
export default whoj();
Combined with legacy config:
If you still use some configs from the legacy eslintrc format, you can use the @eslint/eslintrc
package to convert them to the flat config.
// eslint.config.mjs
import whoj from '@whoj/eslint-config';
import { FlatCompat } from '@eslint/eslintrc';
const compat = new FlatCompat();
export default whoj(
{
ignores: [],
},
// Legacy config
...compat.config({
extends: [
'eslint:recommended',
// Other extends...
],
}),
// Other flat configs...
);
Note that
.eslintignore
no longer works in Flat config, see customization for more details.
For example:
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}
🟦 VS Code support
Install VS Code ESLint extension
Add the following settings to your .vscode/settings.json
:
{
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,
// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],
// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"svelte",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
You can configure each integration individually, for example:
// eslint.config.js
import whoj from '@whoj/eslint-config';
export default whoj({
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
ignores: [
'**/fixtures',
// ...globs
],
// Enable stylistic formatting rules
// stylistic: true,
// Disable jsonc and yaml support
jsonc: false,
// Or customize the stylistic rules
stylistic: {
indent: 2, // 4, or 'tab'
quotes: 'single', // or 'double'
},
// Type of the project. 'lib' for libraries, the default is 'app'
type: 'lib',
// TypeScript and Vue are autodetected, you can also explicitly enable them:
typescript: true,
vue: true,
yaml: false,
});
The whoj
factory function also accepts any number of arbitrary custom config overrides:
// eslint.config.js
import whoj from '@whoj/eslint-config';
export default whoj(
{
// Configures for whoj's config
},
// From the second arguments they are ESLint Flat Configs
// you can have multiple configs
{
files: ['**/*.ts'],
rules: {},
},
{
rules: {},
},
);
Going more advanced, Check out configs