.eslintrc.js 4.6 KB

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