Skip to content

Commit a6d3166

Browse files
LinusBorghaoqunjiang
authored andcommitted
feat: add 3rd option to lintOnSave to support 'default' behaviour (fix #3552) (#3572)
1 parent 09964a0 commit a6d3166

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

docs/config/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,16 @@ Deprecated since Vue CLI 3.3, please use [`publicPath`](#publicPath) instead.
140140

141141
### lintOnSave
142142

143-
- Type: `boolean | 'error'`
143+
- Type: `boolean | 'warning' | 'default' | 'error'`
144144
- Default: `true`
145145

146146
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.
147147

148-
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.
148+
When set to `true` or `'warning'`, `eslint-loader` will emit lint errors as warnings. By default, warnings are only logged to the terminal and does not fail the compilation, so this is a good default for development.
149149

150-
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.
150+
To make lint errors show up in the browser overlay, you can use `lintOnSave: 'default'`. This will force `eslint-loader` to actually emit errors. this also means lint errors will now cause the compilation to fail.
151+
152+
Setting it to `'errors'` will force eslint-loader to emit warnings as errors as well, which means warnings will also show up in the overlay.
151153

152154
Alternatively, you can configure the overlay to display both warnings and errors:
153155

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = (api, options) => {
1717
'eslint-loader',
1818
{
1919
'eslint-loader': require('eslint-loader/package.json').version,
20-
'eslint': eslintPkg.version
20+
eslint: eslintPkg.version
2121
},
2222
[
2323
'.eslintrc.js',
@@ -30,7 +30,13 @@ module.exports = (api, options) => {
3030
)
3131

3232
api.chainWebpack(webpackConfig => {
33-
webpackConfig.resolveLoader.modules.prepend(path.join(__dirname, 'node_modules'))
33+
webpackConfig.resolveLoader.modules.prepend(
34+
path.join(__dirname, 'node_modules')
35+
)
36+
37+
const { lintOnSave } = options
38+
const allWarnings = lintOnSave === true || lintOnSave === 'warning'
39+
const allErrors = lintOnSave === 'error'
3440

3541
webpackConfig.module
3642
.rule('eslint')
@@ -46,8 +52,9 @@ module.exports = (api, options) => {
4652
extensions,
4753
cache: true,
4854
cacheIdentifier,
49-
emitWarning: options.lintOnSave !== 'error',
50-
emitError: options.lintOnSave === 'error',
55+
emitWarning: allWarnings,
56+
// only emit errors in production mode.
57+
emitError: allErrors,
5158
eslintPath: resolveModule('eslint', cwd) || require.resolve('eslint'),
5259
formatter:
5360
loadModule('eslint/lib/formatters/codeframe', cwd, true) ||
@@ -56,18 +63,25 @@ module.exports = (api, options) => {
5663
})
5764
}
5865

59-
api.registerCommand('lint', {
60-
description: 'lint and fix source files',
61-
usage: 'vue-cli-service lint [options] [...files]',
62-
options: {
63-
'--format [formatter]': 'specify formatter (default: codeframe)',
64-
'--no-fix': 'do not fix errors or warnings',
65-
'--no-fix-warnings': 'fix errors, but do not fix warnings',
66-
'--max-errors [limit]': 'specify number of errors to make build failed (default: 0)',
67-
'--max-warnings [limit]': 'specify number of warnings to make build failed (default: Infinity)'
66+
api.registerCommand(
67+
'lint',
68+
{
69+
description: 'lint and fix source files',
70+
usage: 'vue-cli-service lint [options] [...files]',
71+
options: {
72+
'--format [formatter]': 'specify formatter (default: codeframe)',
73+
'--no-fix': 'do not fix errors or warnings',
74+
'--no-fix-warnings': 'fix errors, but do not fix warnings',
75+
'--max-errors [limit]':
76+
'specify number of errors to make build failed (default: 0)',
77+
'--max-warnings [limit]':
78+
'specify number of warnings to make build failed (default: Infinity)'
79+
},
80+
details:
81+
'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
6882
},
69-
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
70-
}, args => {
71-
require('./lint')(args, api)
72-
})
83+
args => {
84+
require('./lint')(args, api)
85+
}
86+
)
7387
}

packages/@vue/cli-service/lib/options.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const schema = createSchema(joi => joi.object({
5151
),
5252

5353
// known runtime options for built-in plugins
54-
lintOnSave: joi.any().valid([true, false, 'error']),
54+
lintOnSave: joi.any().valid([true, false, 'error', 'warning', 'default']),
5555
pwa: joi.object(),
5656

5757
// 3rd party plugin options
@@ -95,7 +95,9 @@ exports.defaults = () => ({
9595
runtimeCompiler: false,
9696

9797
// deps to transpile
98-
transpileDependencies: [/* string or regex */],
98+
transpileDependencies: [
99+
/* string or regex */
100+
],
99101

100102
// sourceMap for production build?
101103
productionSourceMap: !process.env.VUE_CLI_TEST,
@@ -126,7 +128,7 @@ exports.defaults = () => ({
126128
lintOnSave: true,
127129

128130
devServer: {
129-
/*
131+
/*
130132
open: process.platform === 'darwin',
131133
host: '0.0.0.0',
132134
port: 8080,

0 commit comments

Comments
 (0)