.eslintrc.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. 'vue/custom-event-name-casing': ['error', 'kebab-case'],
  137. // Enforce ordering for imports
  138. 'import/order': [
  139. 'error',
  140. {
  141. groups: [
  142. 'builtin',
  143. 'external',
  144. 'internal',
  145. 'parent',
  146. 'sibling',
  147. 'index',
  148. 'object',
  149. 'type',
  150. ],
  151. pathGroups: [
  152. {
  153. pattern: '#tests/**',
  154. group: 'internal',
  155. position: 'before',
  156. },
  157. {
  158. pattern: '#shared/**',
  159. group: 'internal',
  160. position: 'before',
  161. },
  162. {
  163. pattern: '#desktop/**',
  164. group: 'internal',
  165. },
  166. {
  167. pattern: '#mobile/**',
  168. group: 'internal',
  169. },
  170. {
  171. pattern: '**/types.ts',
  172. group: 'type',
  173. position: 'after',
  174. },
  175. ],
  176. 'newlines-between': 'always',
  177. alphabetize: { order: 'asc', caseInsensitive: true },
  178. },
  179. ],
  180. // Enforce Vue v3.3+ tuple syntax for defineEmits.
  181. 'vue/define-emits-declaration': ['error', 'type-literal'],
  182. 'vue/script-setup-uses-vars': 'error',
  183. // Don't require a default value for the props.
  184. 'vue/require-default-prop': 'off',
  185. // Don't require multi word component names.
  186. 'vue/multi-word-component-names': 'off',
  187. // Enforce v-bind directive usage in short form as error instead of warning.
  188. 'vue/v-bind-style': ['error', 'shorthand'],
  189. // Enforce v-on directive usage in short form as error instead of warning.
  190. 'vue/v-on-style': ['error', 'shorthand'],
  191. // Enforce v-slot directive usage in short form as error instead of warning.
  192. 'vue/v-slot-style': ['error', 'shorthand'],
  193. 'no-promise-executor-return': 'off',
  194. // We have quite a lot of constant strings in our code.
  195. 'sonarjs/no-duplicate-string': 'off',
  196. // It also supresses local function returns.
  197. 'sonarjs/prefer-immediate-return': 'off',
  198. 'sonarjs/prefer-single-boolean-return': 'off',
  199. // Consider prettier offenses as errors.
  200. 'prettier/prettier': ['error'],
  201. },
  202. overrides: [
  203. {
  204. files: ['*.js'],
  205. rules: {
  206. '@typescript-eslint/no-var-requires': 'off',
  207. 'security/detect-object-injection': 'off',
  208. 'security/detect-non-literal-fs-filename': 'off',
  209. 'security/detect-non-literal-regexp': 'off',
  210. },
  211. },
  212. {
  213. files: [
  214. 'app/frontend/tests/**',
  215. 'app/frontend/**/__tests__/**',
  216. 'app/frontend/**/*.spec.*',
  217. 'app/frontend/cypress/**',
  218. '.eslint-plugin-zammad/**',
  219. '.eslintrc.js',
  220. ],
  221. rules: {
  222. 'zammad/zammad-tailwind-ltr': 'off',
  223. 'zammad/zammad-detect-translatable-string': 'off',
  224. '@typescript-eslint/no-non-null-assertion': 'off',
  225. '@typescript-eslint/no-explicit-any': 'off',
  226. },
  227. },
  228. // rules that require type information
  229. {
  230. files: ['*.ts', '*.tsx', '*.vue'],
  231. rules: {
  232. // handled by typescript itself with "verbatimModuleSyntax"
  233. '@typescript-eslint/consistent-type-imports': 'off',
  234. '@typescript-eslint/consistent-type-exports': 'error',
  235. 'security/detect-object-injection': 'off',
  236. 'security/detect-non-literal-fs-filename': 'off',
  237. 'security/detect-non-literal-regexp': 'off',
  238. },
  239. parserOptions: {
  240. project: ['./tsconfig.json', './app/frontend/cypress/tsconfig.json'],
  241. },
  242. },
  243. ],
  244. settings: {
  245. 'import/core-modules': ['virtual:pwa-register'],
  246. 'import/parsers': {
  247. '@typescript-eslint/parser': ['.ts', '.tsx'],
  248. },
  249. 'import/resolver': {
  250. typescript: {
  251. alwaysTryTypes: true,
  252. },
  253. alias: {
  254. map: [
  255. [
  256. 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  257. path.resolve(
  258. __dirname,
  259. 'node_modules/vue-easy-lightbox/dist/external-css/vue-easy-lightbox.css',
  260. ),
  261. ],
  262. ],
  263. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  264. },
  265. node: {
  266. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  267. },
  268. },
  269. // Adding typescript file types, because airbnb doesn't allow this by default.
  270. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  271. },
  272. globals: {
  273. defineProps: 'readonly',
  274. defineEmits: 'readonly',
  275. defineExpose: 'readonly',
  276. withDefaults: 'readonly',
  277. },
  278. parser: 'vue-eslint-parser',
  279. parserOptions: {
  280. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  281. sourceType: 'module', // allow the use of imports statements
  282. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  283. },
  284. }