.eslintrc.js 8.1 KB

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