eslint.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import path from 'node:path';
  2. import { includeIgnoreFile } from '@eslint/compat';
  3. import js from '@eslint/js';
  4. import { defineConfig } from 'eslint/config';
  5. import prettier from 'eslint-config-prettier';
  6. import simpleImportSort from 'eslint-plugin-simple-import-sort';
  7. import svelte from 'eslint-plugin-svelte';
  8. import globals from 'globals';
  9. import ts from 'typescript-eslint';
  10. import svelteConfig from './svelte.config.js';
  11. const gitignorePath = path.resolve(import.meta.dirname, '.gitignore');
  12. const prettierignorePath = path.resolve(import.meta.dirname, '.prettierignore');
  13. export default defineConfig(
  14. includeIgnoreFile(gitignorePath),
  15. includeIgnoreFile(prettierignorePath),
  16. js.configs.recommended,
  17. ts.configs.recommended,
  18. svelte.configs.recommended,
  19. prettier,
  20. svelte.configs.prettier,
  21. {
  22. languageOptions: { globals: { ...globals.browser, ...globals.node } },
  23. plugins: {
  24. 'simple-import-sort': simpleImportSort,
  25. },
  26. rules: {
  27. // typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
  28. // see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
  29. 'no-undef': 'off',
  30. 'simple-import-sort/imports': [
  31. 'error',
  32. {
  33. groups: [
  34. ['^node:'],
  35. ['^@?\\w'],
  36. ['^\\$app/'],
  37. ['^\\$lib/'],
  38. ['^\\$'],
  39. ['^\\.\\./'],
  40. ['^\\./'],
  41. ],
  42. },
  43. ],
  44. 'simple-import-sort/exports': 'error',
  45. },
  46. },
  47. {
  48. files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
  49. languageOptions: {
  50. parserOptions: {
  51. projectService: true,
  52. extraFileExtensions: ['.svelte'],
  53. parser: ts.parser,
  54. svelteConfig,
  55. },
  56. },
  57. rules: {
  58. 'svelte/sort-attributes': [
  59. 'error',
  60. {
  61. order: [
  62. 'this',
  63. 'bind:this',
  64. 'id',
  65. 'name',
  66. 'slot',
  67. { match: '/^--/u', sort: 'alphabetical' },
  68. ['style', '/^style:/u'],
  69. 'class',
  70. { match: '/^class:/u', sort: 'alphabetical' },
  71. {
  72. match: [
  73. '!/:/u',
  74. '!/^(?:this|id|name|slot|style|class)$/u',
  75. '!/^--/u',
  76. '!/^on[a-z]/u',
  77. ],
  78. sort: 'alphabetical',
  79. },
  80. ['/^bind:/u', '!bind:this', '/^on:/u', '/^on[a-z]/u'],
  81. { match: '/^use:/u', sort: 'alphabetical' },
  82. { match: '/^transition:/u', sort: 'alphabetical' },
  83. { match: '/^in:/u', sort: 'alphabetical' },
  84. { match: '/^out:/u', sort: 'alphabetical' },
  85. { match: '/^animate:/u', sort: 'alphabetical' },
  86. { match: '/^let:/u', sort: 'alphabetical' },
  87. ],
  88. },
  89. ],
  90. },
  91. },
  92. );