.eslintrc.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright (C) 2012-2022 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: ['@typescript-eslint', 'vue', 'prettier', 'zammad'],
  10. extends: [
  11. 'airbnb-base',
  12. 'plugin:vue/vue3-recommended',
  13. 'plugin:@typescript-eslint/eslint-recommended',
  14. 'plugin:@typescript-eslint/recommended',
  15. 'plugin:prettier/recommended',
  16. '@vue/prettier',
  17. '@vue/typescript/recommended',
  18. 'prettier',
  19. ],
  20. rules: {
  21. 'zammad/zammad-copyright': 'error',
  22. 'zammad/zammad-detect-translatable-string': 'error',
  23. 'vue/script-setup-uses-vars': 'error',
  24. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  25. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  26. 'vue/component-tags-order': [
  27. 'error',
  28. {
  29. order: ['script', 'template', 'style'],
  30. },
  31. ],
  32. // Not allow the usage of relative imports, because we want always use the path aliases.
  33. 'no-restricted-imports': 'off',
  34. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  35. 'no-restricted-syntax': [
  36. 'error',
  37. 'ForInStatement',
  38. // "ForOfStatement", // We want to allow this
  39. 'LabeledStatement',
  40. 'WithStatement',
  41. ],
  42. // Disable the following rule, because it's not relevant for the tool chain and test envoirment.
  43. 'import/no-extraneous-dependencies': [
  44. 'error',
  45. {
  46. devDependencies: [
  47. 'tailwind.config.js',
  48. 'vite.config.ts',
  49. 'app/frontend/build/**',
  50. 'app/frontend/**/*.spec.*',
  51. 'app/frontend/tests/**/*',
  52. 'app/frontend/**/*.stories.ts',
  53. '.storybook/**/*',
  54. 'app/frontend/cypress/**/*',
  55. ],
  56. },
  57. ],
  58. // Adding typescript file types, because airbnb doesn't allow this by default.
  59. 'import/extensions': [
  60. 'error',
  61. 'ignorePackages',
  62. {
  63. js: 'never',
  64. mjs: 'never',
  65. jsx: 'never',
  66. ts: 'never',
  67. tsx: 'never',
  68. },
  69. ],
  70. /* 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). */
  71. 'no-undef': 'off',
  72. // We need to use the extended 'no-shadow' rule from typescript:
  73. // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
  74. 'no-shadow': 'off',
  75. '@typescript-eslint/no-shadow': 'off',
  76. // Enforce v-bind directive usage in long form.
  77. 'vue/v-bind-style': ['error', 'longform'],
  78. // Enforce v-on directive usage in long form.
  79. 'vue/v-on-style': ['error', 'longform'],
  80. // Enforce v-slot directive usage in long form.
  81. 'vue/v-slot-style': ['error', 'longform'],
  82. // Don't require a default value for the props.
  83. 'vue/require-default-prop': 'off',
  84. // Don't require multi word component names.
  85. 'vue/multi-word-component-names': 'off',
  86. },
  87. overrides: [
  88. {
  89. files: ['*.js'],
  90. rules: {
  91. '@typescript-eslint/no-var-requires': 'off',
  92. },
  93. },
  94. {
  95. files: ['.storybook/config/*'],
  96. rules: {
  97. 'import/no-extraneous-dependencies': 'off',
  98. },
  99. },
  100. {
  101. files: [
  102. 'app/frontend/tests/**',
  103. 'app/frontend/**/*.spec.*',
  104. 'app/frontend/stories/**',
  105. 'app/frontend/cypress/**',
  106. 'app/frontend/**/*.stories.ts',
  107. '.eslint-plugin-zammad/**',
  108. '.eslintrc.js',
  109. ],
  110. rules: {
  111. 'zammad/zammad-detect-translatable-string': 'off',
  112. '@typescript-eslint/no-non-null-assertion': 'off',
  113. },
  114. },
  115. ],
  116. settings: {
  117. 'import/resolver': {
  118. alias: {
  119. map: [
  120. ['@', path.resolve(__dirname, './app/frontend')],
  121. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  122. ['@shared', path.resolve(__dirname, './app/frontend/shared')],
  123. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  124. ['@stories', path.resolve(__dirname, './app/frontend/stories')],
  125. ['@cy', path.resolve(__dirname, './.cypress')],
  126. ],
  127. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  128. },
  129. node: {
  130. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  131. paths: [path.resolve(__dirname, '.storybook/node_modules/')],
  132. },
  133. },
  134. // Adding typescript file types, because airbnb doesn't allow this by default.
  135. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  136. },
  137. globals: {
  138. defineProps: 'readonly',
  139. defineEmits: 'readonly',
  140. defineExpose: 'readonly',
  141. withDefaults: 'readonly',
  142. },
  143. parser: 'vue-eslint-parser',
  144. parserOptions: {
  145. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  146. sourceType: 'module', // allow the use of imports statements
  147. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  148. },
  149. }