Skip to content

Commit

Permalink
feat(eslint): add --max-warnings and --max-errors for cli-plugin-esli…
Browse files Browse the repository at this point in the history
…nt (#1289)

close #1268
  • Loading branch information
jkzing authored and yyx990803 committed May 18, 2018
1 parent be94630 commit ab877a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/@vue/cli-plugin-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = (api, { lintOnSave }) => {
usage: 'vue-cli-service lint [options] [...files]',
options: {
'--format [formatter]': 'specify formatter (default: codeframe)',
'--no-fix': 'do not fix errors'
'--no-fix': 'do not fix errors',
'--max-errors [limit]': 'specify number of errors to make build failed (default: 0)',
'--max-warnings [limit]': 'specify number of warnings to make build failed (default: Infinity)'
},
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
}, args => {
Expand Down
18 changes: 15 additions & 3 deletions packages/@vue/cli-plugin-eslint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ module.exports = function lint (args = {}, api) {
const { log, done } = require('@vue/cli-shared-utils')

const files = args._ && args._.length ? args._ : ['src', 'tests', '*.js']
const argsConfig = normalizeConfig(args)
const config = Object.assign({}, options, {
fix: true,
cwd
}, normalizeConfig(args))
}, argsConfig)
const engine = new CLIEngine(config)
const report = engine.executeOnFiles(files)
const formatter = engine.getFormatter(args.format || 'codeframe')

if (config.fix) {
CLIEngine.outputFixes(report)
}

const maxErrors = argsConfig.maxErrors || 0
const maxWarnings = typeof argsConfig.maxWarnings === 'number' ? argsConfig.maxWarnings : Infinity
const isErrorsExceeded = report.errorCount > maxErrors
const isWarningsExceeded = report.warningCount > maxWarnings

if (!report.errorCount) {
if (!isErrorsExceeded && !isWarningsExceeded) {
if (!args.silent) {
const hasFixed = report.results.some(f => f.output)
if (hasFixed) {
Expand All @@ -32,14 +38,20 @@ module.exports = function lint (args = {}, api) {
})
log()
}
if (report.warningCount) {
if (report.warningCount || report.errorCount) {
console.log(formatter(report.results))
} else {
done(hasFixed ? `All lint errors auto-fixed.` : `No lint errors found!`)
}
}
} else {
console.log(formatter(report.results))
if (isErrorsExceed && typeof argsConfig.maxErrors === 'number') {
log(`Eslint found too many errors (maximum: ${argsConfig.maxErrors}).`)
}
if (isWarningsExceed) {
log(`Eslint found too many warnings (maximum: ${argsConfig.maxWarnings}).`)
}
process.exit(1)
}
}
Expand Down

0 comments on commit ab877a2

Please sign in to comment.