.eslintrc.js 7.7 KB

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