eslintOptions.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. exports.config = (api, preset) => {
  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. return config
  40. }
  41. // __expression is a special flag that allows us to customize stringification
  42. // output when extracting configs into standalone files
  43. function makeJSOnlyValue (str) {
  44. const fn = () => {}
  45. fn.__expression = str
  46. return fn
  47. }
  48. const baseExtensions = ['.js', '.jsx', '.vue']
  49. exports.extensions = api => api.hasPlugin('typescript')
  50. ? baseExtensions.concat('.ts', '.tsx')
  51. : baseExtensions