Skip to content

Commit

Permalink
feat(module): set checker configType to flat by default
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 10, 2024
1 parent 077271b commit d84af6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
20 changes: 18 additions & 2 deletions docs/content/1.packages/0.module.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ title: ESLint Module
All-in-one ESLint integration for Nuxt. It generates a project-aware [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new) and provides the ability to optionally run ESLint check along side the dev server.

:::callout{icon="i-ph-lightbulb-duotone"}
This module is designed for the [new ESLint flat config format](https://eslint.org/docs/latest/use/configure/configuration-files-new), which will be the [default in ESLint v9](https://eslint.org/blog/2023/11/whats-coming-in-eslint-9.0.0/).
The legacy `.eslintrc` config is **not supported** by this module. We highly recommand you to migrate over the flat config to be future-proof. If you still want to use the legacy format, you might need to manually config with [`@nuxt/eslint-config`](/packages/config), which will also lose some features like project-aware settings.
This module is designed for the [new ESLint flat config format](https://eslint.org/docs/latest/use/configure/configuration-files-new) with is the [default format since ESLint v9](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/). Flat config is supported since ESLint v8.45.0 so you can use any version of ESLint later than that. We recommend you to use the latest version of ESLint to get the best experience.

The legacy `.eslintrc` config is **not supported** by this module. We highly recommand you to migrate over the flat config to be future-proof. If you still want to use the legacy format, you might need to manually config with [`@nuxt/eslint-config`](/packages/config), which will missing some features like project-aware settings tho.
:::

::read-more
Expand Down Expand Up @@ -185,6 +186,21 @@ npm i -D eslint-webpack-plugin

This enables a similar experience to using [`@nuxtjs/eslint-module`](https://github.com/nuxt-modules/eslint).

The checker runs in flat config mode by default. If you want to run it in legacy mode, you will need to set `configType` to `eslintrc`

```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: [
'@nuxt/eslint'
],
eslint: {
checker: {
configType: 'eslintrc' // <--- (consider migrating to flat config if possible)
}
}
})
```

### Custom Config Presets

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`.
Expand Down
5 changes: 2 additions & 3 deletions packages/module/src/modules/checker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { existsSync } from 'node:fs'
import { addVitePlugin, addWebpackPlugin, useLogger } from '@nuxt/kit'
import { relative, resolve } from 'pathe'
import { relative } from 'pathe'
import { watch } from 'chokidar'
import type { Nuxt } from '@nuxt/schema'
import type { ESLintPluginOptions as ViteCheckerOptions } from 'vite-plugin-eslint2'
Expand Down Expand Up @@ -28,7 +27,7 @@ export async function setupESLintChecker(moduleOptions: ModuleOptions, nuxt: Nux
}

// When not specified, we try to detect the configType
options.configType ||= (process.env.ESLINT_USE_FLAT_CONFIG || flatConfigFiles.some(file => existsSync(resolve(nuxt.options.rootDir, file))))
options.configType ||= process.env.ESLINT_USE_FLAT_CONFIG !== 'false'
? 'flat'
: 'eslintrc'

Expand Down
4 changes: 4 additions & 0 deletions packages/module/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface CheckerOptions {

/**
* ESLint config type
*
* Default to `flat` unless env `ESLINT_USE_FLAT_CONFIG` is set to `false`
*
* @default 'flat'
*/
configType?: 'flat' | 'eslintrc'

Expand Down

0 comments on commit d84af6f

Please sign in to comment.