Skip to content

Commit ab877a2

Browse files
jkzingyyx990803
authored andcommitted
feat(eslint): add --max-warnings and --max-errors for cli-plugin-eslint (#1289)
close #1268
1 parent be94630 commit ab877a2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module.exports = (api, { lintOnSave }) => {
2424
usage: 'vue-cli-service lint [options] [...files]',
2525
options: {
2626
'--format [formatter]': 'specify formatter (default: codeframe)',
27-
'--no-fix': 'do not fix errors'
27+
'--no-fix': 'do not fix errors',
28+
'--max-errors [limit]': 'specify number of errors to make build failed (default: 0)',
29+
'--max-warnings [limit]': 'specify number of warnings to make build failed (default: Infinity)'
2830
},
2931
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
3032
}, args => {

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ module.exports = function lint (args = {}, api) {
77
const { log, done } = require('@vue/cli-shared-utils')
88

99
const files = args._ && args._.length ? args._ : ['src', 'tests', '*.js']
10+
const argsConfig = normalizeConfig(args)
1011
const config = Object.assign({}, options, {
1112
fix: true,
1213
cwd
13-
}, normalizeConfig(args))
14+
}, argsConfig)
1415
const engine = new CLIEngine(config)
1516
const report = engine.executeOnFiles(files)
1617
const formatter = engine.getFormatter(args.format || 'codeframe')
1718

1819
if (config.fix) {
1920
CLIEngine.outputFixes(report)
2021
}
22+
23+
const maxErrors = argsConfig.maxErrors || 0
24+
const maxWarnings = typeof argsConfig.maxWarnings === 'number' ? argsConfig.maxWarnings : Infinity
25+
const isErrorsExceeded = report.errorCount > maxErrors
26+
const isWarningsExceeded = report.warningCount > maxWarnings
2127

22-
if (!report.errorCount) {
28+
if (!isErrorsExceeded && !isWarningsExceeded) {
2329
if (!args.silent) {
2430
const hasFixed = report.results.some(f => f.output)
2531
if (hasFixed) {
@@ -32,14 +38,20 @@ module.exports = function lint (args = {}, api) {
3238
})
3339
log()
3440
}
35-
if (report.warningCount) {
41+
if (report.warningCount || report.errorCount) {
3642
console.log(formatter(report.results))
3743
} else {
3844
done(hasFixed ? `All lint errors auto-fixed.` : `No lint errors found!`)
3945
}
4046
}
4147
} else {
4248
console.log(formatter(report.results))
49+
if (isErrorsExceed && typeof argsConfig.maxErrors === 'number') {
50+
log(`Eslint found too many errors (maximum: ${argsConfig.maxErrors}).`)
51+
}
52+
if (isWarningsExceed) {
53+
log(`Eslint found too many warnings (maximum: ${argsConfig.maxWarnings}).`)
54+
}
4355
process.exit(1)
4456
}
4557
}

0 commit comments

Comments
 (0)