eslintOptions.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. exports.config = (api, preset, rootOptions = {}) => {
  2. const config = {
  3. root: true,
  4. env: { node: true },
  5. extends: ['plugin:vue/essential'],
  6. parserOptions: {
  7. ecmaVersion: 2020
  8. },
  9. rules: {
  10. 'no-console': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'warn' : 'off'`),
  11. 'no-debugger': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'warn' : 'off'`)
  12. }
  13. }
  14. if (api.hasPlugin('babel') && !api.hasPlugin('typescript')) {
  15. config.parserOptions = {
  16. parser: 'babel-eslint'
  17. }
  18. }
  19. if (preset === 'airbnb') {
  20. config.extends.push('@vue/airbnb')
  21. } else if (preset === 'standard') {
  22. config.extends.push('@vue/standard')
  23. } else if (preset === 'prettier') {
  24. config.extends.push(...['eslint:recommended', '@vue/prettier'])
  25. } else {
  26. // default
  27. config.extends.push('eslint:recommended')
  28. }
  29. if (api.hasPlugin('typescript')) {
  30. // typically, typescript ruleset should be appended to the end of the `extends` array
  31. // but that is not the case for prettier, as there are conflicting rules
  32. if (preset === 'prettier') {
  33. config.extends.pop()
  34. config.extends.push(...['@vue/typescript/recommended', '@vue/prettier', '@vue/prettier/@typescript-eslint'])
  35. } else {
  36. config.extends.push('@vue/typescript/recommended')
  37. }
  38. }
  39. if (rootOptions.vueVersion === '3') {
  40. const updateConfig = cfg =>
  41. cfg.replace(
  42. /plugin:vue\/(essential|recommended|strongly-recommended)/gi,
  43. 'plugin:vue/vue3-$1'
  44. )
  45. config.extends = config.extends.map(updateConfig)
  46. }
  47. return config
  48. }
  49. // __expression is a special flag that allows us to customize stringification
  50. // output when extracting configs into standalone files
  51. function makeJSOnlyValue (str) {
  52. const fn = () => {}
  53. fn.__expression = str
  54. return fn
  55. }
  56. const baseExtensions = ['.js', '.jsx', '.vue']
  57. exports.extensions = api => api.hasPlugin('typescript')
  58. ? baseExtensions.concat('.ts', '.tsx')
  59. : baseExtensions