-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathlinter.js
80 lines (76 loc) · 2.01 KB
/
linter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module.exports = cli => {
const chalk = require('chalk')
const { hasGit } = require('@vue/cli-shared-utils')
cli.injectFeature({
name: 'Linter / Formatter',
value: 'linter',
short: 'Linter',
description: 'Check and enforce code quality with ESLint or Prettier',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint',
plugins: ['eslint'],
checked: true
})
cli.injectPrompt({
name: 'eslintConfig',
when: answers => answers.features.includes('linter'),
type: 'list',
message: 'Pick a linter / formatter config:',
description: 'Checking code errors and enforcing an homogeoneous code style is recommended.',
choices: answers => [
{
name: 'ESLint with error prevention only',
value: 'base',
short: 'Basic'
},
{
name: 'ESLint + Airbnb config',
value: 'airbnb',
short: 'Airbnb'
},
{
name: 'ESLint + Standard config',
value: 'standard',
short: 'Standard'
},
{
name: 'ESLint + Prettier',
value: 'prettier',
short: 'Prettier'
},
...(
answers.features.includes('ts')
? [{
name: `TSLint (deprecated)`,
value: 'tslint',
short: 'TSLint'
}]
: []
)
]
})
cli.injectPrompt({
name: 'lintOn',
message: 'Pick additional lint features:',
when: answers => answers.features.includes('linter'),
type: 'checkbox',
choices: [
{
name: 'Lint on save',
value: 'save',
checked: true
},
{
name: 'Lint and fix on commit' + (hasGit() ? '' : chalk.red(' (requires Git)')),
value: 'commit'
}
]
})
cli.onPromptComplete((answers, options) => {
if (answers.features.includes('linter') && answers.eslintConfig !== 'tslint') {
options.plugins['@vue/cli-plugin-eslint'] = {
config: answers.eslintConfig,
lintOn: answers.lintOn
}
}
})
}