.eslintrc.js 7.4 KB

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