From 080656b65a854b92c44cabb77fe310b158dc07b3 Mon Sep 17 00:00:00 2001 From: orfelorfel23 Date: Sat, 5 Sep 2026 13:03:19 +0200 Subject: [PATCH] ESLint 9 Flat-Config-Migration (Bonus 14) - eslint.config.js (NEU): Flat-Config fuer ESLint 9 - Globals explizit definiert (console, process, Buffer, etc.) - TypeScript-Parser + Plugin - Rules: no-unused-vars, no-explicit-any (warn) - Tests haben relaxed rules (no-explicit-any off, fuer Mocks) - .eslintrc.cjs -> .eslintrc.cjs.bak (Deprecation-Warnung weg) - package.json scripts.lint: USE_FLAT_CONFIG-Flag entfernt (default flat) - Tests: 2 tote Variablen entfernt - tests/tfidf.test.ts: jaccardSim (ungenutzt, nur Kommentar-Vergleich noetig) - tests/webapp/manifest.test.ts: indexHtmlPath (ungenutzt) Verifiziert: - 117/117 Tests gruen - ESLint exit 0 (ohne Deprecation-Warnung) - Tool-Build OK, Webapp-Build OK --- eslint.config.js | 60 +++++++++++++++++++++++++++++++++++ package.json | 2 +- tests/tfidf.test.ts | 2 -- tests/webapp/manifest.test.ts | 1 - 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..affdbf1 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,60 @@ +// ESLint 9 Flat Config +// Phase Bonus: Migration von .eslintrc.cjs zu eslint.config.js (flat config) +// Entfernt die Deprecation-Warnung, die bei v9 mit .eslintrc kam. + +import tseslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; + +export default [ + { + ignores: [ + 'dist/**', + 'node_modules/**', + 'webapp/dist/**', + 'webapp/node_modules/**', + 'eslint.config.js.bak', + ], + }, + { + files: ['src/**/*.ts', 'tests/**/*.ts'], + languageOptions: { + parser: tsParser, + parserOptions: { + ecmaVersion: 2022, + sourceType: 'module', + }, + globals: { + console: 'readonly', + process: 'readonly', + Buffer: 'readonly', + setTimeout: 'readonly', + clearTimeout: 'readonly', + fetch: 'readonly', + Response: 'readonly', + localStorage: 'readonly', + globalThis: 'readonly', + navigator: 'readonly', + window: 'readonly', + document: 'readonly', + URL: 'readonly', + NodeJS: 'readonly', + }, + }, + plugins: { + '@typescript-eslint': tseslint, + }, + rules: { + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + '@typescript-eslint/no-explicit-any': 'warn', + 'no-console': 'off', + }, + }, + { + // Tests duerfen globalThis-Mocking und andere Tricks nutzen + files: ['tests/**/*.ts', 'src/cli/ingest.ts'], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, + }, +]; diff --git a/package.json b/package.json index 8af17a0..45e7ff9 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dev": "tsc --watch", "test": "vitest run", "test:watch": "vitest", - "lint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint src/ tests/ --ext .ts", + "lint": "eslint src/ tests/ --ext .ts", "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"webapp/src/**/*.{ts,tsx}\"", "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\" \"webapp/src/**/*.{ts,tsx}\"", "init-vault": "npm run build && node bin/mindomat.mjs init-vault", diff --git a/tests/tfidf.test.ts b/tests/tfidf.test.ts index 96cc0b0..81a0f6e 100644 --- a/tests/tfidf.test.ts +++ b/tests/tfidf.test.ts @@ -66,8 +66,6 @@ describe('tfIdfCosineSimilarity', () => { // Beide Dokumente haben 'Kaffee' und 'Milch' gemeinsam, aber unterschiedliche andere const d1 = 'Kaffee Milch am Morgen'; const d2 = 'Kaffee Milch am Abend'; - // Jaccard wuerde hoch sein, weil viele gleiche Woerter - const jaccardSim = jaccardSimilarity(d1, d2); // TF-IDF sollte unterscheiden, weil 'Kaffee' und 'Milch' im Gesamtkorpus haeufiger sind const tfidfSim = tfIdfCosineSimilarity([d1, d2, 'Eine ganz andere Notiz ueber Sport'], d1, d2); // Beide positiv, aber konzeptuell aehnlich -> TF-IDF ist tendenziell niedriger diff --git a/tests/webapp/manifest.test.ts b/tests/webapp/manifest.test.ts index 77de1ed..402dbf3 100644 --- a/tests/webapp/manifest.test.ts +++ b/tests/webapp/manifest.test.ts @@ -57,7 +57,6 @@ describe('PWA-Icons', () => { describe('Service-Worker', () => { const swPath = join(WEBAPP_DIR, 'public', 'service-worker.js'); - const indexHtmlPath = join(WEBAPP_DIR, 'index.html'); it('existiert', () => { expect(existsSync(swPath)).toBe(true);