.eslintrc.js 7.8 KB

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