.eslintrc.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // Copyright (C) 2012-2023 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: [
  10. '@typescript-eslint',
  11. 'vue',
  12. 'prettier',
  13. 'sonarjs',
  14. 'security',
  15. 'zammad',
  16. ],
  17. extends: [
  18. 'airbnb-base',
  19. 'plugin:vue/vue3-recommended',
  20. 'plugin:@typescript-eslint/eslint-recommended',
  21. 'plugin:@typescript-eslint/recommended',
  22. 'plugin:prettier/recommended',
  23. '@vue/prettier',
  24. '@vue/typescript/recommended',
  25. 'prettier',
  26. 'plugin:sonarjs/recommended',
  27. 'plugin:security/recommended',
  28. ],
  29. rules: {
  30. 'zammad/zammad-copyright': 'error',
  31. 'zammad/zammad-detect-translatable-string': 'error',
  32. 'zammad/zammad-tailwind-ltr': 'error',
  33. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  34. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  35. 'consistent-return': 'off', // allow implicit return
  36. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  37. 'no-restricted-syntax': [
  38. 'error',
  39. 'ForInStatement',
  40. // "ForOfStatement", // We want to allow this
  41. 'LabeledStatement',
  42. 'WithStatement',
  43. ],
  44. 'no-underscore-dangle': 'off',
  45. 'no-param-reassign': 'off',
  46. 'func-style': ['error', 'expression'],
  47. 'no-restricted-imports': 'off',
  48. // Disable the following rule, because it's not relevant for the tool chain and test envoirment.
  49. 'import/no-extraneous-dependencies': [
  50. 'error',
  51. {
  52. devDependencies: [
  53. 'histoire.config.ts',
  54. 'tailwind.config.js',
  55. 'vite.config.*',
  56. 'app/frontend/build/**',
  57. 'app/frontend/**/*.spec.*',
  58. 'app/frontend/**/__tests__/**/*',
  59. 'app/frontend/tests/**/*',
  60. 'app/frontend/**/*.stories.ts',
  61. 'app/frontend/**/*.story.vue',
  62. 'app/frontend/**/*.story.vue',
  63. 'app/frontend/stories/**/*.ts',
  64. 'app/frontend/cypress/**/*',
  65. ],
  66. },
  67. ],
  68. 'import/extensions': ['error', 'ignorePackages'],
  69. 'import/prefer-default-export': 'off',
  70. // 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.
  71. /* 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). */
  72. 'no-undef': 'off',
  73. // We need to use the extended 'no-shadow' rule from typescript:
  74. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  75. 'no-shadow': 'off',
  76. '@typescript-eslint/no-shadow': 'off',
  77. '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
  78. '@typescript-eslint/naming-convention': [
  79. 'error',
  80. {
  81. selector: 'enumMember',
  82. format: ['StrictPascalCase'],
  83. },
  84. {
  85. selector: 'typeLike',
  86. format: ['PascalCase'],
  87. },
  88. ],
  89. 'vue/component-tags-order': [
  90. 'error',
  91. {
  92. order: ['script', 'template', 'style'],
  93. },
  94. ],
  95. 'vue/script-setup-uses-vars': 'error',
  96. // Don't require a default value for the props.
  97. 'vue/require-default-prop': 'off',
  98. // Don't require multi word component names.
  99. 'vue/multi-word-component-names': 'off',
  100. // Enforce v-bind directive usage in short form as error instead of warning.
  101. 'vue/v-bind-style': ['error', 'shorthand'],
  102. // Enforce v-on directive usage in short form as error instead of warning.
  103. 'vue/v-on-style': ['error', 'shorthand'],
  104. // Enforce v-slot directive usage in short form as error instead of warning.
  105. 'vue/v-slot-style': ['error', 'shorthand'],
  106. 'no-promise-executor-return': 'off',
  107. // We have quite a lot of constant strings in our code.
  108. 'sonarjs/no-duplicate-string': 'off',
  109. // It also supresses local function returns.
  110. 'sonarjs/prefer-immediate-return': 'off',
  111. 'sonarjs/prefer-single-boolean-return': 'off',
  112. },
  113. overrides: [
  114. {
  115. files: ['*.js'],
  116. rules: {
  117. '@typescript-eslint/no-var-requires': 'off',
  118. 'security/detect-object-injection': 'off',
  119. 'security/detect-non-literal-fs-filename': 'off',
  120. 'security/detect-non-literal-regexp': 'off',
  121. },
  122. },
  123. {
  124. files: [
  125. 'app/frontend/tests/**',
  126. 'app/frontend/**/__tests__/**',
  127. 'app/frontend/**/*.spec.*',
  128. 'app/frontend/stories/**',
  129. 'app/frontend/cypress/**',
  130. 'app/frontend/**/*.stories.ts',
  131. 'app/frontend/**/*.story.vue',
  132. '.eslint-plugin-zammad/**',
  133. '.eslintrc.js',
  134. ],
  135. rules: {
  136. 'zammad/zammad-tailwind-ltr': 'off',
  137. 'zammad/zammad-detect-translatable-string': 'off',
  138. '@typescript-eslint/no-non-null-assertion': 'off',
  139. '@typescript-eslint/no-explicit-any': 'off',
  140. 'import/first': 'off',
  141. },
  142. },
  143. // rules that require type information
  144. {
  145. files: ['*.ts', '*.tsx', '*.vue'],
  146. rules: {
  147. // handled by typescript itself with "verbatimModuleSyntax"
  148. '@typescript-eslint/consistent-type-imports': 'off',
  149. '@typescript-eslint/consistent-type-exports': 'error',
  150. 'security/detect-object-injection': 'off',
  151. 'security/detect-non-literal-fs-filename': 'off',
  152. 'security/detect-non-literal-regexp': 'off',
  153. },
  154. parserOptions: {
  155. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  156. },
  157. },
  158. ],
  159. settings: {
  160. 'import/core-modules': ['virtual:pwa-register'],
  161. 'import/parsers': {
  162. '@typescript-eslint/parser': ['.ts', '.tsx'],
  163. },
  164. 'import/resolver': {
  165. typescript: {
  166. alwaysTryTypes: true,
  167. },
  168. alias: {
  169. map: [
  170. [
  171. 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  172. path.resolve(
  173. __dirname,
  174. 'node_modules/vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  175. ),
  176. ],
  177. ],
  178. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  179. },
  180. node: {
  181. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  182. },
  183. },
  184. // Adding typescript file types, because airbnb doesn't allow this by default.
  185. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  186. },
  187. globals: {
  188. defineProps: 'readonly',
  189. defineEmits: 'readonly',
  190. defineExpose: 'readonly',
  191. withDefaults: 'readonly',
  192. },
  193. parser: 'vue-eslint-parser',
  194. parserOptions: {
  195. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  196. sourceType: 'module', // allow the use of imports statements
  197. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  198. },
  199. }