ESLint配置预设
pnpm i -D eslint @monousoooo/eslint-configWith "type": "module" in package.json (recommended):
// eslint.config.js
import monousoooo from '@monousoooo/eslint-config'
export default monousoooo()Note that
.eslintignoreno longer works in Flat config, see customization for more details.
For example:
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}Install VS Code ESLint extension
Add the following settings to your .vscode/settings.json:
Since v1.0, we migrated to ESLint Flat config. It provides much better organization and composition.
Normally you only need to import the monousoooo preset:
// eslint.config.js
import monousoooo from '@monousoooo/eslint-config'
export default monousoooo()And that's it! Or you can configure each integration individually, for example:
// eslint.config.js
import monousoooo from '@monousoooo/eslint-config'
export default monousoooo({
// Enable stylistic formatting rules
// stylistic: true,
// Or customize the stylistic rules
stylistic: {
indent: 2, // 4, or 'tab'
quotes: 'single', // or 'double'
},
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
typescript: true,
vue: true,
// Disable jsonc and yaml support
jsonc: false,
yaml: false,
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
ignores: [
'./fixtures',
// ...globs
]
})The monousoooo factory function also accepts any number of arbitrary custom config overrides:
// eslint.config.js
import monousoooo from '@monousoooo/eslint-config'
export default monousoooo(
{
// Configures for monousoooo's config
},
// From the second arguments they are ESLint Flat Configs
// you can have multiple configs
{
files: ['**/*.ts'],
rules: {},
},
{
rules: {},
},
)Going more advanced, you can also import fine-grained configs and compose them as you wish:
// eslint.config.js
import {
comments,
ignores,
imports,
javascript,
jsdoc,
jsonc,
markdown,
node,
sortPackageJson,
sortTsconfig,
stylistic,
typescript,
unicorn,
vue,
yaml,
} from '@monousoooo/eslint-config'
export default [
...ignores(),
...javascript(),
...comments(),
...node(),
...jsdoc(),
...imports(),
...unicorn(),
...typescript(),
...stylistic(),
...vue(),
...jsonc(),
...yaml(),
...markdown(),
]Check out the configs and factory for more details.
感谢大佬 antfu/eslint-config 的配置方式
{ // Enable the ESlint flat config support "eslint.experimental.useFlatConfig": true, // Disable the default formatter, use eslint instead "prettier.enable": false, "editor.formatOnSave": false, // Auto fix "editor.codeActionsOnSave": { "source.fixAll": "explicit", "source.organizeImports": "never" }, // Silent the stylistic rules in you IDE, but still auto fix them "eslint.rules.customizations": [ { "rule": "style/*", "severity": "off" }, { "rule": "*-indent", "severity": "off" }, { "rule": "*-spacing", "severity": "off" }, { "rule": "*-spaces", "severity": "off" }, { "rule": "*-order", "severity": "off" }, { "rule": "*-dangle", "severity": "off" }, { "rule": "*-newline", "severity": "off" }, { "rule": "*quotes", "severity": "off" }, { "rule": "*semi", "severity": "off" } ], // Enable eslint for all supported languages "eslint.validate": [ "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "markdown", "json", "jsonc", "yaml" ] }