.eslintrc.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/tests/**/*',
  47. 'app/frontend/**/*.stories.ts',
  48. '.storybook/**/*',
  49. 'app/frontend/cypress/**/*',
  50. ],
  51. },
  52. ],
  53. // Adding typescript file types, because airbnb doesn't allow this by default.
  54. 'import/extensions': [
  55. 'error',
  56. 'ignorePackages',
  57. {
  58. js: 'never',
  59. mjs: 'never',
  60. jsx: 'never',
  61. ts: 'never',
  62. tsx: 'never',
  63. },
  64. ],
  65. 'import/prefer-default-export': 'off',
  66. // 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.
  67. /* 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). */
  68. 'no-undef': 'off',
  69. // We need to use the extended 'no-shadow' rule from typescript:
  70. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  71. 'no-shadow': 'off',
  72. '@typescript-eslint/no-shadow': 'off',
  73. '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
  74. '@typescript-eslint/naming-convention': [
  75. 'error',
  76. {
  77. selector: 'enumMember',
  78. format: ['StrictPascalCase'],
  79. },
  80. {
  81. selector: 'typeLike',
  82. format: ['PascalCase'],
  83. },
  84. ],
  85. 'vue/component-tags-order': [
  86. 'error',
  87. {
  88. order: ['script', 'template', 'style'],
  89. },
  90. ],
  91. 'vue/script-setup-uses-vars': 'error',
  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. // Enforce v-bind directive usage in short form as error instead of warning
  97. 'vue/v-bind-style': ['error', 'shorthand'],
  98. // Enforce v-on directive usage in short form as error instead of warning
  99. 'vue/v-on-style': ['error', 'shorthand'],
  100. // Enforce v-slot directive usage in short form as error instead of warning
  101. 'vue/v-slot-style': ['error', 'shorthand'],
  102. },
  103. overrides: [
  104. {
  105. files: ['*.js'],
  106. rules: {
  107. '@typescript-eslint/no-var-requires': 'off',
  108. },
  109. },
  110. {
  111. files: ['.storybook/config/*'],
  112. rules: {
  113. 'import/no-extraneous-dependencies': 'off',
  114. },
  115. },
  116. {
  117. files: [
  118. 'app/frontend/tests/**',
  119. 'app/frontend/**/*.spec.*',
  120. 'app/frontend/stories/**',
  121. 'app/frontend/cypress/**',
  122. 'app/frontend/**/*.stories.ts',
  123. '.eslint-plugin-zammad/**',
  124. '.eslintrc.js',
  125. ],
  126. rules: {
  127. 'zammad/zammad-detect-translatable-string': 'off',
  128. '@typescript-eslint/no-non-null-assertion': 'off',
  129. '@typescript-eslint/no-explicit-any': 'off',
  130. 'import/first': 'off',
  131. },
  132. },
  133. ],
  134. settings: {
  135. 'import/resolver': {
  136. alias: {
  137. map: [
  138. ['@', path.resolve(__dirname, './app/frontend')],
  139. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  140. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  141. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  142. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  143. ['@cy', path.resolve(__dirname, './.cypress')],
  144. [
  145. 'vitest',
  146. path.resolve(__dirname, 'node_modules/vitest/dist/index.mjs'),
  147. ],
  148. ],
  149. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  150. },
  151. node: {
  152. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  153. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  154. },
  155. },
  156. // Adding typescript file types, because airbnb doesn't allow this by default.
  157. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  158. },
  159. globals: {
  160. defineProps: 'readonly',
  161. defineEmits: 'readonly',
  162. defineExpose: 'readonly',
  163. withDefaults: 'readonly',
  164. },
  165. parser: 'vue-eslint-parser',
  166. parserOptions: {
  167. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  168. sourceType: 'module', // allow the use of imports statements
  169. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  170. },
  171. }