.eslintrc.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  24. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  25. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  26. 'no-restricted-syntax': [
  27. 'error',
  28. 'ForInStatement',
  29. // "ForOfStatement", // We want to allow this
  30. 'LabeledStatement',
  31. 'WithStatement',
  32. ],
  33. 'no-param-reassign': 'off',
  34. 'func-style': ['error', 'expression'],
  35. 'no-restricted-imports': 'off',
  36. // Disable the following rule, because it's not relevant for the tool chain and test envoirment.
  37. 'import/no-extraneous-dependencies': [
  38. 'error',
  39. {
  40. devDependencies: [
  41. 'tailwind.config.js',
  42. 'vite.config.ts',
  43. 'app/frontend/build/**',
  44. 'app/frontend/**/*.spec.*',
  45. 'app/frontend/tests/**/*',
  46. 'app/frontend/**/*.stories.ts',
  47. '.storybook/**/*',
  48. 'app/frontend/cypress/**/*',
  49. ],
  50. },
  51. ],
  52. // Adding typescript file types, because airbnb doesn't allow this by default.
  53. 'import/extensions': [
  54. 'error',
  55. 'ignorePackages',
  56. {
  57. js: 'never',
  58. mjs: 'never',
  59. jsx: 'never',
  60. ts: 'never',
  61. tsx: 'never',
  62. },
  63. ],
  64. 'import/prefer-default-export': 'off',
  65. // TODO: Add import rule to not allow that "app/**/modules/**" can import from each other and also add a rule that apps/** can not import from other apps.
  66. /* 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). */
  67. 'no-undef': 'off',
  68. // We need to use the extended 'no-shadow' rule from typescript:
  69. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  70. 'no-shadow': 'off',
  71. '@typescript-eslint/no-shadow': 'off',
  72. '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
  73. 'vue/component-tags-order': [
  74. 'error',
  75. {
  76. order: ['script', 'template', 'style'],
  77. },
  78. ],
  79. 'vue/script-setup-uses-vars': 'error',
  80. // Don't require a default value for the props.
  81. 'vue/require-default-prop': 'off',
  82. // Don't require multi word component names.
  83. 'vue/multi-word-component-names': 'off',
  84. // Enforce v-bind directive usage in short form as error instead of warning
  85. 'vue/v-bind-style': ['error', 'shorthand'],
  86. // Enforce v-on directive usage in short form as error instead of warning
  87. 'vue/v-on-style': ['error', 'shorthand'],
  88. // Enforce v-slot directive usage in short form as error instead of warning
  89. 'vue/v-slot-style': ['error', 'shorthand'],
  90. },
  91. overrides: [
  92. {
  93. files: ['*.js'],
  94. rules: {
  95. '@typescript-eslint/no-var-requires': 'off',
  96. },
  97. },
  98. {
  99. files: ['.storybook/config/*'],
  100. rules: {
  101. 'import/no-extraneous-dependencies': 'off',
  102. },
  103. },
  104. {
  105. files: [
  106. 'app/frontend/tests/**',
  107. 'app/frontend/**/*.spec.*',
  108. 'app/frontend/stories/**',
  109. 'app/frontend/cypress/**',
  110. 'app/frontend/**/*.stories.ts',
  111. '.eslint-plugin-zammad/**',
  112. '.eslintrc.js',
  113. ],
  114. rules: {
  115. 'zammad/zammad-detect-translatable-string': 'off',
  116. '@typescript-eslint/no-non-null-assertion': 'off',
  117. '@typescript-eslint/no-explicit-any': 'off',
  118. 'import/first': 'off',
  119. },
  120. },
  121. ],
  122. settings: {
  123. 'import/resolver': {
  124. alias: {
  125. map: [
  126. ['@', path.resolve(__dirname, './app/frontend')],
  127. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  128. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  129. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  130. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  131. ['@cy', path.resolve(__dirname, './.cypress')],
  132. ],
  133. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  134. },
  135. node: {
  136. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  137. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  138. },
  139. },
  140. // Adding typescript file types, because airbnb doesn't allow this by default.
  141. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  142. },
  143. globals: {
  144. defineProps: 'readonly',
  145. defineEmits: 'readonly',
  146. defineExpose: 'readonly',
  147. withDefaults: 'readonly',
  148. },
  149. parser: 'vue-eslint-parser',
  150. parserOptions: {
  151. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  152. sourceType: 'module', // allow the use of imports statements
  153. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  154. },
  155. }