Skip to content

Commit 9b4970c

Browse files
author
Guillaume Chau
committed
chore: merge dev
2 parents c9d58d9 + 07ac887 commit 9b4970c

File tree

12 files changed

+138
-64
lines changed

12 files changed

+138
-64
lines changed

packages/@vue/cli-plugin-eslint/__tests__/eslintGenerator.spec.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ test('base', async () => {
88
})
99

1010
expect(pkg.scripts.lint).toBeTruthy()
11-
expect(pkg.eslintConfig).toEqual({
12-
root: true,
13-
extends: ['plugin:vue/essential', 'eslint:recommended']
11+
expect(pkg.eslintConfig.extends).toEqual([
12+
'plugin:vue/essential', 'eslint:recommended'
13+
])
14+
expect(pkg.eslintConfig.parserOptions).toEqual({
15+
parser: 'babel-eslint'
1416
})
1517
})
1618

@@ -24,9 +26,12 @@ test('airbnb', async () => {
2426
})
2527

2628
expect(pkg.scripts.lint).toBeTruthy()
27-
expect(pkg.eslintConfig).toEqual({
28-
root: true,
29-
extends: ['plugin:vue/essential', '@vue/airbnb']
29+
expect(pkg.eslintConfig.extends).toEqual([
30+
'plugin:vue/essential',
31+
'@vue/airbnb'
32+
])
33+
expect(pkg.eslintConfig.parserOptions).toEqual({
34+
parser: 'babel-eslint'
3035
})
3136
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-airbnb')
3237
})
@@ -41,9 +46,12 @@ test('standard', async () => {
4146
})
4247

4348
expect(pkg.scripts.lint).toBeTruthy()
44-
expect(pkg.eslintConfig).toEqual({
45-
root: true,
46-
extends: ['plugin:vue/essential', '@vue/standard']
49+
expect(pkg.eslintConfig.extends).toEqual([
50+
'plugin:vue/essential',
51+
'@vue/standard'
52+
])
53+
expect(pkg.eslintConfig.parserOptions).toEqual({
54+
parser: 'babel-eslint'
4755
})
4856
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-standard')
4957
})
@@ -58,9 +66,12 @@ test('prettier', async () => {
5866
})
5967

6068
expect(pkg.scripts.lint).toBeTruthy()
61-
expect(pkg.eslintConfig).toEqual({
62-
root: true,
63-
extends: ['plugin:vue/essential', '@vue/prettier']
69+
expect(pkg.eslintConfig.extends).toEqual([
70+
'plugin:vue/essential',
71+
'@vue/prettier'
72+
])
73+
expect(pkg.eslintConfig.parserOptions).toEqual({
74+
parser: 'babel-eslint'
6475
})
6576
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-prettier')
6677
})
@@ -82,10 +93,12 @@ test('typescript', async () => {
8293
])
8394

8495
expect(pkg.scripts.lint).toBeTruthy()
85-
expect(pkg.eslintConfig).toEqual({
86-
root: true,
87-
extends: ['plugin:vue/essential', '@vue/prettier', '@vue/typescript']
88-
})
96+
expect(pkg.eslintConfig.extends).toEqual([
97+
'plugin:vue/essential',
98+
'@vue/prettier',
99+
'@vue/typescript'
100+
])
101+
expect(pkg.eslintConfig).not.toHaveProperty('parserOptions')
89102
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-prettier')
90103
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-typescript')
91104
})
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
module.exports = api => {
2-
const options = {
3-
extensions: ['.js', '.vue'],
4-
envs: ['node'],
1+
exports.config = api => {
2+
const config = {
3+
root: true,
4+
env: { node: true },
5+
extends: ['plugin:vue/essential'],
56
rules: {
6-
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
7-
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
7+
'no-console': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'error' : 'off'`),
8+
'no-debugger': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'error' : 'off'`)
89
}
910
}
10-
11-
if (api.hasPlugin('typescript')) {
12-
options.extensions.push('.ts')
13-
} else {
14-
options.parserOptions = {
15-
parser: require.resolve('babel-eslint')
11+
if (!api.hasPlugin('typescript')) {
12+
config.parserOptions = {
13+
parser: 'babel-eslint'
1614
}
1715
}
16+
return config
17+
}
1818

19-
return options
19+
// __expression is a special flag that allows us to customize stringification
20+
// output when extracting configs into standalone files
21+
function makeJSOnlyValue (str) {
22+
const fn = () => {}
23+
fn.__expression = str
24+
return fn
2025
}
26+
27+
const baseExtensions = ['.js', '.jsx', '.vue']
28+
exports.extensions = api => api.hasPlugin('typescript')
29+
? baseExtensions.concat('.ts', '.tsx')
30+
: baseExtensions

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@ module.exports = (api, { config, lintOn = [] }) => {
33
lintOn = lintOn.split(',')
44
}
55

6+
const eslintConfig = require('./eslintOptions').config(api)
7+
68
const pkg = {
79
scripts: {
810
lint: 'vue-cli-service lint'
911
},
10-
eslintConfig: {
11-
root: true,
12-
extends: ['plugin:vue/essential']
13-
},
12+
eslintConfig,
1413
devDependencies: {}
1514
}
1615

1716
if (config === 'airbnb') {
18-
pkg.eslintConfig.extends.push('@vue/airbnb')
17+
eslintConfig.extends.push('@vue/airbnb')
1918
Object.assign(pkg.devDependencies, {
2019
'@vue/eslint-config-airbnb': '^3.0.0-beta.10'
2120
})
2221
} else if (config === 'standard') {
23-
pkg.eslintConfig.extends.push('@vue/standard')
22+
eslintConfig.extends.push('@vue/standard')
2423
Object.assign(pkg.devDependencies, {
2524
'@vue/eslint-config-standard': '^3.0.0-beta.10'
2625
})
2726
} else if (config === 'prettier') {
28-
pkg.eslintConfig.extends.push('@vue/prettier')
27+
eslintConfig.extends.push('@vue/prettier')
2928
Object.assign(pkg.devDependencies, {
3029
'@vue/eslint-config-prettier': '^3.0.0-beta.10'
3130
})
3231
} else {
3332
// default
34-
pkg.eslintConfig.extends.push('eslint:recommended')
33+
eslintConfig.extends.push('eslint:recommended')
3534
}
3635

3736
// typescript support
3837
if (api.hasPlugin('typescript')) {
39-
pkg.eslintConfig.extends.push('@vue/typescript')
38+
eslintConfig.extends.push('@vue/typescript')
4039
Object.assign(pkg.devDependencies, {
4140
'@vue/eslint-config-typescript': '^3.0.0-beta.10'
4241
})

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = (api, { lintOnSave }) => {
22
if (lintOnSave) {
3-
const options = require('./eslintOptions')(api)
3+
const extensions = require('./eslintOptions').extensions(api)
44
api.chainWebpack(webpackConfig => {
55
webpackConfig.module
66
.rule('eslint')
@@ -12,10 +12,11 @@ module.exports = (api, { lintOnSave }) => {
1212
.test(/\.(vue|(j|t)sx?)$/)
1313
.use('eslint-loader')
1414
.loader('eslint-loader')
15-
.options(Object.assign(options, {
15+
.options({
16+
extensions,
1617
emitWarning: lintOnSave !== 'error',
1718
formatter: require('eslint/lib/formatters/codeframe')
18-
}))
19+
})
1920
})
2021
}
2122

@@ -24,7 +25,9 @@ module.exports = (api, { lintOnSave }) => {
2425
usage: 'vue-cli-service lint [options] [...files]',
2526
options: {
2627
'--format [formatter]': 'specify formatter (default: codeframe)',
27-
'--no-fix': 'do not fix errors'
28+
'--no-fix': 'do not fix errors',
29+
'--max-errors [limit]': 'specify number of errors to make build failed (default: 0)',
30+
'--max-warnings [limit]': 'specify number of warnings to make build failed (default: Infinity)'
2831
},
2932
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
3033
}, args => {

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1+
const renamedArrayArgs = {
2+
ext: 'extensions',
3+
env: 'envs',
4+
global: 'globals',
5+
rulesdir: 'rulePaths',
6+
plugin: 'plugins',
7+
'ignore-pattern': 'ignorePattern'
8+
}
9+
10+
const renamedArgs = {
11+
'inline-config': 'allowInlineConfig',
12+
rule: 'rules',
13+
eslintrc: 'useEslintrc',
14+
c: 'configFile',
15+
config: 'configFile'
16+
}
17+
118
module.exports = function lint (args = {}, api) {
219
const path = require('path')
320
const chalk = require('chalk')
421
const cwd = api.resolve('.')
522
const { CLIEngine } = require('eslint')
6-
const options = require('./eslintOptions')(api)
723
const { log, done, exit } = require('@vue/cli-shared-utils')
824

925
const files = args._ && args._.length ? args._ : ['src', 'tests', '*.js']
10-
const config = Object.assign({}, options, {
26+
const extensions = require('./eslintOptions').extensions(api)
27+
const argsConfig = normalizeConfig(args)
28+
const config = Object.assign({
29+
extensions,
1130
fix: true,
1231
cwd
13-
}, normalizeConfig(args))
32+
}, argsConfig)
1433
const engine = new CLIEngine(config)
1534
const report = engine.executeOnFiles(files)
1635
const formatter = engine.getFormatter(args.format || 'codeframe')
@@ -19,7 +38,12 @@ module.exports = function lint (args = {}, api) {
1938
CLIEngine.outputFixes(report)
2039
}
2140

22-
if (!report.errorCount) {
41+
const maxErrors = argsConfig.maxErrors || 0
42+
const maxWarnings = typeof argsConfig.maxWarnings === 'number' ? argsConfig.maxWarnings : Infinity
43+
const isErrorsExceeded = report.errorCount > maxErrors
44+
const isWarningsExceeded = report.warningCount > maxWarnings
45+
46+
if (!isErrorsExceeded && !isWarningsExceeded) {
2347
if (!args.silent) {
2448
const hasFixed = report.results.some(f => f.output)
2549
if (hasFixed) {
@@ -32,22 +56,32 @@ module.exports = function lint (args = {}, api) {
3256
})
3357
log()
3458
}
35-
if (report.warningCount) {
59+
if (report.warningCount || report.errorCount) {
3660
console.log(formatter(report.results))
3761
} else {
3862
done(hasFixed ? `All lint errors auto-fixed.` : `No lint errors found!`)
3963
}
4064
}
4165
} else {
4266
console.log(formatter(report.results))
67+
if (isErrorsExceeded && typeof argsConfig.maxErrors === 'number') {
68+
log(`Eslint found too many errors (maximum: ${argsConfig.maxErrors}).`)
69+
}
70+
if (isWarningsExceeded) {
71+
log(`Eslint found too many warnings (maximum: ${argsConfig.maxWarnings}).`)
72+
}
4373
exit(1)
4474
}
4575
}
4676

4777
function normalizeConfig (args) {
4878
const config = {}
4979
for (const key in args) {
50-
if (key !== '_') {
80+
if (renamedArrayArgs[key]) {
81+
config[renamedArrayArgs[key]] = args[key].split(',')
82+
} else if (renamedArgs[key]) {
83+
config[renamedArgs[key]] = args[key]
84+
} else if (key !== '_') {
5185
config[camelize(key)] = args[key]
5286
}
5387
}

packages/@vue/cli-service/lib/commands/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = (api, options) => {
3636
res = config
3737
}
3838

39-
const output = toString(config, { verbose })
39+
const output = toString(res, { verbose })
4040
console.log(output)
4141
})
4242
}

packages/@vue/cli/__tests__/Generator.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs-extra')
44
const path = require('path')
55
const Generator = require('../lib/Generator')
66
const { logs } = require('@vue/cli-shared-utils')
7-
const stringifyJS = require('javascript-stringify')
7+
const stringifyJS = require('../util/stringifyJS')
88

99
// prepare template fixtures
1010
const templateDir = path.resolve(__dirname, 'template')

packages/@vue/cli/__tests__/invoke.spec.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ const parseJS = file => {
1111
return res.exports
1212
}
1313

14+
const baseESLintConfig = Object.assign({}, require('@vue/cli-plugin-eslint/eslintOptions').config({
15+
hasPlugin: () => false
16+
}), {
17+
rules: {
18+
'no-console': 'off',
19+
'no-debugger': 'off'
20+
}
21+
})
22+
1423
async function createAndInstall (name) {
1524
const project = await create(name, {
1625
plugins: {
@@ -33,10 +42,9 @@ async function assertUpdates (project) {
3342
})
3443

3544
const eslintrc = parseJS(await project.read('.eslintrc.js'))
36-
expect(eslintrc).toEqual({
37-
root: true,
45+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
3846
extends: ['plugin:vue/essential', '@vue/airbnb']
39-
})
47+
}))
4048

4149
const lintedMain = await project.read('src/main.js')
4250
expect(lintedMain).toMatch(';') // should've been linted in post-generate hook
@@ -85,10 +93,9 @@ test('invoke with existing files', async () => {
8593
await project.write('vue.config.js', `module.exports = { lintOnSave: true }`)
8694

8795
const eslintrc = parseJS(await project.read('.eslintrc.js'))
88-
expect(eslintrc).toEqual({
89-
root: true,
96+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
9097
extends: ['plugin:vue/essential', 'eslint:recommended']
91-
})
98+
}))
9299

93100
await project.run(`${require.resolve('../bin/vue')} invoke eslint --config airbnb --lintOn commit`)
94101

@@ -111,10 +118,9 @@ test('invoke with existing files (yaml)', async () => {
111118
await project.write('package.json', JSON.stringify(pkg, null, 2))
112119

113120
const eslintrc = parseJS(await project.read('.eslintrc.js'))
114-
expect(eslintrc).toEqual({
115-
root: true,
121+
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
116122
extends: ['plugin:vue/essential', 'eslint:recommended']
117-
})
123+
}))
118124

119125
await project.rm(`.eslintrc.js`)
120126
await project.write(`.eslintrc.yml`, `
@@ -128,10 +134,9 @@ extends:
128134

129135
const updated = await project.read('.eslintrc.yml')
130136
expect(updated).toMatch(`
131-
root: true
132137
extends:
133138
- 'plugin:vue/essential'
134-
- '@vue/airbnb'
139+
- 'eslint:recommended'
135140
`.trim())
136141
})
137142

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const resolve = require('resolve')
77
const isBinary = require('isbinaryfile')
88
const yaml = require('yaml-front-matter')
99
const mergeDeps = require('./util/mergeDeps')
10-
const stringifyJS = require('javascript-stringify')
10+
const stringifyJS = require('./util/stringifyJS')
1111
const { getPluginLink, toShortPluginId } = require('@vue/cli-shared-utils')
1212

1313
const isString = val => typeof val === 'string'

packages/@vue/cli/lib/util/configTransforms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs')
22
const path = require('path')
33
const extendJSConfig = require('./extendJSConfig')
4-
const stringifyJS = require('javascript-stringify')
4+
const stringifyJS = require('./stringifyJS')
55

66
function makeJSTransform (filename) {
77
return function transformToJS (value, checkExisting, context) {

0 commit comments

Comments
 (0)