.eslintrc.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. 'no-promise-executor-return': 'off',
  103. },
  104. overrides: [
  105. {
  106. files: ['*.js'],
  107. rules: {
  108. '@typescript-eslint/no-var-requires': 'off',
  109. },
  110. },
  111. {
  112. files: ['.storybook/config/*'],
  113. rules: {
  114. 'import/no-extraneous-dependencies': 'off',
  115. },
  116. },
  117. {
  118. files: [
  119. 'app/frontend/tests/**',
  120. 'app/frontend/**/__tests__/**',
  121. 'app/frontend/**/*.spec.*',
  122. 'app/frontend/stories/**',
  123. 'app/frontend/cypress/**',
  124. 'app/frontend/**/*.stories.ts',
  125. '.eslint-plugin-zammad/**',
  126. '.eslintrc.js',
  127. ],
  128. rules: {
  129. 'zammad/zammad-detect-translatable-string': 'off',
  130. '@typescript-eslint/no-non-null-assertion': 'off',
  131. '@typescript-eslint/no-explicit-any': 'off',
  132. 'import/first': 'off',
  133. },
  134. },
  135. // rules that require type information
  136. {
  137. files: ['*.ts', '*.tsx', '*.vue'],
  138. rules: {
  139. '@typescript-eslint/consistent-type-imports': [
  140. 'error',
  141. { prefer: 'type-imports', disallowTypeAnnotations: false },
  142. ],
  143. '@typescript-eslint/consistent-type-exports': 'error',
  144. },
  145. parserOptions: {
  146. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  147. },
  148. },
  149. ],
  150. settings: {
  151. 'import/resolver': {
  152. alias: {
  153. map: [
  154. ['@', path.resolve(__dirname, './app/frontend')],
  155. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  156. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  157. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  158. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  159. ['@cy', path.resolve(__dirname, './.cypress')],
  160. [
  161. 'vitest',
  162. path.resolve(__dirname, 'node_modules/vitest/dist/index.mjs'),
  163. ],
  164. ],
  165. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  166. },
  167. node: {
  168. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  169. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  170. },
  171. },
  172. // Adding typescript file types, because airbnb doesn't allow this by default.
  173. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  174. },
  175. globals: {
  176. defineProps: 'readonly',
  177. defineEmits: 'readonly',
  178. defineExpose: 'readonly',
  179. withDefaults: 'readonly',
  180. },
  181. parser: 'vue-eslint-parser',
  182. parserOptions: {
  183. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  184. sourceType: 'module', // allow the use of imports statements
  185. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  186. },
  187. }