.eslintrc.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. const path = require('path')
  3. module.exports = {
  4. root: true,
  5. env: {
  6. browser: true,
  7. node: true,
  8. },
  9. plugins: ['@typescript-eslint', 'vue', 'prettier', 'zammad'],
  10. extends: [
  11. 'airbnb-base',
  12. 'plugin:vue/vue3-recommended',
  13. 'plugin:@typescript-eslint/eslint-recommended',
  14. 'plugin:@typescript-eslint/recommended',
  15. 'plugin:prettier/recommended',
  16. '@vue/prettier',
  17. '@vue/typescript/recommended',
  18. 'prettier',
  19. ],
  20. rules: {
  21. 'zammad/zammad-copyright': 'error',
  22. 'zammad/zammad-detect-translatable-string': 'error',
  23. 'vue/script-setup-uses-vars': 'error',
  24. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  25. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  26. 'vue/component-tags-order': [
  27. 'error',
  28. {
  29. order: ['template', 'script', 'style'],
  30. },
  31. ],
  32. // Not allow the usage of relative imports, because we want always use the path aliases.
  33. 'no-restricted-imports': [
  34. 'error',
  35. {
  36. patterns: [
  37. {
  38. group: ['.*'],
  39. message:
  40. 'Usage of relative imports is not allowed. Always path aliases should be used.',
  41. },
  42. ],
  43. },
  44. ],
  45. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  46. 'no-restricted-syntax': [
  47. 'error',
  48. 'ForInStatement',
  49. // "ForOfStatement", // We want to allow this
  50. 'LabeledStatement',
  51. 'WithStatement',
  52. ],
  53. // Disable the following rule, because it's not relevant for the tool chain and test envoirment.
  54. 'import/no-extraneous-dependencies': [
  55. 'error',
  56. {
  57. devDependencies: [
  58. 'tailwind.config.js',
  59. 'vite.config.ts',
  60. 'app/frontend/tests/**/*',
  61. 'app/frontend/stories/**/*',
  62. '.storybook/**/*',
  63. ],
  64. },
  65. ],
  66. // Adding typescript file types, because airbnb doesn't allow this by default.
  67. 'import/extensions': [
  68. 'error',
  69. 'ignorePackages',
  70. {
  71. js: 'never',
  72. mjs: 'never',
  73. jsx: 'never',
  74. ts: 'never',
  75. tsx: 'never',
  76. },
  77. ],
  78. /* We strongly recommend that you do not use the no-undef lint rule on TypeScript projects. The checks it provides are already provided by TypeScript without the need for configuration - TypeScript just does this significantly better (Source: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors). */
  79. 'no-undef': 'off',
  80. // We need to use the extended 'no-shadow' rule from typescript:
  81. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  82. 'no-shadow': 'off',
  83. '@typescript-eslint/no-shadow': 'off',
  84. // Enforce v-bind directive usage in long form.
  85. 'vue/v-bind-style': ['error', 'longform'],
  86. // Enforce v-on directive usage in long form.
  87. 'vue/v-on-style': ['error', 'longform'],
  88. // Enforce v-slot directive usage in long form.
  89. 'vue/v-slot-style': ['error', 'longform'],
  90. // Don't require a default value for the props.
  91. 'vue/require-default-prop': 'off',
  92. // Don't require multi word component names.
  93. 'vue/multi-word-component-names': 'off',
  94. },
  95. overrides: [
  96. {
  97. files: ['*.js'],
  98. rules: {
  99. '@typescript-eslint/no-var-requires': 'off',
  100. },
  101. },
  102. {
  103. files: ['.storybook/config/*'],
  104. rules: {
  105. 'import/no-extraneous-dependencies': 'off',
  106. },
  107. },
  108. {
  109. files: [
  110. 'app/frontend/tests/**',
  111. 'app/frontend/stories/**',
  112. '.eslint-plugin-zammad/**',
  113. '.eslintrc.js',
  114. ],
  115. rules: {
  116. 'zammad/zammad-detect-translatable-string': 'off',
  117. },
  118. },
  119. ],
  120. settings: {
  121. 'import/resolver': {
  122. alias: {
  123. map: [
  124. ['@', path.resolve(__dirname, './app/frontend')],
  125. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  126. ['@common', path.resolve(__dirname, './app/frontend/common')],
  127. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  128. ],
  129. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  130. },
  131. node: {
  132. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  133. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  134. },
  135. },
  136. // Adding typescript file types, because airbnb doesn't allow this by default.
  137. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  138. },
  139. globals: {
  140. defineProps: 'readonly',
  141. defineEmits: 'readonly',
  142. defineExpose: 'readonly',
  143. withDefaults: 'readonly',
  144. },
  145. parser: 'vue-eslint-parser',
  146. parserOptions: {
  147. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  148. sourceType: 'module', // allow the use of imports statements
  149. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  150. },
  151. }