.eslintrc.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. '@typescript-eslint/naming-convention': [
  74. 'error',
  75. {
  76. selector: 'enumMember',
  77. format: ['StrictPascalCase'],
  78. },
  79. {
  80. selector: 'typeLike',
  81. format: ['PascalCase'],
  82. },
  83. ],
  84. 'vue/component-tags-order': [
  85. 'error',
  86. {
  87. order: ['script', 'template', 'style'],
  88. },
  89. ],
  90. 'vue/script-setup-uses-vars': 'error',
  91. // Don't require a default value for the props.
  92. 'vue/require-default-prop': 'off',
  93. // Don't require multi word component names.
  94. 'vue/multi-word-component-names': 'off',
  95. // Enforce v-bind directive usage in short form as error instead of warning
  96. 'vue/v-bind-style': ['error', 'shorthand'],
  97. // Enforce v-on directive usage in short form as error instead of warning
  98. 'vue/v-on-style': ['error', 'shorthand'],
  99. // Enforce v-slot directive usage in short form as error instead of warning
  100. 'vue/v-slot-style': ['error', 'shorthand'],
  101. },
  102. overrides: [
  103. {
  104. files: ['*.js'],
  105. rules: {
  106. '@typescript-eslint/no-var-requires': 'off',
  107. },
  108. },
  109. {
  110. files: ['.storybook/config/*'],
  111. rules: {
  112. 'import/no-extraneous-dependencies': 'off',
  113. },
  114. },
  115. {
  116. files: [
  117. 'app/frontend/tests/**',
  118. 'app/frontend/**/*.spec.*',
  119. 'app/frontend/stories/**',
  120. 'app/frontend/cypress/**',
  121. 'app/frontend/**/*.stories.ts',
  122. '.eslint-plugin-zammad/**',
  123. '.eslintrc.js',
  124. ],
  125. rules: {
  126. 'zammad/zammad-detect-translatable-string': 'off',
  127. '@typescript-eslint/no-non-null-assertion': 'off',
  128. '@typescript-eslint/no-explicit-any': 'off',
  129. 'import/first': 'off',
  130. },
  131. },
  132. ],
  133. settings: {
  134. 'import/resolver': {
  135. alias: {
  136. map: [
  137. ['@', path.resolve(__dirname, './app/frontend')],
  138. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  139. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  140. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  141. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  142. ['@cy', path.resolve(__dirname, './.cypress')],
  143. ],
  144. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  145. },
  146. node: {
  147. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  148. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  149. },
  150. },
  151. // Adding typescript file types, because airbnb doesn't allow this by default.
  152. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  153. },
  154. globals: {
  155. defineProps: 'readonly',
  156. defineEmits: 'readonly',
  157. defineExpose: 'readonly',
  158. withDefaults: 'readonly',
  159. },
  160. parser: 'vue-eslint-parser',
  161. parserOptions: {
  162. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  163. sourceType: 'module', // allow the use of imports statements
  164. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  165. },
  166. }