-
pnpm dlx @antfu/eslint-config@latest -
将新生成的
eslint.config.(mjs|ts|js)中的内容替换为eslint.config.mjs文件中的内容
- 添加
settings.json文件中的内容到你的.vscode/settings.json文件中
pnpm dlx @antfu/eslint-config@latest
将新生成的 eslint.config.(mjs|ts|js)中的内容替换为 eslint.config.mjs 文件中的内容
settings.json 文件中的内容到你的 .vscode/settings.json 文件中| import antfu from "@antfu/eslint-config"; | |
| export default antfu({ | |
| // Type of the project. 'lib' for libraries, the default is 'app' | |
| // type: 'lib', | |
| type: "app", | |
| // Enable stylistic formatting rules | |
| // stylistic: true, | |
| // Or customize the stylistic rules | |
| stylistic: { | |
| indent: 2, // 4, or 'tab' | |
| quotes: 'single', // or 'double' | |
| semi: true, // end with semi | |
| }, | |
| // TypeScript and Vue are autodetected, you can also explicitly enable them: | |
| typescript: true, | |
| // Disable jsonc and yaml support | |
| // jsonc: false, | |
| // yaml: false, | |
| // Enable React support, you need to explicitly turn it on | |
| // Running npx eslint should prompt you to install the required dependencies, | |
| // otherwise, you can install them manually: | |
| // `npm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh` | |
| react: true, | |
| // Running npx eslint should prompt you to install the required dependencies, | |
| // otherwise, you can install them manually: | |
| // `npm i -D eslint-plugin-format` | |
| formatters: { | |
| /** | |
| * Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue | |
| * By default uses Prettier | |
| */ | |
| css: true, | |
| /** | |
| * Format HTML files | |
| * By default uses Prettier | |
| */ | |
| html: true, | |
| /** | |
| * Format Markdown files | |
| * Supports Prettier and dprint | |
| * By default uses Prettier | |
| */ | |
| markdown: 'prettier' | |
| } | |
| }, { | |
| // From the second arguments they are ESLint Flat Configs | |
| // you can have multiple configs | |
| rules: { | |
| }, | |
| }); |
| { | |
| // 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" | |
| ] | |
| } |