.eslintrc.js 7.8 KB

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