.eslintrc.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. 'vue/script-setup-uses-vars': 'error',
  134. // Don't require a default value for the props.
  135. 'vue/require-default-prop': 'off',
  136. // Don't require multi word component names.
  137. 'vue/multi-word-component-names': 'off',
  138. // Enforce v-bind directive usage in short form as error instead of warning.
  139. 'vue/v-bind-style': ['error', 'shorthand'],
  140. // Enforce v-on directive usage in short form as error instead of warning.
  141. 'vue/v-on-style': ['error', 'shorthand'],
  142. // Enforce v-slot directive usage in short form as error instead of warning.
  143. 'vue/v-slot-style': ['error', 'shorthand'],
  144. 'no-promise-executor-return': 'off',
  145. // We have quite a lot of constant strings in our code.
  146. 'sonarjs/no-duplicate-string': 'off',
  147. // It also supresses local function returns.
  148. 'sonarjs/prefer-immediate-return': 'off',
  149. 'sonarjs/prefer-single-boolean-return': 'off',
  150. },
  151. overrides: [
  152. {
  153. files: ['*.js'],
  154. rules: {
  155. '@typescript-eslint/no-var-requires': 'off',
  156. 'security/detect-object-injection': 'off',
  157. 'security/detect-non-literal-fs-filename': 'off',
  158. 'security/detect-non-literal-regexp': 'off',
  159. },
  160. },
  161. {
  162. files: [
  163. 'app/frontend/tests/**',
  164. 'app/frontend/**/__tests__/**',
  165. 'app/frontend/**/*.spec.*',
  166. 'app/frontend/cypress/**',
  167. '.eslint-plugin-zammad/**',
  168. '.eslintrc.js',
  169. ],
  170. rules: {
  171. 'zammad/zammad-tailwind-ltr': 'off',
  172. 'zammad/zammad-detect-translatable-string': 'off',
  173. '@typescript-eslint/no-non-null-assertion': 'off',
  174. '@typescript-eslint/no-explicit-any': 'off',
  175. },
  176. },
  177. // rules that require type information
  178. {
  179. files: ['*.ts', '*.tsx', '*.vue'],
  180. rules: {
  181. // handled by typescript itself with "verbatimModuleSyntax"
  182. '@typescript-eslint/consistent-type-imports': 'off',
  183. '@typescript-eslint/consistent-type-exports': 'error',
  184. 'security/detect-object-injection': 'off',
  185. 'security/detect-non-literal-fs-filename': 'off',
  186. 'security/detect-non-literal-regexp': 'off',
  187. },
  188. parserOptions: {
  189. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  190. },
  191. },
  192. ],
  193. settings: {
  194. 'import/core-modules': ['virtual:pwa-register'],
  195. 'import/parsers': {
  196. '@typescript-eslint/parser': ['.ts', '.tsx'],
  197. },
  198. 'import/resolver': {
  199. typescript: {
  200. alwaysTryTypes: true,
  201. },
  202. alias: {
  203. map: [
  204. [
  205. 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  206. path.resolve(
  207. __dirname,
  208. 'node_modules/vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  209. ),
  210. ],
  211. ],
  212. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  213. },
  214. node: {
  215. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  216. },
  217. },
  218. // Adding typescript file types, because airbnb doesn't allow this by default.
  219. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  220. },
  221. globals: {
  222. defineProps: 'readonly',
  223. defineEmits: 'readonly',
  224. defineExpose: 'readonly',
  225. withDefaults: 'readonly',
  226. },
  227. parser: 'vue-eslint-parser',
  228. parserOptions: {
  229. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  230. sourceType: 'module', // allow the use of imports statements
  231. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  232. },
  233. }