Skip to content

Commit 921fa8e

Browse files
committed
feat: scaffold projects with eslint 6
FIXME: Pending vuejs/eslint-plugin-vue#985 Need to remove the `resolutions` field in package.json before merging
1 parent 7a835df commit 921fa8e

File tree

7 files changed

+126
-62
lines changed

7 files changed

+126
-62
lines changed

package.json

+14-6
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,27 @@
4545
},
4646
"devDependencies": {
4747
"@babel/core": "^7.7.4",
48-
"@vue/eslint-config-airbnb": "^4.0.0",
49-
"@vue/eslint-config-prettier": "^5.0.0",
50-
"@vue/eslint-config-standard": "^4.0.0",
51-
"@vue/eslint-config-typescript": "^4.0.0",
48+
"@vue/eslint-config-airbnb": "^5.0.0",
49+
"@vue/eslint-config-prettier": "^6.0.0",
50+
"@vue/eslint-config-standard": "^5.0.0",
51+
"@vue/eslint-config-typescript": "^5.0.1",
5252
"@vuepress/plugin-pwa": "^1.2.0",
5353
"@vuepress/theme-vue": "^1.2.0",
54+
"@typescript-eslint/eslint-plugin": "^2.10.0",
55+
"@typescript-eslint/parser": "^2.10.0",
5456
"babel-core": "7.0.0-bridge.0",
5557
"babel-eslint": "^10.0.3",
5658
"babel-jest": "^24.9.0",
5759
"chromedriver": "^78.0.1",
5860
"debug": "^4.1.0",
59-
"eslint": "^5.16.0",
61+
"eslint": "^6.7.2",
62+
"eslint-plugin-import": "^2.18.2",
6063
"eslint-plugin-graphql": "^3.1.0",
6164
"eslint-plugin-node": "^9.1.0",
6265
"eslint-plugin-prettier": "^3.1.1",
63-
"eslint-plugin-vue": "^5.2.2",
66+
"eslint-plugin-promise": "^4.2.1",
67+
"eslint-plugin-standard": "^4.0.0",
68+
"eslint-plugin-vue": "^6.0.1",
6469
"eslint-plugin-vue-libs": "^4.0.0",
6570
"execa": "^1.0.0",
6671
"geckodriver": "^1.19.1",
@@ -85,6 +90,9 @@
8590
"yorkie": "^2.0.0"
8691
},
8792
"resolutions": {
93+
"eslint": "^6.7.2",
94+
"eslint-plugin-vue": "^6.0.1",
95+
"eslint-plugin-vue/vue-eslint-parser": "^7.0.0",
8896
"puppeteer": "1.11.0",
8997
"vue": "^2.6.10",
9098
"vue-template-compiler": "^2.6.10",

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

+34-16
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ test('base', async () => {
1414
expect(pkg.eslintConfig.extends).toEqual([
1515
'plugin:vue/essential', 'eslint:recommended'
1616
])
17-
expect(pkg.eslintConfig.parserOptions).toEqual({
18-
parser: 'babel-eslint'
19-
})
2017
})
2118

2219
test('airbnb', async () => {
@@ -33,9 +30,6 @@ test('airbnb', async () => {
3330
'plugin:vue/essential',
3431
'@vue/airbnb'
3532
])
36-
expect(pkg.eslintConfig.parserOptions).toEqual({
37-
parser: 'babel-eslint'
38-
})
3933
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-airbnb')
4034
})
4135

@@ -53,9 +47,6 @@ test('standard', async () => {
5347
'plugin:vue/essential',
5448
'@vue/standard'
5549
])
56-
expect(pkg.eslintConfig.parserOptions).toEqual({
57-
parser: 'babel-eslint'
58-
})
5950
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-standard')
6051
})
6152

@@ -71,12 +62,31 @@ test('prettier', async () => {
7162
expect(pkg.scripts.lint).toBeTruthy()
7263
expect(pkg.eslintConfig.extends).toEqual([
7364
'plugin:vue/essential',
65+
'eslint:recommended',
7466
'@vue/prettier'
7567
])
68+
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-prettier')
69+
})
70+
71+
test('babel', async () => {
72+
const { pkg } = await generateWithPlugin([
73+
{
74+
id: 'eslint',
75+
apply: require('../generator'),
76+
options: {}
77+
},
78+
{
79+
id: 'babel',
80+
apply: require('@vue/cli-plugin-babel/generator'),
81+
options: {}
82+
}
83+
])
84+
85+
expect(pkg.scripts.lint).toBeTruthy()
86+
expect(pkg.devDependencies).toHaveProperty('babel-eslint')
7687
expect(pkg.eslintConfig.parserOptions).toEqual({
7788
parser: 'babel-eslint'
7889
})
79-
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-prettier')
8090
})
8191

8292
test('typescript', async () => {
@@ -98,12 +108,11 @@ test('typescript', async () => {
98108
expect(pkg.scripts.lint).toBeTruthy()
99109
expect(pkg.eslintConfig.extends).toEqual([
100110
'plugin:vue/essential',
111+
'eslint:recommended',
112+
'@vue/typescript/recommended',
101113
'@vue/prettier',
102-
'@vue/typescript'
114+
'@vue/prettier/@typescript-eslint'
103115
])
104-
expect(pkg.eslintConfig.parserOptions).toEqual({
105-
parser: '@typescript-eslint/parser'
106-
})
107116
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-prettier')
108117
expect(pkg.devDependencies).toHaveProperty('@vue/eslint-config-typescript')
109118
})
@@ -131,7 +140,7 @@ test('lint on commit', async () => {
131140
expect(pkg.gitHooks['pre-commit']).toBe('lint-staged')
132141
expect(pkg.devDependencies).toHaveProperty('lint-staged')
133142
expect(pkg['lint-staged']).toEqual({
134-
'*.{js,vue}': ['vue-cli-service lint', 'git add']
143+
'*.{js,jsx,vue}': ['vue-cli-service lint', 'git add']
135144
})
136145
expect(pkg.vue).toEqual({
137146
lintOnSave: false
@@ -150,7 +159,7 @@ test('should lint ts files when typescript plugin co-exists', async () => {
150159
const pkg = JSON.parse(await read('package.json'))
151160
expect(pkg).toMatchObject({
152161
'lint-staged': {
153-
'*.{js,vue,ts}': ['vue-cli-service lint', 'git add']
162+
'*.{js,jsx,vue,ts,tsx}': ['vue-cli-service lint', 'git add']
154163
}
155164
})
156165
})
@@ -196,3 +205,12 @@ test('airbnb config + typescript + unit-mocha', async () => {
196205
}
197206
})
198207
}, 30000)
208+
209+
test('should be able to parse dynamic import syntax', async () => {
210+
await create('eslint-dynamic-import', {
211+
plugins: {
212+
'@vue/cli-plugin-eslint': {},
213+
'@vue/cli-plugin-router': {}
214+
}
215+
})
216+
}, 30000)

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ exports.config = api => {
33
root: true,
44
env: { node: true },
55
extends: ['plugin:vue/essential'],
6+
parserOptions: {
7+
ecmaVersion: 2020
8+
},
69
rules: {
710
'no-console': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'error' : 'off'`),
811
'no-debugger': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'error' : 'off'`)
912
}
1013
}
11-
if (!api.hasPlugin('typescript')) {
14+
if (api.hasPlugin('babel') && !api.hasPlugin('typescript')) {
1215
config.parserOptions = {
1316
parser: 'babel-eslint'
1417
}

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

+53-32
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,74 @@ const fs = require('fs')
22
const path = require('path')
33

44
module.exports = (api, { config, lintOn = [] }, _, invoking) => {
5-
if (typeof lintOn === 'string') {
6-
lintOn = lintOn.split(',')
7-
}
8-
95
const eslintConfig = require('../eslintOptions').config(api)
6+
const extentions = require('../eslintOptions').extensions(api)
7+
.map(ext => ext.replace(/^\./, '')) // remove the leading `.`
108

119
const pkg = {
1210
scripts: {
1311
lint: 'vue-cli-service lint'
1412
},
1513
eslintConfig,
1614
devDependencies: {
17-
'eslint': '^5.16.0',
18-
'eslint-plugin-vue': '^5.0.0'
15+
eslint: '^6.7.2',
16+
'eslint-plugin-vue': '^6.0.1'
1917
}
2018
}
2119

22-
if (!api.hasPlugin('typescript')) {
20+
if (api.hasPlugin('babel') && !api.hasPlugin('typescript')) {
2321
pkg.devDependencies['babel-eslint'] = '^10.0.3'
2422
}
2523

26-
if (config === 'airbnb') {
24+
switch (config) {
25+
case 'airbnb':
2726
eslintConfig.extends.push('@vue/airbnb')
2827
Object.assign(pkg.devDependencies, {
29-
'@vue/eslint-config-airbnb': '^4.0.0'
28+
'@vue/eslint-config-airbnb': '^5.0.0',
29+
'eslint-plugin-import': '^2.18.2'
3030
})
31-
} else if (config === 'standard') {
31+
break
32+
case 'standard':
3233
eslintConfig.extends.push('@vue/standard')
3334
Object.assign(pkg.devDependencies, {
34-
'@vue/eslint-config-standard': '^4.0.0'
35+
'@vue/eslint-config-standard': '^5.0.0',
36+
'eslint-plugin-import': '^2.18.2',
37+
'eslint-plugin-node': '^9.1.0',
38+
'eslint-plugin-promise': '^4.2.1',
39+
'eslint-plugin-standard': '^4.0.0'
3540
})
36-
} else if (config === 'prettier') {
37-
eslintConfig.extends.push('@vue/prettier')
41+
break
42+
case 'prettier':
43+
eslintConfig.extends.push(
44+
...(api.hasPlugin('typescript')
45+
? ['eslint:recommended', '@vue/typescript/recommended', '@vue/prettier', '@vue/prettier/@typescript-eslint']
46+
: ['eslint:recommended', '@vue/prettier']
47+
)
48+
)
3849
Object.assign(pkg.devDependencies, {
39-
'@vue/eslint-config-prettier': '^5.0.0',
50+
'@vue/eslint-config-prettier': '^6.0.0',
4051
'eslint-plugin-prettier': '^3.1.1',
4152
prettier: '^1.19.1'
4253
})
43-
// prettier & default config do not have any style rules
44-
// so no need to generate an editorconfig file
45-
} else {
54+
break
55+
default:
4656
// default
4757
eslintConfig.extends.push('eslint:recommended')
58+
break
59+
}
60+
61+
// typescript support
62+
if (api.hasPlugin('typescript')) {
63+
Object.assign(pkg.devDependencies, {
64+
'@vue/eslint-config-typescript': '^5.0.1',
65+
'@typescript-eslint/eslint-plugin': '^2.10.0',
66+
'@typescript-eslint/parser': '^2.10.0'
67+
})
68+
if (config !== 'prettier') {
69+
// for any config other than `prettier`,
70+
// typescript ruleset should be appended to the end of the `extends` array
71+
eslintConfig.extends.push('@vue/typescript/recommended')
72+
}
4873
}
4974

5075
const editorConfigTemplatePath = path.resolve(__dirname, `./template/${config}/_editorconfig`)
@@ -60,6 +85,10 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
6085
}
6186
}
6287

88+
if (typeof lintOn === 'string') {
89+
lintOn = lintOn.split(',')
90+
}
91+
6392
if (!lintOn.includes('save')) {
6493
pkg.vue = {
6594
lintOnSave: false // eslint-loader configured in runtime plugin
@@ -73,24 +102,13 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
73102
pkg.gitHooks = {
74103
'pre-commit': 'lint-staged'
75104
}
76-
if (api.hasPlugin('typescript')) {
77-
pkg['lint-staged'] = {
78-
'*.{js,vue,ts}': ['vue-cli-service lint', 'git add']
79-
}
80-
} else {
81-
pkg['lint-staged'] = {
82-
'*.{js,vue}': ['vue-cli-service lint', 'git add']
83-
}
105+
pkg['lint-staged'] = {
106+
[`*.{${extentions.join(',')}}`]: ['vue-cli-service lint', 'git add']
84107
}
85108
}
86109

87110
api.extendPackage(pkg)
88111

89-
// typescript support
90-
if (api.hasPlugin('typescript')) {
91-
applyTS(api)
92-
}
93-
94112
// invoking only
95113
if (invoking) {
96114
if (api.hasPlugin('unit-mocha')) {
@@ -130,7 +148,8 @@ module.exports.hooks = (api) => {
130148
})
131149
}
132150

133-
const applyTS = module.exports.applyTS = api => {
151+
// exposed for the typescript plugin
152+
module.exports.applyTS = api => {
134153
api.extendPackage({
135154
eslintConfig: {
136155
extends: ['@vue/typescript'],
@@ -139,7 +158,9 @@ const applyTS = module.exports.applyTS = api => {
139158
}
140159
},
141160
devDependencies: {
142-
'@vue/eslint-config-typescript': '^4.0.0'
161+
'@vue/eslint-config-typescript': '^5.0.1',
162+
'@typescript-eslint/eslint-plugin': '^2.7.0',
163+
'@typescript-eslint/parser': '^2.7.0'
143164
}
144165
})
145166
}

packages/@vue/cli-ui-addon-webpack/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
"@vue/cli-plugin-babel": "^4.1.1",
2222
"@vue/cli-plugin-eslint": "^4.1.1",
2323
"@vue/cli-service": "^4.1.1",
24-
"@vue/eslint-config-standard": "^4.0.0",
24+
"@vue/eslint-config-standard": "^5.0.0",
2525
"core-js": "^3.4.4",
26-
"eslint": "^5.16.0",
26+
"eslint": "^6.7.2",
27+
"eslint-plugin-import": "^2.18.0",
28+
"eslint-plugin-node": "^9.1.0",
29+
"eslint-plugin-promise": "^4.2.1",
30+
"eslint-plugin-standard": "^4.0.0",
31+
"eslint-plugin-vue": "^6.0.1",
2732
"stylus": "^0.54.7",
2833
"stylus-loader": "^3.0.2",
2934
"vue-progress-path": "^0.0.2",

packages/@vue/cli-ui-addon-widgets/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
"@vue/cli-plugin-babel": "^4.1.1",
2222
"@vue/cli-plugin-eslint": "^4.1.1",
2323
"@vue/cli-service": "^4.1.1",
24-
"@vue/eslint-config-standard": "^4.0.0",
24+
"@vue/eslint-config-standard": "^5.0.0",
2525
"core-js": "^3.4.4",
26-
"eslint": "^5.16.0",
26+
"eslint": "^6.7.2",
27+
"eslint-plugin-import": "^2.18.0",
28+
"eslint-plugin-node": "^9.1.0",
29+
"eslint-plugin-promise": "^4.2.1",
30+
"eslint-plugin-standard": "^4.0.0",
31+
"eslint-plugin-vue": "^6.0.1",
2732
"stylus": "^0.54.7",
2833
"stylus-loader": "^3.0.2",
2934
"vue-template-compiler": "^2.6.10"

packages/@vue/cli-ui/package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,21 @@
6666
"@vue/cli-plugin-e2e-cypress": "^4.1.1",
6767
"@vue/cli-plugin-eslint": "^4.1.1",
6868
"@vue/cli-service": "^4.1.1",
69-
"@vue/eslint-config-standard": "^4.0.0",
69+
"@vue/eslint-config-standard": "^5.0.0",
7070
"@vue/ui": "^0.9.2",
7171
"ansi_up": "^3.0.0",
7272
"apollo-client": "^2.6.0",
7373
"apollo-link": "^1.0.0",
7474
"babel-eslint": "^10.0.3",
7575
"core-js": "^3.4.4",
7676
"cross-env": "^6.0.3",
77-
"eslint": "^5.16.0",
77+
"eslint": "^6.7.2",
7878
"eslint-plugin-graphql": "^3.1.0",
79-
"eslint-plugin-vue": "^5.2.2",
79+
"eslint-plugin-import": "^2.18.0",
80+
"eslint-plugin-node": "^9.1.0",
81+
"eslint-plugin-promise": "^4.2.1",
82+
"eslint-plugin-standard": "^4.0.0",
83+
"eslint-plugin-vue": "^6.0.1",
8084
"lint-staged": "^9.5.0",
8185
"lodash.debounce": "^4.0.8",
8286
"portal-vue": "^1.3.0",

0 commit comments

Comments
 (0)