.eslintrc.cjs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. module.exports = {
  2. env: {
  3. browser: true,
  4. es2021: true,
  5. },
  6. extends: [
  7. '@antfu/eslint-config-vue',
  8. 'plugin:vue/vue3-recommended',
  9. 'plugin:import/recommended',
  10. 'plugin:import/typescript',
  11. 'plugin:sonarjs/recommended',
  12. 'plugin:@typescript-eslint/recommended',
  13. // 'plugin:unicorn/recommended',
  14. ],
  15. parser: 'vue-eslint-parser',
  16. parserOptions: {
  17. ecmaVersion: 13,
  18. parser: '@typescript-eslint/parser',
  19. sourceType: 'module',
  20. },
  21. plugins: [
  22. 'vue',
  23. '@typescript-eslint',
  24. 'regex',
  25. ],
  26. ignorePatterns: ['src/@iconify/*.js', 'node_modules', 'dist', '*.d.ts'],
  27. rules: {
  28. 'vue/no-v-html': 'off',
  29. 'vue/block-tag-newline': 'off',
  30. // eslint-disable-next-line n/prefer-global/process
  31. 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  32. // eslint-disable-next-line n/prefer-global/process
  33. 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
  34. // indentation (Already present in TypeScript)
  35. 'comma-spacing': ['error', {
  36. before: false,
  37. after: true,
  38. }],
  39. 'key-spacing': ['error', {afterColon: true}],
  40. 'vue/first-attribute-linebreak': ['error', {
  41. singleline: 'beside',
  42. multiline: 'below',
  43. }],
  44. 'antfu/top-level-function': 'off',
  45. // Enforce trailing comma (Already present in TypeScript)
  46. 'comma-dangle': ['error', 'always-multiline'],
  47. // Disable max-len
  48. 'max-len': 'off',
  49. // we don't want it
  50. 'semi': ['error', 'never'],
  51. // add parens ony when required in arrow function
  52. 'arrow-parens': ['error', 'as-needed'],
  53. // add new line above comment
  54. 'newline-before-return': 'error',
  55. // add new line above comment
  56. 'lines-around-comment': [
  57. 'error',
  58. {
  59. beforeBlockComment: true,
  60. beforeLineComment: true,
  61. allowBlockStart: true,
  62. allowClassStart: true,
  63. allowObjectStart: true,
  64. allowArrayStart: true,
  65. },
  66. ],
  67. // Ignore _ as unused variable
  68. '@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_+$'}],
  69. 'array-element-newline': ['error', 'consistent'],
  70. 'array-bracket-newline': ['error', 'consistent'],
  71. 'vue/multi-word-component-names': 'off',
  72. 'padding-line-between-statements': [
  73. 'error',
  74. {
  75. blankLine: 'always',
  76. prev: 'expression',
  77. next: 'const',
  78. },
  79. {
  80. blankLine: 'always',
  81. prev: 'const',
  82. next: 'expression',
  83. },
  84. {
  85. blankLine: 'always',
  86. prev: 'multiline-const',
  87. next: '*',
  88. },
  89. {
  90. blankLine: 'always',
  91. prev: '*',
  92. next: 'multiline-const',
  93. },
  94. ],
  95. // Plugin: eslint-plugin-import
  96. 'import/prefer-default-export': 'off',
  97. 'import/newline-after-import': ['error', {count: 1}],
  98. 'no-restricted-imports': ['error', 'vuetify/components'],
  99. // For omitting extension for ts files
  100. 'import/extensions': [
  101. 'error',
  102. 'ignorePackages',
  103. {
  104. mjs: 'never',
  105. js: 'never',
  106. jsx: 'never',
  107. ts: 'never',
  108. tsx: 'never',
  109. },
  110. ],
  111. // ignore virtual files
  112. 'import/no-unresolved': [2, {
  113. ignore: [
  114. '~pages$',
  115. 'virtual:generated-layouts',
  116. // Ignore vite's ?raw imports
  117. '.*\?raw',
  118. ],
  119. }],
  120. // Thanks: https://stackoverflow.com/a/63961972/10796681
  121. 'no-shadow': 'off',
  122. '@typescript-eslint/no-shadow': ['error'],
  123. '@typescript-eslint/consistent-type-imports': 'error',
  124. // Plugin: eslint-plugin-promise
  125. 'promise/always-return': 'off',
  126. 'promise/catch-or-return': 'off',
  127. // ESLint plugin vue
  128. 'vue/component-api-style': 'error',
  129. 'vue/component-name-in-template-casing': ['error', 'PascalCase', {registeredComponentsOnly: false}],
  130. 'vue/custom-event-name-casing': ['error', 'camelCase', {
  131. ignores: [
  132. '/^(click):[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?/',
  133. ],
  134. }],
  135. 'vue/define-macros-order': 'error',
  136. 'vue/html-comment-content-newline': 'error',
  137. 'vue/html-comment-content-spacing': 'error',
  138. 'vue/html-comment-indent': 'error',
  139. 'vue/match-component-file-name': 'error',
  140. 'vue/no-child-content': 'error',
  141. 'vue/require-default-prop': 'off',
  142. // NOTE this rule only supported in SFC, Users of the unplugin-vue-define-options should disable that rule: https://github.com/vuejs/eslint-plugin-vue/issues/1886
  143. // 'vue/no-duplicate-attr-inheritance': 'error',
  144. 'vue/no-multiple-objects-in-class': 'error',
  145. 'vue/no-reserved-component-names': 'error',
  146. 'vue/no-template-target-blank': 'error',
  147. 'vue/no-useless-mustaches': 'error',
  148. 'vue/no-useless-v-bind': 'error',
  149. 'vue/padding-line-between-blocks': 'error',
  150. 'vue/prefer-separate-static-class': 'error',
  151. 'vue/prefer-true-attribute-shorthand': 'error',
  152. 'vue/v-on-function-call': 'error',
  153. 'vue/valid-v-slot': ['error', {
  154. allowModifiers: true,
  155. }],
  156. // -- Extension Rules
  157. 'vue/no-irregular-whitespace': 'error',
  158. // -- Sonarlint
  159. 'sonarjs/no-duplicate-string': 'off',
  160. 'sonarjs/no-nested-template-literals': 'off',
  161. // -- Unicorn
  162. // 'unicorn/filename-case': 'off',
  163. // 'unicorn/prevent-abbreviations': ['error', {
  164. // replacements: {
  165. // props: false,
  166. // },
  167. // }],
  168. // https://github.com/gmullerb/eslint-plugin-regex
  169. 'regex/invalid': [
  170. 'error',
  171. [
  172. {
  173. regex: '@/assets/images',
  174. replacement: '@images',
  175. message: 'Use \'@images\' path alias for image imports',
  176. },
  177. {
  178. regex: '@/styles',
  179. replacement: '@styles',
  180. message: 'Use \'@styles\' path alias for importing styles from \'src/styles\'',
  181. },
  182. // {
  183. // id: 'Disallow icon of icon library',
  184. // regex: 'tabler-\\w',
  185. // message: 'Only \'mdi\' icons are allowed',
  186. // },
  187. {
  188. regex: '@core/\\w',
  189. message: 'You can\'t use @core when you are in @layouts module',
  190. files: {
  191. inspect: '@layouts/.*',
  192. },
  193. },
  194. {
  195. regex: 'useLayouts\\(',
  196. message: '`useLayouts` composable is only allowed in @layouts & @core directory. Please use `useThemeConfig` composable instead.',
  197. files: {
  198. inspect: '^(?!.*(@core|@layouts)).*',
  199. },
  200. },
  201. ],
  202. // Ignore files
  203. '\.eslintrc\.js',
  204. ],
  205. },
  206. settings: {
  207. 'import/resolver': {
  208. node: {
  209. extensions: ['.ts', '.js', '.tsx', '.jsx', '.mjs', '.png', '.jpg'],
  210. },
  211. typescript: {},
  212. alias: {
  213. map: [
  214. ['@', './src'],
  215. ],
  216. },
  217. },
  218. },
  219. overrides: [
  220. {
  221. files: ['*.json'],
  222. rules: {
  223. 'no-invalid-meta': 'off',
  224. },
  225. },
  226. ],
  227. }