|
| 1 | +import js from "@eslint/js"; |
| 2 | +import { defineConfig, globalIgnores } from "eslint/config"; |
| 3 | +import * as pluginImport from "eslint-plugin-import"; |
| 4 | +import pluginPrettier from "eslint-plugin-prettier"; |
| 5 | +import pluginSvelte from "eslint-plugin-svelte"; |
| 6 | +import globals from "globals"; |
| 7 | +import ts from "typescript-eslint"; |
| 8 | + |
| 9 | +export default defineConfig([ |
| 10 | + js.configs.recommended, |
| 11 | + ts.configs.recommended, |
| 12 | + pluginImport.flatConfigs.recommended, |
| 13 | + pluginImport.flatConfigs.typescript, |
| 14 | + pluginSvelte.configs["flat/recommended"], |
| 15 | + pluginSvelte.configs["flat/prettier"], |
| 16 | + globalIgnores([ |
| 17 | + // Ignore generated directories |
| 18 | + "**/node_modules/", |
| 19 | + "**/dist/", |
| 20 | + "**/pkg/", |
| 21 | + "wasm/pkg/", |
| 22 | + // Don't ignore JS and TS dotfiles in this folder |
| 23 | + "!**/.*.js", |
| 24 | + "!**/.*.ts", |
| 25 | + ]), |
| 26 | + { |
| 27 | + plugins: { |
| 28 | + prettier: pluginPrettier, |
| 29 | + }, |
| 30 | + settings: { |
| 31 | + "import/parsers": { "@typescript-eslint/parser": [".ts"] }, |
| 32 | + "import/resolver": { typescript: true, node: true }, |
| 33 | + }, |
| 34 | + languageOptions: { |
| 35 | + parserOptions: { |
| 36 | + project: "./tsconfig.json", |
| 37 | + }, |
| 38 | + globals: { |
| 39 | + ...globals.browser, |
| 40 | + ...globals.node, |
| 41 | + }, |
| 42 | + }, |
| 43 | + rules: { |
| 44 | + // Standard ESLint config (for ordinary JS syntax linting) |
| 45 | + indent: "off", |
| 46 | + quotes: ["error", "double", { allowTemplateLiterals: true }], |
| 47 | + camelcase: ["error", { properties: "always" }], |
| 48 | + "linebreak-style": ["error", "unix"], |
| 49 | + "eol-last": ["error", "always"], |
| 50 | + "max-len": ["error", { code: 200, tabWidth: 4, ignorePattern: `d="([\\s\\S]*?)"` }], |
| 51 | + "prefer-destructuring": "off", |
| 52 | + "no-console": "warn", |
| 53 | + "no-debugger": "warn", |
| 54 | + "no-param-reassign": ["error", { props: false }], |
| 55 | + "no-bitwise": "off", |
| 56 | + "no-shadow": "off", |
| 57 | + "no-use-before-define": "off", |
| 58 | + "no-restricted-imports": ["error", { patterns: [".*", "!@graphite/*"] }], |
| 59 | + |
| 60 | + // TypeScript plugin config (for TS-specific linting) |
| 61 | + "@typescript-eslint/indent": "off", |
| 62 | + "@typescript-eslint/camelcase": "off", |
| 63 | + "@typescript-eslint/no-use-before-define": "off", |
| 64 | + "@typescript-eslint/no-unused-vars": [ |
| 65 | + "error", |
| 66 | + { |
| 67 | + args: "all", |
| 68 | + argsIgnorePattern: "^_", |
| 69 | + caughtErrors: "all", |
| 70 | + caughtErrorsIgnorePattern: "^_", |
| 71 | + destructuredArrayIgnorePattern: "^_", |
| 72 | + varsIgnorePattern: "^_", |
| 73 | + ignoreRestSiblings: true, |
| 74 | + }, |
| 75 | + ], |
| 76 | + "@typescript-eslint/consistent-type-imports": "error", |
| 77 | + "@typescript-eslint/consistent-type-definitions": ["error", "type"], |
| 78 | + "@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as", objectLiteralTypeAssertions: "never" }], |
| 79 | + "@typescript-eslint/consistent-indexed-object-style": ["error", "record"], |
| 80 | + "@typescript-eslint/consistent-generic-constructors": ["error", "constructor"], |
| 81 | + "@typescript-eslint/no-restricted-types": ["error", { types: { null: "Use `undefined` instead." } }], |
| 82 | + |
| 83 | + // Prettier plugin config (for validating and fixing formatting) |
| 84 | + "prettier/prettier": "error", |
| 85 | + |
| 86 | + // Svelte plugin config (for validating Svelte-specific syntax) |
| 87 | + "svelte/no-at-html-tags": "off", |
| 88 | + "svelte/no-useless-mustaches": "off", |
| 89 | + "svelte/valid-compile": ["error", { ignoreWarnings: true }], |
| 90 | + "svelte/require-each-key": "off", // TODO: Remove this rule and fix the places where it's violated |
| 91 | + |
| 92 | + // Import plugin config (for intelligently validating module import statements) |
| 93 | + "import/no-unresolved": "error", |
| 94 | + // `no-duplicates` disabled due to <https://github.com/import-js/eslint-plugin-import/issues/1479#issuecomment-1789527447>. Reenable if that issue gets fixed. |
| 95 | + "import/no-duplicates": "off", |
| 96 | + "import/prefer-default-export": "off", |
| 97 | + "import/no-relative-packages": "error", |
| 98 | + "import/no-named-as-default-member": "off", |
| 99 | + "import/order": [ |
| 100 | + "error", |
| 101 | + { |
| 102 | + alphabetize: { order: "asc", caseInsensitive: true }, |
| 103 | + pathGroups: [{ pattern: "**/*.svelte", group: "unknown", position: "after" }], |
| 104 | + "newlines-between": "always-and-inside-groups", |
| 105 | + warnOnUnassignedImports: true, |
| 106 | + }, |
| 107 | + ], |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + files: ["**/*.svelte"], |
| 112 | + languageOptions: { |
| 113 | + // Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration. |
| 114 | + parserOptions: { |
| 115 | + projectService: true, |
| 116 | + parser: ts.parser, |
| 117 | + extraFileExtensions: [".svelte"], |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + { |
| 122 | + files: ["**/*.js"], |
| 123 | + extends: [ts.configs.disableTypeChecked], |
| 124 | + }, |
| 125 | +]); |
0 commit comments