.eslintrc.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. const path = require('path')
  3. const fs = require('fs')
  4. const mobilePagesDir = path.resolve(__dirname, 'app/frontend/apps/mobile/pages')
  5. const mobilePagesFolder = fs.readdirSync(mobilePagesDir)
  6. const desktopPagesDir = path.resolve(
  7. __dirname,
  8. 'app/frontend/apps/desktop/pages',
  9. )
  10. const desktopPagesFolder = fs.readdirSync(desktopPagesDir)
  11. module.exports = {
  12. root: true,
  13. env: {
  14. browser: true,
  15. node: true,
  16. },
  17. plugins: [
  18. '@typescript-eslint',
  19. 'vue',
  20. 'prettier',
  21. 'sonarjs',
  22. 'security',
  23. 'zammad',
  24. ],
  25. extends: [
  26. 'airbnb-base',
  27. 'plugin:vue/vue3-recommended',
  28. 'plugin:@typescript-eslint/eslint-recommended',
  29. 'plugin:@typescript-eslint/recommended',
  30. 'plugin:prettier/recommended',
  31. '@vue/prettier',
  32. '@vue/typescript/recommended',
  33. 'prettier',
  34. 'plugin:sonarjs/recommended',
  35. 'plugin:security/recommended-legacy',
  36. ],
  37. rules: {
  38. 'zammad/zammad-copyright': 'error',
  39. 'zammad/zammad-detect-translatable-string': 'error',
  40. 'zammad/zammad-tailwind-ltr': 'error',
  41. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  42. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  43. 'consistent-return': 'off', // allow implicit return
  44. 'class-methods-use-this': 'off',
  45. 'prefer-destructuring': [
  46. 'error',
  47. {
  48. VariableDeclarator: {
  49. array: false,
  50. object: true,
  51. },
  52. AssignmentExpression: {
  53. array: false,
  54. object: true,
  55. },
  56. },
  57. {
  58. enforceForRenamedProperties: false,
  59. },
  60. ],
  61. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  62. 'no-restricted-syntax': [
  63. 'error',
  64. 'ForInStatement',
  65. // "ForOfStatement", // We want to allow this
  66. 'LabeledStatement',
  67. 'WithStatement',
  68. ],
  69. 'no-underscore-dangle': 'off',
  70. 'no-param-reassign': 'off',
  71. 'func-style': ['error', 'expression'],
  72. 'no-restricted-imports': 'off',
  73. 'import/no-extraneous-dependencies': 'off',
  74. 'import/extensions': ['error', 'ignorePackages'],
  75. 'import/prefer-default-export': 'off',
  76. 'import/no-restricted-paths': [
  77. 'error',
  78. {
  79. zones: [
  80. // restrict import inside shared context from app context
  81. {
  82. target: './app/frontend/shared',
  83. from: './app/frontend/apps',
  84. },
  85. {
  86. target: './app/frontend/apps/desktop',
  87. from: './app/frontend/apps/mobile',
  88. },
  89. {
  90. target: './app/frontend/apps/mobile',
  91. from: './app/frontend/apps/desktop',
  92. },
  93. // restrict imports between different pages folder
  94. ...mobilePagesFolder.map((page) => {
  95. return {
  96. target: `./app/frontend/apps/mobile/pages/!(${page})/**/*`,
  97. from: `./app/frontend/apps/mobile/pages/${page}/**/*`,
  98. }
  99. }),
  100. ...desktopPagesFolder.map((page) => {
  101. return {
  102. target: `./app/frontend/apps/desktop/pages/!(${page})/**/*`,
  103. from: `./app/frontend/apps/desktop/pages/${page}/**/*`,
  104. }
  105. }),
  106. ],
  107. },
  108. ],
  109. /* 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). */
  110. 'no-undef': 'off',
  111. // We need to use the extended 'no-shadow' rule from typescript:
  112. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  113. 'no-shadow': 'off',
  114. '@typescript-eslint/no-shadow': 'off',
  115. '@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
  116. '@typescript-eslint/naming-convention': [
  117. 'error',
  118. {
  119. selector: 'enumMember',
  120. format: ['StrictPascalCase'],
  121. },
  122. {
  123. selector: 'typeLike',
  124. format: ['PascalCase'],
  125. },
  126. ],
  127. 'vue/component-tags-order': [
  128. 'error',
  129. {
  130. order: ['script', 'template', 'style'],
  131. },
  132. ],
  133. // Enforce Vue v3.3+ tuple syntax for defineEmits.
  134. 'vue/define-emits-declaration': ['error', 'type-literal'],
  135. 'vue/script-setup-uses-vars': 'error',
  136. // Don't require a default value for the props.
  137. 'vue/require-default-prop': 'off',
  138. // Don't require multi word component names.
  139. 'vue/multi-word-component-names': 'off',
  140. // Enforce v-bind directive usage in short form as error instead of warning.
  141. 'vue/v-bind-style': ['error', 'shorthand'],
  142. // Enforce v-on directive usage in short form as error instead of warning.
  143. 'vue/v-on-style': ['error', 'shorthand'],
  144. // Enforce v-slot directive usage in short form as error instead of warning.
  145. 'vue/v-slot-style': ['error', 'shorthand'],
  146. 'no-promise-executor-return': 'off',
  147. // We have quite a lot of constant strings in our code.
  148. 'sonarjs/no-duplicate-string': 'off',
  149. // It also supresses local function returns.
  150. 'sonarjs/prefer-immediate-return': 'off',
  151. 'sonarjs/prefer-single-boolean-return': 'off',
  152. // Consider prettier offenses as errors.
  153. 'prettier/prettier': ['error'],
  154. },
  155. overrides: [
  156. {
  157. files: ['*.js'],
  158. rules: {
  159. '@typescript-eslint/no-var-requires': 'off',
  160. 'security/detect-object-injection': 'off',
  161. 'security/detect-non-literal-fs-filename': 'off',
  162. 'security/detect-non-literal-regexp': 'off',
  163. },
  164. },
  165. {
  166. files: [
  167. 'app/frontend/tests/**',
  168. 'app/frontend/**/__tests__/**',
  169. 'app/frontend/**/*.spec.*',
  170. 'app/frontend/cypress/**',
  171. '.eslint-plugin-zammad/**',
  172. '.eslintrc.js',
  173. ],
  174. rules: {
  175. 'zammad/zammad-tailwind-ltr': 'off',
  176. 'zammad/zammad-detect-translatable-string': 'off',
  177. '@typescript-eslint/no-non-null-assertion': 'off',
  178. '@typescript-eslint/no-explicit-any': 'off',
  179. },
  180. },
  181. // rules that require type information
  182. {
  183. files: ['*.ts', '*.tsx', '*.vue'],
  184. rules: {
  185. // handled by typescript itself with "verbatimModuleSyntax"
  186. '@typescript-eslint/consistent-type-imports': 'off',
  187. '@typescript-eslint/consistent-type-exports': 'error',
  188. 'security/detect-object-injection': 'off',
  189. 'security/detect-non-literal-fs-filename': 'off',
  190. 'security/detect-non-literal-regexp': 'off',
  191. },
  192. parserOptions: {
  193. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  194. },
  195. },
  196. ],
  197. settings: {
  198. 'import/core-modules': ['virtual:pwa-register'],
  199. 'import/parsers': {
  200. '@typescript-eslint/parser': ['.ts', '.tsx'],
  201. },
  202. 'import/resolver': {
  203. typescript: {
  204. alwaysTryTypes: true,
  205. },
  206. alias: {
  207. map: [
  208. [
  209. 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  210. path.resolve(
  211. __dirname,
  212. 'node_modules/vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  213. ),
  214. ],
  215. ],
  216. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  217. },
  218. node: {
  219. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  220. },
  221. },
  222. // Adding typescript file types, because airbnb doesn't allow this by default.
  223. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  224. },
  225. globals: {
  226. defineProps: 'readonly',
  227. defineEmits: 'readonly',
  228. defineExpose: 'readonly',
  229. withDefaults: 'readonly',
  230. },
  231. parser: 'vue-eslint-parser',
  232. parserOptions: {
  233. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  234. sourceType: 'module', // allow the use of imports statements
  235. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  236. },
  237. }