From 1b5fbf106e83312b6d8b7b275fc9431b62518c11 Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Mon, 21 Apr 2025 17:02:42 +0000 Subject: [PATCH] Fix ESLint warnings and configure CI to fail on warnings This PR addresses issue # 32 with the following changes: 1. Updated the package.json to make ESLint fail on warnings by adding `--max-warnings=0` flag to the lint script 2. Fixed all 13 ESLint warnings in the frontend code: - Removed unused imports and variables - Added missing component display name - Replaced `any` types with proper types (`unknown` or specific component types) 3. Updated CI workflow step description to clarify that ESLint will fail on warnings These changes ensure higher code quality by preventing ESLint warnings from passing CI checks. Closes # 32 Mentat precommits passed. Log: https://mentat.ai/log/7e4fc768-fcc8-4260-8e60-0328f8b6f1da --- .github/workflows/frontend-checks.yml | 2 +- frontend/package.json | 2 +- frontend/src/components/FileDetails.tsx | 6 +++--- frontend/src/components/FileUpload.tsx | 2 +- .../src/components/Visualization/RepositoryGraph.tsx | 7 ++++--- frontend/src/types/schema.ts | 10 +++++----- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/frontend-checks.yml b/.github/workflows/frontend-checks.yml index 17812f3..4d0fc94 100644 --- a/.github/workflows/frontend-checks.yml +++ b/.github/workflows/frontend-checks.yml @@ -32,5 +32,5 @@ jobs: - name: Check formatting with Prettier run: npm run format:check - - name: Run ESLint + - name: Run ESLint (fails on warnings) run: npm run lint diff --git a/frontend/package.json b/frontend/package.json index ceec7d3..b2875c6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,7 +7,7 @@ "dev": "vite", "build": "tsc && vite build", "preview": "vite preview", - "lint": "eslint --ext .js,.jsx,.ts,.tsx src/", + "lint": "eslint --ext .js,.jsx,.ts,.tsx src/ --max-warnings=0", "lint:fix": "eslint --ext .js,.jsx,.ts,.tsx src/ --fix", "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,json}\"", "format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,json}\"" diff --git a/frontend/src/components/FileDetails.tsx b/frontend/src/components/FileDetails.tsx index 3acf718..9983714 100644 --- a/frontend/src/components/FileDetails.tsx +++ b/frontend/src/components/FileDetails.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { RepositoryData, File } from '../types/schema'; +import { RepositoryData, Component } from '../types/schema'; interface FileDetailsProps { fileId: string; @@ -32,7 +32,7 @@ const FileDetails: React.FC = ({ fileId, data, onClose }) => { }; // Render a component and its children - const renderComponent = (component: any, depth = 0) => { + const renderComponent = (component: Component, depth = 0) => { return (
@@ -45,7 +45,7 @@ const FileDetails: React.FC = ({ fileId, data, onClose }) => { )} {component.components && component.components.length > 0 && (
- {component.components.map((subComp: any) => renderComponent(subComp, depth + 1))} + {component.components.map((subComp: Component) => renderComponent(subComp, depth + 1))}
)}
diff --git a/frontend/src/components/FileUpload.tsx b/frontend/src/components/FileUpload.tsx index f9a063c..8bd4670 100644 --- a/frontend/src/components/FileUpload.tsx +++ b/frontend/src/components/FileUpload.tsx @@ -57,7 +57,7 @@ const FileUpload: React.FC = ({ onDataLoaded, onLoadExample }) return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = e => resolve(e.target?.result as string); - reader.onerror = e => reject(new Error('Failed to read file')); + reader.onerror = () => reject(new Error('Failed to read file')); reader.readAsText(file); }); }; diff --git a/frontend/src/components/Visualization/RepositoryGraph.tsx b/frontend/src/components/Visualization/RepositoryGraph.tsx index 705f02b..d8532ca 100644 --- a/frontend/src/components/Visualization/RepositoryGraph.tsx +++ b/frontend/src/components/Visualization/RepositoryGraph.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react'; import * as d3 from 'd3'; -import { RepositoryData, File } from '../../types/schema'; +import { RepositoryData } from '../../types/schema'; interface RepositoryGraphProps { data: RepositoryData; @@ -179,10 +179,10 @@ const RepositoryGraph = forwardRef( .attr('stroke', '#fff') .attr('stroke-width', 1.5) .style('cursor', 'pointer') - .on('mouseover', function (event, d) { + .on('mouseover', function () { d3.select(this).attr('stroke-width', 3); }) - .on('mouseout', function (event, d) { + .on('mouseout', function (_event, d) { d3.select(this).attr('stroke-width', d.id === selectedFile ? 3 : 1.5); }) .on('click', (event, d) => { @@ -399,4 +399,5 @@ const RepositoryGraph = forwardRef( } ); +RepositoryGraph.displayName = 'RepositoryGraph'; export default RepositoryGraph; diff --git a/frontend/src/types/schema.ts b/frontend/src/types/schema.ts index 2568932..42816d8 100644 --- a/frontend/src/types/schema.ts +++ b/frontend/src/types/schema.ts @@ -8,7 +8,7 @@ export interface RepositoryData { files: File[]; relationships: Relationship[]; history?: History; - customData?: Record; + customData?: Record; } export interface Metadata { @@ -41,7 +41,7 @@ export interface FileMetrics { linesOfCode?: number; commentLines?: number; emptyLines?: number; - custom?: Record; + custom?: Record; } export interface Component { @@ -57,7 +57,7 @@ export interface Component { export interface ComponentMetrics { complexity?: number; linesOfCode?: number; - custom?: Record; + custom?: Record; } export interface Relationship { @@ -65,7 +65,7 @@ export interface Relationship { target: string; type: string; strength?: number; - metadata?: Record; + metadata?: Record; } export interface FileChange { @@ -85,7 +85,7 @@ export interface Commit { export interface TimelinePoint { commitId: string; - state: Record; + state: Record; snapshot: { files?: File[]; relationships?: Relationship[];