.eslintrc.js 6.9 KB

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