.eslintrc.js 7.7 KB

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