diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 6992bce93..000000000 --- a/.eslintrc +++ /dev/null @@ -1,130 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "env": { - "node": true, - "browser": true - }, - "plugins": [ - "@typescript-eslint", - "unused-imports" - ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "plugin:svelte/recommended", - "plugin:import/recommended", - "plugin:import/typescript" - ], - "settings": { - "import/parsers": { - "@typescript-eslint/parser": [ - ".ts", - ".tsx" - ] - }, - "import/resolver": { - "typescript": { - "alwaysTryTypes": true, - // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/unist` - "project": "./tsconfig.json" - } - } - }, - "parserOptions": { - "sourceType": "module", - "extraFileExtensions": [ - ".svelte" - ] - }, - "overrides": [ - { - "files": [ - "*.svelte" - ], - "parser": "svelte-eslint-parser", - "parserOptions": { - "parser": "@typescript-eslint/parser" - } - } - ], - "rules": { - "no-constant-condition": [ - "error", - { - "checkLoops": false - } - ], - // todo: Reenable once https://github.com/import-js/eslint-plugin-import/issues/1479 is fixed. - "import/no-duplicates": "off", - "svelte/valid-compile": "off", - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": [ - "error", - { - "args": "none" - } - ], - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-empty-function": "off", - "no-prototype-builtins": "off", - "svelte/sort-attributes": "warn", - "import/order": [ - "warn", - { - "alphabetize": { - "order": "asc", - "caseInsensitive": true - }, - "newlines-between": "always" - } - ], - "import/no-unresolved": [ - "error", - { - "ignore": [ - "^obsidian$", - "^@testing-library/svelte$" - ] - } - ], - "unused-imports/no-unused-imports": "error", - "@typescript-eslint/naming-convention": [ - "error", - { - "selector": "enum", - "format": [ - "PascalCase" - ] - }, - { - "selector": "enumMember", - "format": [ - "UPPER_CASE" - ] - }, - { - "selector": "interface", - "format": [ - "PascalCase" - ], - "custom": { - "regex": "^I[A-Z]", - "match": false - } - }, - // UPPER_CASE is great, but we can't check it automatically only for vars declared once in the lifecycle of a program, - // as Google's style guide suggests - { - "selector": "variable", - "modifiers": [ - "const" - ], - "format": [ - "camelCase" - ] - } - ] - } -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..e1c053db5 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,118 @@ +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import js from '@eslint/js'; +import { FlatCompat } from '@eslint/eslintrc'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, +}); + +export default [ + ...compat.config({ + root: true, + parser: '@typescript-eslint/parser', + env: { + node: true, + browser: true, + }, + plugins: ['@typescript-eslint', 'unused-imports'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:svelte/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + ], + settings: { + 'import/parsers': { + '@typescript-eslint/parser': ['.js', '.cjs', '.mjs', '.ts', '.tsx'], + }, + 'import/resolver': { + typescript: { + alwaysTryTypes: true, + project: './tsconfig.json', + }, + }, + }, + parserOptions: { + sourceType: 'module', + extraFileExtensions: ['.svelte'], + }, + overrides: [ + { + files: ['**/*.svelte'], + parser: 'svelte-eslint-parser', + parserOptions: { + parser: '@typescript-eslint/parser', + }, + }, + ], + rules: { + 'no-constant-condition': ['error', { checkLoops: false }], + 'import/no-duplicates': 'off', + 'svelte/valid-compile': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unnecessary-type-constraint': 'off', + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': ['error', { args: 'none' }], + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-function': 'off', + 'no-prototype-builtins': 'off', + 'svelte/sort-attributes': 'warn', + 'import/order': [ + 'warn', + { + alphabetize: { + order: 'asc', + caseInsensitive: true, + }, + 'newlines-between': 'always', + }, + ], + 'import/no-unresolved': [ + 'error', + { + ignore: ['^obsidian$', '^@testing-library/svelte$'], + }, + ], + 'unused-imports/no-unused-imports': 'error', + '@typescript-eslint/naming-convention': [ + 'error', + { + selector: 'enum', + format: ['PascalCase'], + }, + { + selector: 'enumMember', + format: ['UPPER_CASE'], + }, + { + selector: 'interface', + format: ['PascalCase'], + custom: { + regex: '^I[A-Z]', + match: false, + }, + }, + { + selector: 'variable', + modifiers: ['const'], + format: ['camelCase'], + }, + ], + }, + }), + { + files: ['**/*.svelte'], + rules: { + '@typescript-eslint/no-unused-vars': 'off', + 'unused-imports/no-unused-imports': 'off', + }, + }, +]; diff --git a/package-lock.json b/package-lock.json index 82e21bc8e..14797fa65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,8 +46,8 @@ "@types/mdast": "^4.0.4", "@types/node": "^22.5.5", "@types/unist": "^3.0.3", - "@typescript-eslint/eslint-plugin": "^8.4.0", - "@typescript-eslint/parser": "^8.6.0", + "@typescript-eslint/eslint-plugin": "latest", + "@typescript-eslint/parser": "latest", "@vitest/coverage-istanbul": "^2.1.4", "babel": "^6.23.0", "builtin-modules": "^4.0.0", @@ -60,11 +60,11 @@ "esbuild-plugin-replace": "^1.4.0", "esbuild-sass-plugin": "^3.3.1", "esbuild-svelte": "^0.8.1", - "eslint": "^8.57.0", - "eslint-import-resolver-typescript": "^3.6.3", - "eslint-plugin-import": "^2.30.0", - "eslint-plugin-svelte": "^2.43.0", - "eslint-plugin-unused-imports": "^4.1.3", + "eslint": "9.39.3", + "eslint-import-resolver-typescript": "latest", + "eslint-plugin-import": "latest", + "eslint-plugin-svelte": "latest", + "eslint-plugin-unused-imports": "latest", "husky": "^9.1.5", "ignore-styles": "^5.0.1", "js-yaml": "^4.1.0", diff --git a/package.json b/package.json index e1ce40881..266c45422 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "@types/mdast": "^4.0.4", "@types/node": "^22.5.5", "@types/unist": "^3.0.3", - "@typescript-eslint/eslint-plugin": "^8.4.0", - "@typescript-eslint/parser": "^8.6.0", + "@typescript-eslint/eslint-plugin": "latest", + "@typescript-eslint/parser": "latest", "@vitest/coverage-istanbul": "^2.1.4", "babel": "^6.23.0", "builtin-modules": "^4.0.0", @@ -43,11 +43,11 @@ "esbuild-plugin-replace": "^1.4.0", "esbuild-sass-plugin": "^3.3.1", "esbuild-svelte": "^0.8.1", - "eslint": "^8.57.0", - "eslint-import-resolver-typescript": "^3.6.3", - "eslint-plugin-import": "^2.30.0", - "eslint-plugin-svelte": "^2.43.0", - "eslint-plugin-unused-imports": "^4.1.3", + "eslint": "9.39.3", + "eslint-import-resolver-typescript": "latest", + "eslint-plugin-import": "latest", + "eslint-plugin-svelte": "latest", + "eslint-plugin-unused-imports": "latest", "husky": "^9.1.5", "ignore-styles": "^5.0.1", "js-yaml": "^4.1.0",