@@ -2,49 +2,74 @@ const fs = require('fs')
2
2
const path = require ( 'path' )
3
3
4
4
module . exports = ( api , { config, lintOn = [ ] } , _ , invoking ) => {
5
- if ( typeof lintOn === 'string' ) {
6
- lintOn = lintOn . split ( ',' )
7
- }
8
-
9
5
const eslintConfig = require ( '../eslintOptions' ) . config ( api )
6
+ const extentions = require ( '../eslintOptions' ) . extensions ( api )
7
+ . map ( ext => ext . replace ( / ^ \. / , '' ) ) // remove the leading `.`
10
8
11
9
const pkg = {
12
10
scripts : {
13
11
lint : 'vue-cli-service lint'
14
12
} ,
15
13
eslintConfig,
16
14
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 '
19
17
}
20
18
}
21
19
22
- if ( ! api . hasPlugin ( 'typescript' ) ) {
20
+ if ( api . hasPlugin ( 'babel' ) && ! api . hasPlugin ( 'typescript' ) ) {
23
21
pkg . devDependencies [ 'babel-eslint' ] = '^10.0.3'
24
22
}
25
23
26
- if ( config === 'airbnb' ) {
24
+ switch ( config ) {
25
+ case 'airbnb' :
27
26
eslintConfig . extends . push ( '@vue/airbnb' )
28
27
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'
30
30
} )
31
- } else if ( config === 'standard' ) {
31
+ break
32
+ case 'standard' :
32
33
eslintConfig . extends . push ( '@vue/standard' )
33
34
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'
35
40
} )
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
+ )
38
49
Object . assign ( pkg . devDependencies , {
39
- '@vue/eslint-config-prettier' : '^5 .0.0' ,
50
+ '@vue/eslint-config-prettier' : '^6 .0.0' ,
40
51
'eslint-plugin-prettier' : '^3.1.1' ,
41
52
prettier : '^1.19.1'
42
53
} )
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 :
46
56
// default
47
57
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
+ }
48
73
}
49
74
50
75
const editorConfigTemplatePath = path . resolve ( __dirname , `./template/${ config } /_editorconfig` )
@@ -60,6 +85,10 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
60
85
}
61
86
}
62
87
88
+ if ( typeof lintOn === 'string' ) {
89
+ lintOn = lintOn . split ( ',' )
90
+ }
91
+
63
92
if ( ! lintOn . includes ( 'save' ) ) {
64
93
pkg . vue = {
65
94
lintOnSave : false // eslint-loader configured in runtime plugin
@@ -73,24 +102,13 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
73
102
pkg . gitHooks = {
74
103
'pre-commit' : 'lint-staged'
75
104
}
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' ]
84
107
}
85
108
}
86
109
87
110
api . extendPackage ( pkg )
88
111
89
- // typescript support
90
- if ( api . hasPlugin ( 'typescript' ) ) {
91
- applyTS ( api )
92
- }
93
-
94
112
// invoking only
95
113
if ( invoking ) {
96
114
if ( api . hasPlugin ( 'unit-mocha' ) ) {
@@ -130,7 +148,8 @@ module.exports.hooks = (api) => {
130
148
} )
131
149
}
132
150
133
- const applyTS = module . exports . applyTS = api => {
151
+ // exposed for the typescript plugin
152
+ module . exports . applyTS = api => {
134
153
api . extendPackage ( {
135
154
eslintConfig : {
136
155
extends : [ '@vue/typescript' ] ,
@@ -139,7 +158,9 @@ const applyTS = module.exports.applyTS = api => {
139
158
}
140
159
} ,
141
160
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'
143
164
}
144
165
} )
145
166
}
0 commit comments