Skip to content

Instantly share code, notes, and snippets.

@wangyingang
Forked from w3cj/eslint.config.mjs
Last active August 14, 2025 19:01
Show Gist options
  • Select an option

  • Save wangyingang/f3bf9256abc6627ebb50d52cd6dda8c0 to your computer and use it in GitHub Desktop.

Select an option

Save wangyingang/f3bf9256abc6627ebb50d52cd6dda8c0 to your computer and use it in GitHub Desktop.

eslint-config 配置备忘

具体使用说明请仔细查看官方文档

antfu/eslint-config

Run this command to generate base config and vs code settings:

  1. pnpm dlx @antfu/eslint-config@latest

  2. 将新生成的 eslint.config.(mjs|ts|js)中的内容替换为 eslint.config.mjs 文件中的内容

VSCode Support (可选,运行命令后已生成,手动需自己添加)

  1. 添加 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"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment