Skip to content

Commit c3de9d2

Browse files
committedMar 8, 2023
fix: options
1 parent 2a84a08 commit c3de9d2

File tree

2 files changed

+41
-53
lines changed

2 files changed

+41
-53
lines changed
 

‎README.md

+30-37
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ npm install -D eslint
3939
With `pnpm`
4040

4141
```bash
42-
pnpm add @nuxtjs/eslint-module
42+
pnpm add -D @nuxtjs/eslint-module
4343
```
4444

4545
Or, with `yarn`
4646

4747
```bash
48-
yarn add @nuxtjs/eslint-module
48+
yarn add -D @nuxtjs/eslint-module
4949
```
5050

5151
Or, with `npm`
5252

5353
```bash
54-
npm install @nuxtjs/eslint-module
54+
npm install -D @nuxtjs/eslint-module
5555
```
5656

5757
2. Add `@nuxtjs/eslint-module` to the `modules` section of `nuxt.config.js`
@@ -96,19 +96,19 @@ See the [eslint docs](https://eslint.org/docs/latest/integrate/nodejs-api#-new-e
9696

9797
**Note**: The cache is enabled by default to decrease execution time.
9898

99-
### `exclude`
99+
### `include`
100100

101-
- Type: `Array[String]`
102-
- Default: `['**/node_modules/**']]`
101+
- Type: `String|Array[String]`
102+
- Default: `[nuxt.options.srcDir.'/**/*.{js,jsx,ts,tsx,vue}']`
103103

104-
Specify the files and/or directories to exclude.
104+
Specify directories, files, or globs.
105105

106-
### `extensions`
106+
### `exclude`
107107

108-
- Type: `String|Array[String]`
109-
- Default: `['js', 'jsx', 'ts', 'tsx', 'vue']`
108+
- Type: `Array[String]`
109+
- Default: `['**/node_modules/**', nuxt.options.buildDir]`
110110

111-
Specify extensions that should be checked.
111+
Specify the files and/or directories to exclude.
112112

113113
### `eslintPath`
114114

@@ -117,56 +117,49 @@ Specify extensions that should be checked.
117117

118118
Path to `eslint` instance that will be used for linting.
119119

120-
#### `emitError`
120+
### `formatter`
121121

122-
- Type: `Boolean`
123-
- Default: `true`
122+
- Type: `String|Function`
123+
- Default: `'stylish'`
124124

125-
The errors found will be printed.
125+
Accepts a function that will have one argument: an array of eslint messages (object).
126+
The function must return the output as a string.
127+
You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).
126128

127-
#### `emitWarning`
129+
### `lintOnStart`
128130

129131
- Type: `Boolean`
130132
- Default: `true`
131133

132-
The warnings found will be printed.
134+
Check all matching files on project startup, too slow, turn on discreetly.
133135

134-
#### `failOnWarning`
136+
### `emitWarning`
135137

136138
- Type: `Boolean`
137-
- Default: `false`
139+
- Default: `true`
138140

139-
Will cause the module build to fail if there are any warnings, based on `emitWarning`.
141+
The warnings found will be printed.
140142

141-
#### `failOnError`
143+
### `emitError`
142144

143145
- Type: `Boolean`
144-
- Default: `false`
146+
- Default: `true`
145147

146-
Will cause the module build to fail if there are any errors, based on `emitError`.
148+
The errors found will be printed.
147149

148-
### `fix`
150+
### `failOnWarning`
149151

150152
- Type: `Boolean`
151153
- Default: `false`
152154

153-
Auto fix source code.
154-
155-
**Be careful: this option will change source files.**
156-
157-
### `formatter`
158-
159-
- Type: `String|Function`
160-
- Default: `'stylish'`
161-
162-
Accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).
155+
Will cause the module build to fail if there are any warnings, based on `emitWarning`.
163156

164-
### `lintOnStart`
157+
### `failOnError`
165158

166159
- Type: `Boolean`
167-
- Default: `true`
160+
- Default: `false`
168161

169-
Check all matching files on project startup, too slow, turn on discreetly.
162+
Will cause the module build to fail if there are any errors, based on `emitError`.
170163

171164
## Contributing
172165

‎src/module.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import vitePluginEslint from 'vite-plugin-eslint'
55
import EslintWebpackPlugin from 'eslint-webpack-plugin'
66
import { name, version } from '../package.json'
77

8-
export type ModuleOptions = VitePlugin & WebpackPlugin & {
9-
extensions: string[]
10-
}
8+
export type ModuleOptions = VitePlugin & WebpackPlugin
119

1210
export default defineNuxtModule<ModuleOptions>({
1311
meta: {
@@ -18,19 +16,18 @@ export default defineNuxtModule<ModuleOptions>({
1816
bridge: true
1917
}
2018
},
21-
defaults: {
19+
defaults: nuxt => ({
2220
cache: true,
23-
exclude: ['**/node_modules/**'],
24-
extensions: ['js', 'jsx', 'ts', 'tsx', 'vue'],
21+
include: [`${nuxt.options.srcDir}/**/*.{js,jsx,ts,tsx,vue}`],
22+
exclude: ['**/node_modules/**', nuxt.options.buildDir],
2523
eslintPath: 'eslint',
26-
emitError: true,
24+
formatter: 'stylish',
25+
lintOnStart: true,
2726
emitWarning: true,
28-
failOnError: false,
27+
emitError: true,
2928
failOnWarning: false,
30-
fix: false,
31-
formatter: 'stylish',
32-
lintOnStart: true
33-
},
29+
failOnError: false
30+
}),
3431
setup (options, nuxt) {
3532
if (!nuxt.options.dev) {
3633
return
@@ -51,14 +48,12 @@ export default defineNuxtModule<ModuleOptions>({
5148
}
5249
})
5350

54-
addVitePlugin(vitePluginEslint({
55-
...options,
56-
include: options.extensions.map(ext => `**/*.${ext}`)
57-
}), { server: false })
51+
addVitePlugin(vitePluginEslint(options), { server: false })
5852

5953
addWebpackPlugin(new EslintWebpackPlugin({
6054
...options,
6155
context: nuxt.options.srcDir,
56+
files: options.include,
6257
lintDirtyModulesOnly: !options.lintOnStart
6358
}), { server: false })
6459
}

0 commit comments

Comments
 (0)
Please sign in to comment.