.eslintrc.js 9.1 KB

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