.eslintrc.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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: ['script', 'template', '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/build/**',
  61. 'app/frontend/**/*.spec.*',
  62. 'app/frontend/tests/**/*',
  63. 'app/frontend/**/*.stories.ts',
  64. '.storybook/**/*',
  65. ],
  66. },
  67. ],
  68. // Adding typescript file types, because airbnb doesn't allow this by default.
  69. 'import/extensions': [
  70. 'error',
  71. 'ignorePackages',
  72. {
  73. js: 'never',
  74. mjs: 'never',
  75. jsx: 'never',
  76. ts: 'never',
  77. tsx: 'never',
  78. },
  79. ],
  80. /* 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). */
  81. 'no-undef': 'off',
  82. // We need to use the extended 'no-shadow' rule from typescript:
  83. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  84. 'no-shadow': 'off',
  85. '@typescript-eslint/no-shadow': 'off',
  86. // Enforce v-bind directive usage in long form.
  87. 'vue/v-bind-style': ['error', 'longform'],
  88. // Enforce v-on directive usage in long form.
  89. 'vue/v-on-style': ['error', 'longform'],
  90. // Enforce v-slot directive usage in long form.
  91. 'vue/v-slot-style': ['error', 'longform'],
  92. // Don't require a default value for the props.
  93. 'vue/require-default-prop': 'off',
  94. // Don't require multi word component names.
  95. 'vue/multi-word-component-names': 'off',
  96. },
  97. overrides: [
  98. {
  99. files: ['*.js'],
  100. rules: {
  101. '@typescript-eslint/no-var-requires': 'off',
  102. },
  103. },
  104. {
  105. files: ['.storybook/config/*'],
  106. rules: {
  107. 'import/no-extraneous-dependencies': 'off',
  108. },
  109. },
  110. {
  111. files: [
  112. 'app/frontend/tests/**',
  113. 'app/frontend/**/*.spec.*',
  114. 'app/frontend/stories/**',
  115. 'app/frontend/**/*.stories.ts',
  116. '.eslint-plugin-zammad/**',
  117. '.eslintrc.js',
  118. ],
  119. rules: {
  120. 'zammad/zammad-detect-translatable-string': 'off',
  121. '@typescript-eslint/no-non-null-assertion': 'off',
  122. },
  123. },
  124. ],
  125. settings: {
  126. 'import/resolver': {
  127. alias: {
  128. map: [
  129. ['@', path.resolve(__dirname, './app/frontend')],
  130. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  131. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  132. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  133. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  134. ],
  135. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  136. },
  137. node: {
  138. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  139. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  140. },
  141. },
  142. // Adding typescript file types, because airbnb doesn't allow this by default.
  143. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  144. },
  145. globals: {
  146. defineProps: 'readonly',
  147. defineEmits: 'readonly',
  148. defineExpose: 'readonly',
  149. withDefaults: 'readonly',
  150. },
  151. parser: 'vue-eslint-parser',
  152. parserOptions: {
  153. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  154. sourceType: 'module', // allow the use of imports statements
  155. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  156. },
  157. }