.eslintrc.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. 'import/no-extraneous-dependencies': 'off',
  49. 'import/extensions': ['error', 'ignorePackages'],
  50. 'import/prefer-default-export': 'off',
  51. // 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.
  52. /* 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). */
  53. 'no-undef': 'off',
  54. // We need to use the extended 'no-shadow' rule from typescript:
  55. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  56. 'no-shadow': 'off',
  57. '@typescript-eslint/no-shadow': 'off',
  58. '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
  59. '@typescript-eslint/naming-convention': [
  60. 'error',
  61. {
  62. selector: 'enumMember',
  63. format: ['StrictPascalCase'],
  64. },
  65. {
  66. selector: 'typeLike',
  67. format: ['PascalCase'],
  68. },
  69. ],
  70. 'vue/component-tags-order': [
  71. 'error',
  72. {
  73. order: ['script', 'template', 'style'],
  74. },
  75. ],
  76. 'vue/script-setup-uses-vars': 'error',
  77. // Don't require a default value for the props.
  78. 'vue/require-default-prop': 'off',
  79. // Don't require multi word component names.
  80. 'vue/multi-word-component-names': 'off',
  81. // Enforce v-bind directive usage in short form as error instead of warning.
  82. 'vue/v-bind-style': ['error', 'shorthand'],
  83. // Enforce v-on directive usage in short form as error instead of warning.
  84. 'vue/v-on-style': ['error', 'shorthand'],
  85. // Enforce v-slot directive usage in short form as error instead of warning.
  86. 'vue/v-slot-style': ['error', 'shorthand'],
  87. 'no-promise-executor-return': 'off',
  88. // We have quite a lot of constant strings in our code.
  89. 'sonarjs/no-duplicate-string': 'off',
  90. // It also supresses local function returns.
  91. 'sonarjs/prefer-immediate-return': 'off',
  92. 'sonarjs/prefer-single-boolean-return': 'off',
  93. },
  94. overrides: [
  95. {
  96. files: ['*.js'],
  97. rules: {
  98. '@typescript-eslint/no-var-requires': 'off',
  99. 'security/detect-object-injection': 'off',
  100. 'security/detect-non-literal-fs-filename': 'off',
  101. 'security/detect-non-literal-regexp': 'off',
  102. },
  103. },
  104. {
  105. files: [
  106. 'app/frontend/tests/**',
  107. 'app/frontend/**/__tests__/**',
  108. 'app/frontend/**/*.spec.*',
  109. 'app/frontend/stories/**',
  110. 'app/frontend/cypress/**',
  111. 'app/frontend/**/*.stories.ts',
  112. 'app/frontend/**/*.story.vue',
  113. '.eslint-plugin-zammad/**',
  114. '.eslintrc.js',
  115. ],
  116. rules: {
  117. 'zammad/zammad-tailwind-ltr': 'off',
  118. 'zammad/zammad-detect-translatable-string': 'off',
  119. '@typescript-eslint/no-non-null-assertion': 'off',
  120. '@typescript-eslint/no-explicit-any': 'off',
  121. 'import/first': 'off',
  122. },
  123. },
  124. // rules that require type information
  125. {
  126. files: ['*.ts', '*.tsx', '*.vue'],
  127. rules: {
  128. // handled by typescript itself with "verbatimModuleSyntax"
  129. '@typescript-eslint/consistent-type-imports': 'off',
  130. '@typescript-eslint/consistent-type-exports': 'error',
  131. 'security/detect-object-injection': 'off',
  132. 'security/detect-non-literal-fs-filename': 'off',
  133. 'security/detect-non-literal-regexp': 'off',
  134. },
  135. parserOptions: {
  136. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  137. },
  138. },
  139. ],
  140. settings: {
  141. 'import/core-modules': ['virtual:pwa-register'],
  142. 'import/parsers': {
  143. '@typescript-eslint/parser': ['.ts', '.tsx'],
  144. },
  145. 'import/resolver': {
  146. typescript: {
  147. alwaysTryTypes: true,
  148. },
  149. alias: {
  150. map: [
  151. [
  152. 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  153. path.resolve(
  154. __dirname,
  155. 'node_modules/vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  156. ),
  157. ],
  158. ],
  159. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  160. },
  161. node: {
  162. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  163. },
  164. },
  165. // Adding typescript file types, because airbnb doesn't allow this by default.
  166. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  167. },
  168. globals: {
  169. defineProps: 'readonly',
  170. defineEmits: 'readonly',
  171. defineExpose: 'readonly',
  172. withDefaults: 'readonly',
  173. },
  174. parser: 'vue-eslint-parser',
  175. parserOptions: {
  176. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  177. sourceType: 'module', // allow the use of imports statements
  178. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  179. },
  180. }