网页
综合
更新时间 2026-11-16 04:29:56
Recipes · @nuxt/eslint · Nuxt Modules
自动蜘蛛
nuxt.com
正文约 5025 字
ESLint v9.x support was added in the ESLint VS Code extension (vscode-eslint) v3.0.10. In versions of vscode-eslint prior to v3.0.10, the new configuration system is not enabled by default. To enable support for the new configuration files, edit your .vscode/settings.json file and add the following:
Add the below to lint commands to your package.json script section:
Run the npm run lint command to check if the code style is correct or run npm run lint:fix to automatically fix issues.
This module does not enable stylistic/formatting rules by default. You can use Prettier alongside directly.
If you prefer to use ESLint for formatting, we also directly integrate with ESLint Stylistic to make it easy. You can opt in by setting config.stylistic to true in the eslint module options.
You can also pass an object to customize the rules:
Learn more about all the available options in the ESLint Stylistic documentation.
When stylistic rules are enabled, the keys of your nuxt.config are also sorted in a recommended order by the nuxt/nuxt-config-keys-order rule. Set config.nuxt.sortConfigKeys to false to disable it, or to true to enable it without stylistic rules.
ESLint only lints JavaScript, TypeScript and Vue files. To also format CSS, HTML, GraphQL and other files with ESLint, enable config.formatters. It uses eslint-plugin-format with Prettier under the hood, which you need to install:
true formats CSS, Less, SCSS, HTML and GraphQL files, plus XML and SVG when @prettier/plugin-xml is installed. Markdown is not formatted by default, as many Nuxt projects use MDC syntax with Nuxt Content. Pass an object to pick the file types:
TypeScript support is enabled automatically when typescript is installed in your project. To enable type-aware rules, set config.typescript.tsconfigPath to your tsconfig.json:
Type-aware rules are slower, as ESLint needs to run the TypeScript compiler. The TypeScript rules use the strict preset by default; set config.typescript.strict to false to use the recommended one.
withNuxt() returns a chainable FlatConfigComposer instance from eslint-flat-config-utils which allows you to manipulate the ESLint flat config with ease.
You can learn more about the available methods with the types and JSDocs of the instance.
To find the names of all the config items, use the Config Inspector.
This module ships ESLint Config Inspector in your Nuxt DevTools. You can inspect the resolved ESLint flat config there:
By default, the inspector starts when you click Launch in its DevTools tab. Set config.devtools.enabled to true to start it with the dev server, or to false to disable the integration. You can also set the port it runs on with config.devtools.port.
Usually you don't need this setting as most IDEs are capable of running ESLint directly to inform you of issues. It's also possible to set up a pre-commit hook with lint-staged to guard your codebase before committing.
That said, if you are working on a team using a variety of IDEs you may still want to run the ESLint checker alongside the dev server (which might slow down the dev server) to ensure issues are raised no matter the environment. You can enable it by setting checker to true in the eslint module options.
You will need to install extra dependencies vite-plugin-eslint2 for Vite, or eslint-webpack-plugin if you are using the Webpack builder.
This enables a similar experience to using @nuxtjs/eslint-module.
The checker runs in flat config mode by default. If you are still on ESLint v9 with a legacy .eslintrc config, you can run it in legacy mode by setting configType to eslintrc. ESLint v10 no longer supports .eslintrc.
By default, this module installs the JS, TS and Vue plugins with their recommended rules. This might already be covered by your config presets, so in that case you can disable the default setup by setting the standalone option to false.
This ensures the module only generates Nuxt-specific rules so that you can merge it with your own config presets.
For example, with @antfu/eslint-config:
Upon server start, the module will look for an eslint.config.* file and generate an eslint.config.mjs if it doesn't exist for easier usage. You can opt out of this by setting config.autoInit to false in the eslint module options.
The module generates its flat config at .nuxt/eslint.config.mjs by default. You can change the path with config.configFile, relative to your project root. If you run ESLint from a different directory than your Nuxt project, set config.rootDir so the paths in the generated config resolve correctly.
Other Nuxt modules can add flat config items to the generated config with the eslint:config:addons hook. Each addon provides the imports it needs and the config items, as code strings:
All-in-one ESLint integration for Nuxt, generating a project-aware ESLint flat config.
Shared, unopinionated but customizable ESLint flat config for Nuxt projects.
Stay updated on new releases and features, guides, and community updates.
Copyright © 2016-2026 Nuxt - MIT License
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。