linter.js 2.0 KB

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