@@ -2,49 +2,74 @@ const fs = require('fs')
22const  path  =  require ( 'path' ) 
33
44module . 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.1.2 ' 
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.1' , 
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.1.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} 
0 commit comments