.eslintrc.js 9.3 KB

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