iTranslated by AI
Why I Adopt @antfu/eslint-config Despite Having No Preference for Coding Styles
Introduction
To be honest: I have no preference when it comes to coding styles.
Semicolons or no semicolons? 2-space indentation or 4? Single quotes or double quotes?
...It doesn't matter to me.
But that’s exactly why I think:
"Wouldn't it be better to just adopt the rules set by a top-tier engineer?"
What is @antfu/eslint-config?
It is an ESLint configuration preset created by Anthony Fu.
Anthony Fu is a core team member of Vue and Vite, and the creator of numerous popular OSS projects such as VueUse, Slidev, and UnoCSS. His projects have garnered a total of hundreds of thousands of stars on GitHub.
In other words, you can use the exact same configuration that a world-class engineer uses in his own projects.
Why @antfu/eslint-config?
1. Configuration in just one line
import antfu from '@antfu/eslint-config'
export default antfu()
That's it. Seriously, that’s all you need.
You no longer need to fiddle with ESLint settings every time you start a new project.
2. No more Prettier
Formatting is handled entirely by ESLint.
You don't have to manage both .prettierrc and .eslintrc, reducing the number of configuration files. You also don't have to worry about conflicts with Prettier.
3. Multi-language support
- TypeScript
- Vue / React / Svelte / Astro
- JSON / YAML / TOML
- Markdown
All of these are covered by a single configuration.
4. Support for ESLint Flat Config
It supports the new configuration format (Flat Config) recommended since ESLint v9. By starting with it now, you won't need to perform any migration work in the future.
Installation
The easiest way
pnpm dlx @antfu/eslint-config@latest
Running this will complete the setup interactively.
Manual setup
pnpm add -D eslint @antfu/eslint-config
import antfu from '@antfu/eslint-config'
export default antfu()
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}
VS Code Settings
Add the following to your .vscode/settings.json:
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"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 }
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"svelte",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
This will enable automatic formatting on save.
Customization
If you find yourself thinking, "No, I want to change just this part," you can easily do so.
import antfu from '@antfu/eslint-config'
export default antfu({
// Enable TypeScript and Vue
typescript: true,
vue: true,
// Customize style
stylistic: {
indent: 2,
quotes: 'single',
semi: false,
},
// Disable features you don't need
jsonc: false,
yaml: false,
})
You can also override specific rules:
import antfu from '@antfu/eslint-config'
export default antfu({
// Existing config
}, {
// Rules overrides
rules: {
'no-console': 'off',
},
})
Having "no preference" is a strength
People like me, who "don't have a preference for coding style," often think "I should really set this up properly" but end up procrastinating.
As a result, configurations end up being slightly different for each project, or worse, Linter isn't even installed at all...
By using @antfu/eslint-config:
- No hesitation: Best practices are included from the start.
- Fast: Configuration is done in a single line.
- Consistency: The same style across all projects.
-
Maintenance-free: Just run
pnpm updateto upgrade.
Summary
If you don't have a preference for coding style, you might as well adopt the configuration from someone who does.
It's easy because you don't have to think about it.
It's reliable because it's used by a world-class engineer.
I highly recommend this for anyone who wants to launch new services quickly.
Reference links
- GitHub - antfu/eslint-config
- ESLint Config Inspector - Visualize and check your configuration settings
- ESLint One for All Made Easy - JSNation 2024 - Talk by Anthony Fu
Discussion