Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lint): add max-warnings for cli-plugin-eslint, close #1268 #1289

Merged
merged 4 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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