.eslintrc.js 6.7 KB

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