### Install @antfu/eslint-config via pnpm dlx Source: https://github.com/antfu/eslint-config/blob/main/README.md Use this command to automatically set up your project or migrate from a legacy config. It's the recommended way to get started. ```bash pnpm dlx @antfu/eslint-config@latest ``` -------------------------------- ### ESLint formatting example Source: https://github.com/antfu/eslint-config/blob/main/fixtures/output/no-markdown-with-formatters/markdown.md Example of code that should be handled by ESLint. ```js // This should be handled by ESLint instead of Prettier function identity(x) { if (foo) { console.log('bar'); } } ``` -------------------------------- ### Basic ESLint Configuration with antfu/eslint-config Source: https://github.com/antfu/eslint-config/blob/main/README.md Import and use the default antfu ESLint preset for a project. This is the simplest way to get started with the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu() ``` -------------------------------- ### Install React Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugins for React if prompted or manually. ```bash npm i -D @eslint-react/eslint-plugin eslint-plugin-react-refresh ``` -------------------------------- ### Install Solid Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugin for Solid if prompted or manually. ```bash npm i -D eslint-plugin-solid ``` -------------------------------- ### Manual Installation of ESLint and Config Source: https://github.com/antfu/eslint-config/blob/main/README.md Install ESLint and the @antfu/eslint-config package manually. This is an alternative to the CLI wizard. ```bash pnpm i -D eslint @antfu/eslint-config ``` -------------------------------- ### ESLint formatting example Source: https://github.com/antfu/eslint-config/blob/main/fixtures/output/tab-double-quotes/markdown.md Example of code that should be managed by ESLint rather than Prettier. ```js // This should be handled by ESLint instead of Prettier function identity(x) { if (foo) { console.log("bar") } } ``` -------------------------------- ### Install Next.js Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugin for Next.js if prompted or manually. ```bash npm i -D @next/eslint-plugin-next ``` -------------------------------- ### Basic ESLint Flat Config Setup Source: https://github.com/antfu/eslint-config/blob/main/README.md Create an 'eslint.config.mjs' file in your project root and import the @antfu/eslint-config. This is the minimal setup for using the config. ```javascript import antfu from '@antfu/eslint-config' export default antfu() ``` -------------------------------- ### Install Angular Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugins for Angular if prompted or manually. ```bash npm i -D @angular-eslint/eslint-plugin @angular-eslint/eslint-plugin-template @angular-eslint/template-parser ``` -------------------------------- ### Install Astro Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugin for Astro if prompted or manually. ```bash npm i -D eslint-plugin-astro ``` -------------------------------- ### Install and Activate Lint Staged Hooks Source: https://github.com/antfu/eslint-config/blob/main/README.md Install `lint-staged` and `simple-git-hooks` as development dependencies and activate the Git hooks. ```bash npm i -D lint-staged simple-git-hooks // to active the hooks npx simple-git-hooks ``` -------------------------------- ### Install Svelte Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugin for Svelte if prompted or manually. ```bash npm i -D eslint-plugin-svelte ``` -------------------------------- ### Install UnoCSS Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Install the necessary ESLint plugin for UnoCSS if prompted or manually. ```bash npm i -D @unocss/eslint-plugin ``` -------------------------------- ### Install Formatter Dependencies Source: https://github.com/antfu/eslint-config/blob/main/README.md Manually install the required dependency for external formatters if prompted by ESLint. ```bash npm i -D eslint-plugin-format ``` -------------------------------- ### Neovim Configuration for ESLint Source: https://github.com/antfu/eslint-config/blob/main/README.md Configure Neovim's lspconfig to integrate ESLint, enabling auto-fixing on save and supporting a wide array of file types. This setup silences stylistic rules in the IDE while ensuring they are automatically fixed. ```lua local 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 }, } local lspconfig = require('lspconfig') -- Enable eslint for all supported languages lspconfig.eslint.setup( { filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx", "vue", "html", "markdown", "json", "jsonc", "yaml", "toml", "xml", "gql", "graphql", "astro", "svelte", "css", "less", "scss", "pcss", "postcss" }, settings = { -- Silent the stylistic rules in your IDE, but still auto fix them rulesCustomizations = customizations, }, } ) ``` -------------------------------- ### Install Vue Accessibility Dependency Source: https://github.com/antfu/eslint-config/blob/main/README.md Manually install the required dependency for Vue accessibility support if prompted by ESLint. ```bash npm i -D eslint-plugin-vuejs-accessibility ``` -------------------------------- ### Customized ESLint Configuration with antfu/eslint-config Source: https://github.com/antfu/eslint-config/blob/main/README.md Configure specific aspects of the antfu ESLint preset, such as project type, ignores, and stylistic rules. This example shows how to set indentation, quotes, and brace style. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ // Type of the project. 'lib' for libraries, the default is 'app' type: 'lib', // `.eslintignore` is no longer supported in Flat config, use `ignores` instead // The `ignores` option in the option (first argument) is specifically treated to always be global ignores // And will **extend** the config's default ignores, not override them // You can also pass a function to modify the default ignores ignores: [ '**/fixtures', // ...globs ], // Parse the `.gitignore` file to get the ignores, on by default gitignore: true, // Enable stylistic formatting rules // stylistic: true, // Or customize the stylistic rules stylistic: { indent: 2, // 4, or 'tab' quotes: 'single', // or 'double' braceStyle: 'stroustrup', // '1tbs', or 'allman' }, // TypeScript and Vue are autodetected, you can also explicitly enable them: typescript: true, vue: true, // Disable jsonc and yaml support jsonc: false, yaml: false, }) ``` -------------------------------- ### Define CSS class style Source: https://github.com/antfu/eslint-config/blob/main/fixtures/output/with-formatters/markdown.md Example of a CSS rule intended for Prettier formatting. ```css /* This should be handled by Prettier */ .foo { color: red; } ``` -------------------------------- ### Enable Vue Accessibility Support in ESLint Source: https://github.com/antfu/eslint-config/blob/main/README.md Turn on Vue accessibility support by setting `a11y` to `true` within the `vue` options. Ensure `eslint-plugin-vuejs-accessibility` is installed. ```js // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ vue: { a11y: true }, }) ``` -------------------------------- ### VS Code Settings for ESLint Auto Fix Source: https://github.com/antfu/eslint-config/blob/main/README.md Configure VS Code's settings.json to disable default formatters, enable auto-fix on save for ESLint, and silence stylistic rules while still allowing them to be fixed. This setup ensures ESLint handles code formatting and fixes automatically. ```jsonc { // 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 your 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" ] } ``` -------------------------------- ### Enable Solid Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable Solid support, import Antfu and pass `{ solid: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ solid: true, }) ``` -------------------------------- ### Enable React Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable React support, import Antfu and pass `{ react: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ react: true, }) ``` -------------------------------- ### Enable Astro Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable Astro support, import Antfu and pass `{ astro: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ astro: true, }) ``` -------------------------------- ### Enable Angular Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable Angular support, import Antfu and pass `{ angular: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ angular: true, }) ``` -------------------------------- ### Enable Next.js Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable Next.js support, import Antfu and pass `{ nextjs: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ nextjs: true, }) ``` -------------------------------- ### Initialize Google Analytics Source: https://github.com/antfu/eslint-config/blob/main/fixtures/input/html.html Standard tracking snippet for Google Analytics. Ensure this is placed before the closing body tag. ```javascript window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date; ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview') ``` -------------------------------- ### Enable Svelte Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable Svelte support, import Antfu and pass `{ svelte: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ svelte: true, }) ``` -------------------------------- ### Combine @antfu/eslint-config with Legacy ESLint Configs Source: https://github.com/antfu/eslint-config/blob/main/README.md Integrate the new flat config with existing legacy ESLint configurations using '@eslint/eslintrc'. This allows for a gradual migration. ```javascript import antfu from '@antfu/eslint-config' import { FlatCompat } from '@eslint/eslintrc' const compat = new FlatCompat() export default antfu( { ignores: [], }, // Legacy config ...compat.config({ extends: [ 'eslint:recommended', // Other extends... ], }) // Other flat configs... ) ``` -------------------------------- ### Enable UnoCSS Support Source: https://github.com/antfu/eslint-config/blob/main/README.md To enable UnoCSS support, import Antfu and pass `{ unocss: true }` to the configuration. ```javascript // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ unocss: true, }) ``` -------------------------------- ### Enable CSS, HTML, and Markdown Formatting Source: https://github.com/antfu/eslint-config/blob/main/README.md Configure external formatters for CSS, HTML, and Markdown files. By default, Prettier is used for all. Markdown can also be formatted with dprint. ```js // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ formatters: { /** * Format CSS, LESS, SCSS files, also the `