diff --git a/cli/index.ts b/cli/index.ts index 24e63fc..fd18017 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -28,7 +28,7 @@ program .command('sync') .description('Sync Markdown files to DB') .argument('', 'directory') - .action(async (dir) => { + .action(async (dir: string) => { console.log(`Syncing from "${dir}"...`); if (!fs.existsSync(dir)) { console.error('Directory not found'); @@ -57,12 +57,17 @@ program console.log('Sync complete.'); }); +interface ExportOptions { + format: string; + output: string; +} + program .command('export') .description('Export data (md, json, site)') .option('-f, --format ', 'format', 'md') .option('-o, --output ', 'output directory', './export') - .action(async (options) => { + .action(async (options: ExportOptions) => { const outDir = options.output; if (!fs.existsSync(outDir)) fs.mkdirSync(outDir, { recursive: true }); @@ -194,13 +199,18 @@ async function exportSite(outDir: string) { fs.writeFileSync(path.join(outDir, 'index.html'), html); } +interface EntityCreateOptions { + type: string; + description?: string; +} + program .command('entity-create') .description('Create entity') .argument('') .option('-t, --type ', 'type', 'concept') .option('-d, --description ', 'description') - .action(async (name, options) => { + .action(async (name: string, options: EntityCreateOptions) => { await ensureDb(); try { const entity = await repository.createEntity({ @@ -210,7 +220,7 @@ program }); console.log(`Created: ${entity.name} [${entity.type}] (ID: ${entity.id})`); } catch (err) { - console.error(`Failed to create entity: ${err}`); + console.error(`Failed to create entity: ${String(err)}`); } }); @@ -229,13 +239,17 @@ program } }); +interface ClaimCreateOptions { + confidence: string; +} + program .command('claim-create') .description('Create claim for entity') .argument('') .argument('') .option('-c, --confidence ', 'confidence', '1.0') - .action(async (entityName, statement, options) => { + .action(async (entityName: string, statement: string, options: ClaimCreateOptions) => { await ensureDb(); const entity = await repository.getEntityByName(entityName); if (!entity || !entity.id) { @@ -250,7 +264,7 @@ program }); console.log(`Claim added to ${entity.name}: ${claim.statement}`); } catch (err) { - console.error(`Failed to create claim: ${err}`); + console.error(`Failed to create claim: ${String(err)}`); } }); diff --git a/eslint.config.js b/eslint.config.js index b25321b..8ab1faa 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,6 +4,7 @@ import reactHooks from 'eslint-plugin-react-hooks'; import react from 'eslint-plugin-react'; import jsxA11y from 'eslint-plugin-jsx-a11y'; import reactRefresh from 'eslint-plugin-react-refresh'; +import globals from 'globals'; export default tseslint.config( { @@ -17,18 +18,47 @@ export default tseslint.config( }, js.configs.recommended, ...tseslint.configs.recommendedTypeChecked, - react.configs.flat.recommended, - react.configs.flat['jsx-runtime'], - jsxA11y.flatConfigs.recommended, + + // App-specific configuration (React) { files: ['src/**/*.{ts,tsx}'], + ...react.configs.flat.recommended, + ...react.configs.flat['jsx-runtime'], + plugins: { + ...react.configs.flat.recommended.plugins, + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + 'jsx-a11y': jsxA11y, + }, languageOptions: { parserOptions: { project: ['./tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, }, + rules: { + ...react.configs.flat.recommended.rules, + ...react.configs.flat['jsx-runtime'].rules, + ...reactHooks.configs.recommended.rules, + ...jsxA11y.flatConfigs.recommended.rules, + 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], + 'jsx-a11y/click-events-have-key-events': 'warn', + 'jsx-a11y/no-static-element-interactions': 'warn', + 'jsx-a11y/no-noninteractive-element-interactions': 'warn', + 'jsx-a11y/interactive-supports-focus': 'warn', + 'jsx-a11y/role-has-required-aria-props': 'warn', + 'jsx-a11y/role-supports-aria-props': 'warn', + 'jsx-a11y/no-autofocus': 'warn', + 'react/no-unescaped-entities': 'warn', + }, + settings: { + react: { + version: 'detect', + }, + }, }, + + // Test configuration { files: ['tests/**/*.{ts,tsx}', 'src/**/*.test.{ts,tsx}', 'src/**/*.spec.{ts,tsx}', 'src/test/setup.ts'], languageOptions: { @@ -38,59 +68,45 @@ export default tseslint.config( }, }, }, + + // CLI and Config Files (Node) { files: ['cli/**/*.ts', 'scripts/**/*.ts', '*.config.{ts,js,cjs}', '*.config.*.{ts,js,cjs}', 'eslint.config.js'], languageOptions: { globals: { - module: 'readonly', - process: 'readonly', - require: 'readonly', - __dirname: 'readonly', + ...globals.node, }, parserOptions: { project: ['./tsconfig.node.json'], tsconfigRootDir: import.meta.dirname, }, }, + rules: { + '@typescript-eslint/no-unsafe-assignment': 'warn', + '@typescript-eslint/no-unsafe-call': 'warn', + '@typescript-eslint/no-unsafe-member-access': 'warn', + }, }, + { - plugins: { - 'react-hooks': reactHooks, - 'react-refresh': reactRefresh, - }, rules: { - ...reactHooks.configs.recommended.rules, - 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-empty-function': 'error', 'no-empty-function': 'off', // Replaced by TS version - // Temporarily downgrade new rules to warn to allow for incremental fixing - '@typescript-eslint/no-misused-promises': 'warn', - '@typescript-eslint/no-floating-promises': 'warn', - '@typescript-eslint/no-unsafe-assignment': 'warn', - '@typescript-eslint/no-unsafe-member-access': 'warn', - '@typescript-eslint/no-unsafe-call': 'warn', - '@typescript-eslint/no-unsafe-argument': 'warn', - '@typescript-eslint/await-thenable': 'warn', - '@typescript-eslint/no-unnecessary-type-assertion': 'warn', - '@typescript-eslint/unbound-method': 'warn', - '@typescript-eslint/require-await': 'warn', - 'jsx-a11y/click-events-have-key-events': 'warn', - 'jsx-a11y/no-static-element-interactions': 'warn', - 'jsx-a11y/no-noninteractive-element-interactions': 'warn', - 'jsx-a11y/interactive-supports-focus': 'warn', - 'jsx-a11y/role-has-required-aria-props': 'warn', - 'jsx-a11y/role-supports-aria-props': 'warn', - 'jsx-a11y/no-autofocus': 'warn', - 'react/no-unescaped-entities': 'warn', - }, - settings: { - react: { - version: 'detect', - }, + + '@typescript-eslint/no-misused-promises': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-unsafe-assignment': 'error', + '@typescript-eslint/no-unsafe-member-access': 'error', + '@typescript-eslint/no-unsafe-call': 'error', + '@typescript-eslint/no-unsafe-argument': 'error', + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/unbound-method': 'error', + '@typescript-eslint/require-await': 'error', }, }, -); +); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7f7cb10..9ac2c00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.6", + "globals": "^17.6.0", "jsdom": "^29.1.1", "ts-node": "^10.9.2", "typescript": "^5.2.2", @@ -503,6 +504,19 @@ "concat-map": "0.0.1" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/eslintrc/node_modules/minimatch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", @@ -3348,9 +3362,9 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "17.6.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.6.0.tgz", + "integrity": "sha512-sepffkT8stwnIYbsMBpoCHJuJM5l98FUF2AnE07hfvE0m/qp3R586hw4jF4uadbhvg1ooIdzuu7CsfD2jzCaNA==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index 3110bce..1b8159f 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint-plugin-react": "^7.37.5", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.6", + "globals": "^17.6.0", "jsdom": "^29.1.1", "ts-node": "^10.9.2", "typescript": "^5.2.2",