Skip to content

Instantly share code, notes, and snippets.

@Akryum
Last active March 24, 2018 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akryum/e303a8294f25096e70d741f4b6c66e15 to your computer and use it in GitHub Desktop.
Save Akryum/e303a8294f25096e70d741f4b6c66e15 to your computer and use it in GitHub Desktop.
@vue/cli-ui plugin API
// @vue/cli-plugin-eslint/ui.js
module.exports = api => {
// Config file
api.describeConfig({
name: 'ESLint configuration',
description: 'Error checking & Code quality',
link: 'https://eslint.org',
files: {
json: ['eslintrc', 'eslintrc.json'],
js: ['eslintrc.js'],
package: 'eslintConfig'
},
onRead: ({ data }) => {
return {
prompts: [
{
name: 'rules.commaDangle',
type: 'list',
message: 'Trailing commas',
description: 'Enforce or disallow trailing commas at the end of the lines',
link: 'https://eslint.org/docs/rules/comma-dangle',
choices: [
{
name: 'Off',
value: 'off'
},
{
name: 'Never',
value: JSON.stringify(['error', 'never'])
},
{
name: 'Always',
value: JSON.stringify(['error', 'always'])
},
{
name: 'Always on multiline',
value: JSON.stringify(['error', 'always-multiline'])
},
{
name: 'Only on multiline',
value: JSON.stringify(['error', 'only-multiline'])
}
],
value: JSON.stringify(data.rules['comma-dangle'] || ['error', 'never'])
}
]
}
},
onWrite: ({ file, answers }) => {
file.assignData({
'rules.comma-dangle': answers.rules.commaDangle
})
}
})
// Tasks
api.describeTask({
match: /vue-cli-service lint/,
description: 'Lints and fixes files',
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint#injected-commands',
prompts: [
{
name: 'noFix',
type: 'confirm',
default: false,
description: 'Do not fix errors'
}
],
onRun: ({ answers, args }) => {
if (answers.noFix) {
args.push('no-fix')
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment