.eslintrc.cjs 7.2 KB

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