Skip to content

Commit d96a794

Browse files
committed
fix(eslint): always emit error when lintOnSave === error + improve docs
ref vuejs#2162
1 parent ddbb375 commit d96a794

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

docs/config/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,34 @@ module.exports = {
135135
- Type: `boolean | 'error'`
136136
- Default: `true`
137137

138-
::: tip
139-
If you want lint errors to show up in the browser overlay, set this to `'error'`.
140-
:::
141-
142138
Whether to perform lint-on-save during development using [eslint-loader](https://github.com/webpack-contrib/eslint-loader). This value is respected only when [`@vue/cli-plugin-eslint`](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint) is installed.
143139

144-
When set to `true`, eslint-loader will emit warnings (which only get logged to the terminal to avoid interrupting development). If you want it to emit errors instead, set it to `'error'`. This will make lint errors show up in the in-browser dev overlay and will make your build fail on lint errors.
140+
When set to `true`, `eslint-loader` will emit lint errors as warnings. By default, warnings are only logged to the terminal and does not fail the compilation.
141+
142+
To make lint errors show up in the browser overlay, you can use `lintOnSave: 'error'`. This will force `eslint-loader` to always emit errors. this also means lint errors will now cause the compilation to fail.
143+
144+
Alternatively, you can configure the overlay to display both warnings and errors:
145+
146+
``` js
147+
// vue.config.js
148+
module.exports = {
149+
devServer: {
150+
overlay: {
151+
warnings: true,
152+
errors: true
153+
}
154+
}
155+
}
156+
```
157+
158+
When `lintOnSave` is a truthy value, `eslint-loader` will be applied in both development and production. If you want to disable `eslint-loader` during production build, you can use the following config:
159+
160+
``` js
161+
// vue.config.js
162+
module.exports = {
163+
lintOnSave: process.env.NODE_ENV !== 'production'
164+
}
165+
```
145166

146167
### runtimeCompiler
147168

docs/zh/config/README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,34 @@ module.exports = {
133133
- Type: `boolean` | `'error'`
134134
- Default: `true`
135135

136-
::: tip
137-
如果你想要让 lint 错误在开发时直接显示在浏览器中,将这个选项设置为 `'error'`
138-
:::
139-
140136
是否在开发环境下通过 [eslint-loader](https://github.com/webpack-contrib/eslint-loader) 在每次保存时 lint 代码。这个值会在 [`@vue/cli-plugin-eslint`](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint) 被安装之后生效。
141137

142-
设置为 `true` 时,eslint-loader 在 webpack 的编译过程中会触发输出到控制台的警告,以避免中断开发流程。如果设置为 `'error'`,则 lint 错误会在开发时直接显示在浏览器中。另外构建时如果存在 lint 错误会导致构建失败。
138+
设置为 `true` 时,`eslint-loader` 会将 lint 错误输出为编译警告。默认情况下,警告仅仅会被输出到命令行,且不会使得编译失败。
139+
140+
如果你希望让 lint 错误在开发时直接显示在浏览器中,你可以使用 `lintOnSave: 'error'`。这会强制 `eslint-loader` 将 lint 错误输出为编译错误,同时也意味着 lint 错误将会导致编译失败。
141+
142+
或者,你也可以通过设置让浏览器 overlay 同时显示警告和错误:
143+
144+
``` js
145+
// vue.config.js
146+
module.exports = {
147+
devServer: {
148+
overlay: {
149+
warnings: true,
150+
errors: true
151+
}
152+
}
153+
}
154+
```
155+
156+
`lintOnSave` 是一个 truthy 的值时,`eslint-loader` 在开发和生产构建下都会被启用。如果你想要在生产构建时禁用 `eslint-loader`,你可以用如下配置:
157+
158+
``` js
159+
// vue.config.js
160+
module.exports = {
161+
lintOnSave: process.env.NODE_ENV !== 'production'
162+
}
163+
```
143164

144165
### runtimeCompiler
145166

packages/@vue/cli-plugin-eslint/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ module.exports = {
3333
}
3434
```
3535

36+
When set to `true`, `eslint-loader` will emit lint errors as warnings. By default, warnings are only logged to the terminal and does not fail the compilation.
37+
38+
To make lint errors show up in the browser overlay, you can use `lintOnSave: 'error'`. This will force `eslint-loader` to always emit errors. this also means lint errors will now cause the compilation to fail.
39+
40+
Alternatively, you can configure the overlay to display both warnings and errors:
41+
42+
``` js
43+
// vue.config.js
44+
module.exports = {
45+
devServer: {
46+
overlay: {
47+
warnings: true,
48+
errors: true
49+
}
50+
}
51+
}
52+
```
53+
54+
When `lintOnSave` is a truthy value, `eslint-loader` will be applied in both development and production. If you want to disable `eslint-loader` during production build, you can use the following config:
55+
56+
``` js
57+
// vue.config.js
58+
module.exports = {
59+
lintOnSave: process.env.NODE_ENV !== 'production'
60+
}
61+
```
62+
3663
## Installing in an Already Created Project
3764

3865
``` sh

packages/@vue/cli-plugin-eslint/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = (api, options) => {
3737
cache: true,
3838
cacheIdentifier,
3939
emitWarning: options.lintOnSave !== 'error',
40+
emitError: options.lintOnSave === 'error',
4041
formatter: require('eslint/lib/formatters/codeframe')
4142
})
4243
})

0 commit comments

Comments
 (0)