diff --git a/CLEANUP_GUIDE.md b/CLEANUP_GUIDE.md new file mode 100644 index 0000000..001aa0e --- /dev/null +++ b/CLEANUP_GUIDE.md @@ -0,0 +1,175 @@ +# ESLint Warning Cleanup Guide + +This document provides patterns for quickly fixing the 525 ESLint warnings in the codebase. + +## Quick Fixes + +### 1. Unused Imports +**Pattern:** `'X' is defined but never used` + +**Fix:** Remove the import +```typescript +// Before +import { Card, CardContent, Label } from '@/components/ui' + +// After +import { Card } from '@/components/ui' +``` + +### 2. Unused Function Parameters +**Pattern:** `'paramName' is defined but never used` + +**Fix:** Prefix with underscore +```typescript +// Before +const handleClick = (event, index) => { + doSomething() +} + +// After +const handleClick = (_event, _index) => { + doSomething() +} +``` + +### 3. Unused Destructured Variables +**Pattern:** `'variable' is assigned a value but never used` + +**Fix:** Remove from destructuring +```typescript +// Before +const { data, error, isLoading } = useQuery() + +// After +const { data } = useQuery() +``` + +### 4. Empty Catch Blocks +**Pattern:** `Empty block statement` + +**Fix:** Add comment or remove unused error +```typescript +// Before +try { + JSON.parse(value) +} catch (error) { + console.debug('Invalid JSON:', error) +} + +// After +try { + JSON.parse(value) +} catch { + // Ignore invalid JSON during typing +} +``` + +### 5. React Hook Dependencies +**Pattern:** `React Hook X has missing dependencies` + +**Fix:** Add dependencies or suppress with comment +```typescript +// Option 1: Add dependency +useEffect(() => { + fetchData(id) +}, [id, fetchData]) // Added fetchData + +// Option 2: Intentionally ignore (with explanation) +useEffect(() => { + // Only run on mount + initialize() + // eslint-disable-next-line react-hooks/exhaustive-deps +}, []) +``` + +### 6. `any` Types in Dynamic JSON Systems +**Pattern:** `Unexpected any. Specify a different type` + +**When to keep:** JSON schemas, component registries, dynamic props +**When to fix:** Function parameters, return types, simple objects + +```typescript +// Keep any for truly dynamic systems +interface ComponentRegistry { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: React.ComponentType +} + +// Fix for known structures +interface UserData { + id: string + name: string + email: string +} +``` + +## Automated Fixes + +### Using VSCode +1. Open Command Palette (`Cmd/Ctrl + Shift + P`) +2. Run "ESLint: Fix all auto-fixable Problems" +3. Review changes before committing + +### Using CLI +```bash +# Fix all auto-fixable issues +npm run lint -- --fix + +# Fix specific file +npx eslint --fix src/components/MyComponent.tsx +``` + +## Priority Order + +1. **High Priority** (Can cause bugs) + - Remove unused variables that shadow others + - Fix exhaustive-deps that could cause stale closures + - Fix typing errors in function calls + +2. **Medium Priority** (Code quality) + - Remove unused imports (speeds up builds) + - Prefix unused params with underscore + - Add proper types where straightforward + +3. **Low Priority** (Cosmetic) + - Fast refresh warnings + - any types in JSON/dynamic systems + - Optional chaining suggestions + +## Files to Skip (For Now) + +These files have intentionally loose typing due to their dynamic nature: +- `src/lib/json-ui/**/*.ts` - JSON-driven UI system +- `src/config/orchestration/**/*.ts` - Dynamic orchestration +- `src/schemas/**/*.ts` - Schema definitions with any +- `packages/spark-tools/**/*.ts` - External package + +## Bulk Patterns to Search/Replace + +### Remove unused console imports +Search: `import.*console.*from` +Action: Review and remove if not used + +### Fix underscore params +Search: `\(([a-z]+),\s*([a-z]+)\)\s*=>` +Review: Check if params are used, prefix with _ if not + +### Empty catch blocks with unused error +Search: `catch\s*\(error\)\s*\{[^}]*\}` +Replace: `catch { /* intentionally empty */ }` + +## Testing After Cleanup + +1. Run full lint: `npm run lint` +2. Run type check: `npm run type-check` (if available) +3. Run tests: `npm test` +4. Build: `npm run build` +5. Manual smoke test in dev: `npm run dev` + +## Notes + +- Don't fix all 525 at once - do batches by file/directory +- Always test after each batch +- Commit frequently with clear messages +- Some `any` types are justified in this codebase +- Focus on fixes that improve code quality, not just reduce warnings diff --git a/LINTING_STATUS.md b/LINTING_STATUS.md new file mode 100644 index 0000000..92d9d2e --- /dev/null +++ b/LINTING_STATUS.md @@ -0,0 +1,106 @@ +# Linting Status & Cleanup Plan + +## Current Status +**Total Warnings: 525** + +The codebase currently has 525 ESLint/TypeScript warnings across the project. These are **warnings, not errors**, meaning the application builds and runs successfully. + +## Warning Categories + +### 1. TypeScript `any` Types (Most Common - ~300 warnings) +**Issue:** `@typescript-eslint/no-explicit-any` +**Files Affected:** Nearly all files with type annotations +**Priority:** Medium +**Reason:** The app uses a highly dynamic JSON-driven architecture where strict typing is challenging + +**Strategy:** +- Create proper TypeScript interfaces for JSON schemas +- Use `unknown` instead of `any` where appropriate +- Add type guards for runtime validation +- Consider using `Record` for truly dynamic objects + +### 2. Unused Variables/Imports (~100 warnings) +**Issue:** `@typescript-eslint/no-unused-vars` +**Files Affected:** Throughout the codebase +**Priority:** High (easy wins) +**Examples:** +- Unused imports like `Toaster`, `CardContent`, `Label` +- Unused destructured values +- Unused function parameters + +**Strategy:** +- Remove unused imports +- Prefix unused parameters with `_` (e.g., `_config`, `_index`) +- Remove dead code + +### 3. React Hooks Dependencies (~50 warnings) +**Issue:** `react-hooks/exhaustive-deps` +**Files Affected:** Components with useEffect, useCallback, useMemo +**Priority:** Medium-High (can cause bugs) + +**Strategy:** +- Add missing dependencies +- Use useCallback for function dependencies +- Wrap objects/arrays in useMemo +- Carefully evaluate exhaustive-deps warnings (some may be intentional) + +### 4. Fast Refresh Export Issues (~15 warnings) +**Issue:** `react-refresh/only-export-components` +**Files Affected:** UI component files that also export constants +**Priority:** Low (doesn't affect production) + +**Strategy:** +- Move constants to separate files +- Use `allowConstantExport` (already enabled in config) + +### 5. Specific File Issues +- Empty catch blocks (use comment or remove console.log) +- Naming conflicts (EmptyState, LoadingState, StatCard) - **FIXED** +- Missing type definitions in orchestration/JSON-UI systems + +## Pragmatic Approach + +Given the codebase is **a low-code/no-code platform that generates code**, many `any` types are justifiable: +- JSON schemas are inherently dynamic +- Component props are defined at runtime +- The system needs flexibility for code generation + +## Cleanup Phases + +### Phase 1: Quick Wins (Completed Partially) +- [x] Fix naming conflicts in component exports +- [x] Remove empty catch blocks with unused error variables +- [ ] Remove unused imports (automated with IDE) +- [ ] Prefix unused args with underscore + +### Phase 2: Type Safety +- [ ] Create comprehensive interfaces for JSON schemas +- [ ] Replace `any` with `unknown` in data sources +- [ ] Add type guards for runtime validation +- [ ] Define proper types for component registry + +### Phase 3: React Best Practices +- [ ] Fix exhaustive-deps warnings +- [ ] Optimize re-renders with proper memoization +- [ ] Extract constants from component files + +### Phase 4: Architecture +- [ ] Consider using Zod schemas for runtime validation +- [ ] Generate TypeScript types from JSON schemas +- [ ] Implement stricter typing in orchestration layer + +## Notes +- Warnings are currently set to not fail the build (they're warnings, not errors) +- The app functions correctly despite these warnings +- Many warnings are inherent to the flexible/dynamic nature of the platform +- Prioritize fixing warnings that could cause actual bugs (hooks deps, unused vars) + +## CI/CD Linting +Current lint job shows warnings but doesn't fail. Consider: +1. Keeping current behavior (warnings only) +2. OR: Setting error threshold (fail if > X warnings) +3. OR: Making specific rules errors (e.g., no-unused-vars) + +## Related Files +- `eslint.config.js` - ESLint configuration +- `.github/workflows/lint.yml` - CI lint workflow diff --git a/src/App.new.tsx b/src/App.new.tsx index 7b53bf7..9ecd61b 100644 --- a/src/App.new.tsx +++ b/src/App.new.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { toast, Toaster } from 'sonner' +import { toast } from 'sonner' import { Tabs, TabsContent } from '@/components/ui/tabs' import { AppHeader, PageHeader } from '@/components/organisms' import { ProjectDashboard } from '@/components/ProjectDashboard' @@ -87,6 +87,7 @@ function App() { featureToggles, }) + // eslint-disable-next-line @typescript-eslint/no-explicit-any const loadProject = (project: any) => { if (project.files) setFiles(project.files) if (project.models) setModels(project.models) @@ -113,7 +114,7 @@ function App() { handleFileClose, } = useFileOperations(files, setFiles) - const { handleExportProject, exportDialogOpen, setExportDialogOpen, generatedCode, handleDownloadZip } = useProjectExport( + const { handleExportProject } = useProjectExport( files, models, components, diff --git a/src/components/ComponentTreeBuilder.tsx b/src/components/ComponentTreeBuilder.tsx index 522eb1c..233e2ea 100644 --- a/src/components/ComponentTreeBuilder.tsx +++ b/src/components/ComponentTreeBuilder.tsx @@ -274,8 +274,8 @@ export function ComponentTreeBuilder({ try { const props = JSON.parse(e.target.value) updateNode(selectedNode.id, { props }) - } catch (error) { - console.debug('Invalid JSON during typing:', error) + } catch { + // Ignore invalid JSON during typing } }} className="font-mono text-sm h-64" diff --git a/src/components/FeatureToggleSettings.tsx b/src/components/FeatureToggleSettings.tsx index dd41b4f..d7a821f 100644 --- a/src/components/FeatureToggleSettings.tsx +++ b/src/components/FeatureToggleSettings.tsx @@ -1,5 +1,4 @@ -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' -import { Label } from '@/components/ui/label' +import { Card, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Switch } from '@/components/ui/switch' import { FeatureToggles } from '@/types/project' import { Code, Database, Tree, PaintBrush, Flask, Play, BookOpen, Cube, Wrench, FileText, FlowArrow, Image, Lightbulb } from '@phosphor-icons/react' diff --git a/src/components/KeyboardShortcutsDialog.tsx b/src/components/KeyboardShortcutsDialog.tsx index a717947..9e062f5 100644 --- a/src/components/KeyboardShortcutsDialog.tsx +++ b/src/components/KeyboardShortcutsDialog.tsx @@ -5,7 +5,6 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog' -import { Card, CardContent } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { Keyboard } from '@phosphor-icons/react' diff --git a/src/components/LambdaDesigner.tsx b/src/components/LambdaDesigner.tsx index ad9857c..3e6f295 100644 --- a/src/components/LambdaDesigner.tsx +++ b/src/components/LambdaDesigner.tsx @@ -1,7 +1,7 @@ import { useState } from 'react' import { Lambda, LambdaTrigger } from '@/types/project' import { Button } from '@/components/ui/button' -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' +import { Card, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' diff --git a/src/components/index.ts b/src/components/index.ts index f383b7d..b7b4ce8 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,4 +1,32 @@ -export * from './atoms' +export { + AppLogo, + TabIcon, + StatusIcon, + ErrorBadge, + IconWrapper, + LoadingSpinner, + EmptyStateIcon, + TreeIcon, + FileIcon, + ActionIcon, + SeedDataStatus, + ActionButton, + IconButton, + DataList, + StatusBadge, + Text, + Heading, + List, + Grid, + DataSourceBadge, + BindingIndicator, + StatCard, + LoadingState, + EmptyState, + DetailRow, + CompletionCard, + TipsCard +} from './atoms' export { AppBranding, Breadcrumb,