.eslintrc.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (C) 2012-2021 Zammad Foundation, https://zammad-foundation.org/
  2. const path = require('path')
  3. module.exports = {
  4. root: true,
  5. env: {
  6. browser: true,
  7. jest: true,
  8. node: true,
  9. },
  10. plugins: ['@typescript-eslint', 'vue', 'prettier', 'jest', 'zammad'],
  11. extends: [
  12. 'airbnb-base',
  13. 'plugin:vue/vue3-recommended',
  14. 'plugin:@typescript-eslint/eslint-recommended',
  15. 'plugin:@typescript-eslint/recommended',
  16. 'plugin:prettier/recommended',
  17. 'plugin:jest/recommended',
  18. '@vue/prettier',
  19. '@vue/typescript/recommended',
  20. 'prettier',
  21. ],
  22. rules: {
  23. 'zammad/zammad-copyright': 'error',
  24. 'vue/script-setup-uses-vars': 'error',
  25. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  26. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  27. 'vue/component-tags-order': [
  28. 'error',
  29. {
  30. order: ['template', 'script', 'style'],
  31. },
  32. ],
  33. // Not allow the usage of relative imports, because we want always use the path aliases.
  34. 'no-restricted-imports': [
  35. 'error',
  36. {
  37. patterns: [
  38. {
  39. group: ['.*'],
  40. message:
  41. 'Usage of relative imports is not allowed. Always path aliases should be used.',
  42. },
  43. ],
  44. },
  45. ],
  46. // Loosen AirBnB's strict rules a bit to allow 'for .. of'
  47. 'no-restricted-syntax': [
  48. 'error',
  49. 'ForInStatement',
  50. // "ForOfStatement", // We want to allow this
  51. 'LabeledStatement',
  52. 'WithStatement',
  53. ],
  54. // Disable the following rule, because it's not relevant for the tool chain and test envoirment.
  55. 'import/no-extraneous-dependencies': [
  56. 'error',
  57. {
  58. devDependencies: [
  59. 'tailwind.config.js',
  60. 'vite.config.ts',
  61. 'app/frontend/tests/**/*',
  62. 'app/frontend/stories/**/*',
  63. '.storybook/**/*',
  64. ],
  65. },
  66. ],
  67. // Adding typescript file types, because airbnb doesn't allow this by default.
  68. 'import/extensions': [
  69. 'error',
  70. 'ignorePackages',
  71. {
  72. js: 'never',
  73. mjs: 'never',
  74. jsx: 'never',
  75. ts: 'never',
  76. tsx: 'never',
  77. },
  78. ],
  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. // Expect assertions are mandatory for async tests.
  86. 'jest/prefer-expect-assertions': [
  87. 'error',
  88. { onlyFunctionsWithAsyncKeyword: true },
  89. ],
  90. // Enforce v-bind directive usage in long form.
  91. 'vue/v-bind-style': ['error', 'longform'],
  92. // Enforce v-on directive usage in long form.
  93. 'vue/v-on-style': ['error', 'longform'],
  94. // Don't require a default value for the props.
  95. 'vue/require-default-prop': 'off',
  96. },
  97. overrides: [
  98. {
  99. files: ['*.js'],
  100. rules: {
  101. '@typescript-eslint/no-var-requires': 'off',
  102. },
  103. },
  104. ],
  105. settings: {
  106. 'import/resolver': {
  107. alias: {
  108. map: [
  109. ['@', path.resolve(__dirname, './app/frontend/')],
  110. ['@mobile', path.resolve(__dirname, './app/frontend/apps/mobile')],
  111. ['@common', path.resolve(__dirname, './app/frontend/common')],
  112. ['@tests', path.resolve(__dirname, './app/frontend/tests')],
  113. ],
  114. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  115. },
  116. node: {
  117. extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  118. },
  119. },
  120. // Adding typescript file types, because airbnb doesn't allow this by default.
  121. 'import/extensions': ['.js', '.jsx', '.ts', '.tsx', '.vue'],
  122. },
  123. globals: {
  124. defineProps: 'readonly',
  125. defineEmits: 'readonly',
  126. defineExpose: 'readonly',
  127. withDefaults: 'readonly',
  128. },
  129. parser: 'vue-eslint-parser',
  130. parserOptions: {
  131. parser: '@typescript-eslint/parser', // the typescript-parser for eslint, instead of tslint
  132. sourceType: 'module', // allow the use of imports statements
  133. ecmaVersion: 2020, // allow the parsing of modern ecmascript
  134. },
  135. }