329 lines
7.9 KiB
Markdown
329 lines
7.9 KiB
Markdown
# Unused Code Audit Report
|
|
|
|
**Generated:** January 12, 2026
|
|
**Project:** Charon
|
|
**Audit Scope:** Backend (Go) and Frontend (TypeScript/React)
|
|
|
|
## Executive Summary
|
|
|
|
This audit examined the Charon project for unused code elements using the following linting tools:
|
|
|
|
1. **Go Vet** - Static analysis for Go code
|
|
2. **Staticcheck** - Advanced Go linter
|
|
3. **ESLint** - Frontend JavaScript/TypeScript linter
|
|
4. **TypeScript Compiler** - Type checking and unused code detection
|
|
|
|
### Findings Overview
|
|
|
|
| Category | Count | Severity |
|
|
|----------|-------|----------|
|
|
| Unused Variables (Frontend) | 1 | Low |
|
|
| Unused Type Annotations (Frontend) | 56 | Low |
|
|
| Unused Err Values (Backend) | 1 | Medium |
|
|
|
|
**Total Issues:** 58
|
|
|
|
---
|
|
|
|
## 1. Backend (Go) Unused Code
|
|
|
|
### 1.1 Unused Variables
|
|
|
|
#### File: `internal/services/certificate_service_test.go`
|
|
|
|
- **Line:** 397
|
|
- **Issue:** Value of `err` is never used
|
|
- **Code Context:**
|
|
|
|
```go
|
|
// Line 397
|
|
err := someOperation()
|
|
// err is assigned but never checked or used
|
|
```
|
|
|
|
- **Severity:** Medium
|
|
- **Recommendation:** Either check the error with proper error handling or use `_ = err` if intentionally ignoring
|
|
- **Safe to Remove:** No - Needs review. Error should be handled or explicitly ignored.
|
|
- **Category:** Unused Assignment (SA4006)
|
|
|
|
### 1.2 Analysis Notes
|
|
|
|
- **Go Vet:** Passed with no issues (exit code 0)
|
|
- **Staticcheck:** Identified 1 unused value issue
|
|
- No unused imports detected
|
|
- No unused functions detected
|
|
- No unused constants detected
|
|
|
|
The Go codebase is generally very clean with minimal unused code.
|
|
|
|
---
|
|
|
|
## 2. Frontend (TypeScript/React) Unused Code
|
|
|
|
### 2.1 Unused Variables
|
|
|
|
#### File: `frontend/src/components/CredentialManager.tsx`
|
|
|
|
- **Line:** 370
|
|
- **Variable:** `zone_filter`
|
|
- **Code Context:**
|
|
|
|
```tsx
|
|
const { zone_filter, ...rest } = prev
|
|
return rest
|
|
```
|
|
|
|
- **Severity:** Low
|
|
- **Recommendation:** This is a destructuring assignment used to remove `zone_filter` from the object. This is intentional and follows the pattern of "destructuring to omit properties".
|
|
- **Safe to Remove:** No - This is intentional code, not unused.
|
|
- **Category:** Unused Variable (False Positive)
|
|
- **Notes:** ESLint flags this as unused, but it's actually a common React pattern to extract and discard specific properties. Consider adding `// eslint-disable-next-line @typescript-eslint/no-unused-vars` if this warning is unwanted.
|
|
|
|
### 2.2 Type Annotation Issues (Not Unused Code)
|
|
|
|
The frontend linter reported 56 warnings about using `any` type. These are **NOT** unused code issues but rather type safety warnings.
|
|
|
|
#### Distribution by File
|
|
|
|
| File | Count | Lines |
|
|
|------|-------|-------|
|
|
| `src/api/__tests__/dnsProviders.test.ts` | 1 | 202 |
|
|
| `src/components/CredentialManager.tsx` | 5 | 71, 93, 370, 429, 454 |
|
|
| `src/components/DNSProviderForm.tsx` | 6 | 67, 93, 120, 132, 146, 298 |
|
|
| `src/components/__tests__/CredentialManager.test.tsx` | 9 | 128, 133, 138, 143, 148, 245, 269, 301, 480 |
|
|
| `src/components/__tests__/DNSProviderSelector.test.tsx` | 8 | 140, 235, 257, 275, 289, 304, 319, 424 |
|
|
| `src/components/__tests__/ManualDNSChallenge.test.tsx` | 11 | 147, 162, 404, 427, 452, 480, 520, 614, 642, 664, 686 |
|
|
| `src/components/dns-providers/ManualDNSChallenge.tsx` | 2 | 215, 229 |
|
|
| `src/hooks/__tests__/useCredentials.test.tsx` | 4 | 41, 68, 89, 126 |
|
|
| `src/hooks/useDocker.ts` | 1 | 15 |
|
|
| `src/pages/DNSProviders.tsx` | 2 | 33, 51 |
|
|
| `src/pages/Plugins.tsx` | 2 | 52, 66 |
|
|
| `src/pages/__tests__/Plugins.test.tsx` | 5 | 11, 186, 265, 281, 296 |
|
|
|
|
**Total:** 56 instances
|
|
|
|
#### Example Instances
|
|
|
|
**File:** `src/components/CredentialManager.tsx`
|
|
|
|
```tsx
|
|
// Line 71
|
|
const handleChange = (field: string, value: any) => { // ⚠️ any type
|
|
// ...
|
|
}
|
|
|
|
// Line 93
|
|
const handleFieldChange = (field: string, value: any) => { // ⚠️ any type
|
|
// ...
|
|
}
|
|
|
|
// Line 429
|
|
catch (error: any) { // ⚠️ any type
|
|
// ...
|
|
}
|
|
```
|
|
|
|
**File:** `src/components/DNSProviderForm.tsx`
|
|
|
|
```tsx
|
|
// Line 67
|
|
const handleCredentialChange = (field: string, value: any) => { // ⚠️ any type
|
|
// ...
|
|
}
|
|
|
|
// Line 93
|
|
const getFieldValue = (field: string): any => { // ⚠️ any type
|
|
// ...
|
|
}
|
|
```
|
|
|
|
**Severity:** Low
|
|
**Recommendation:** Replace `any` with proper TypeScript types for better type safety. This is a code quality issue, not unused code.
|
|
**Safe to Remove:** N/A - These are not unused; they need type improvements.
|
|
**Category:** Type Safety Warning
|
|
|
|
---
|
|
|
|
## 3. Detailed Findings by Category
|
|
|
|
### 3.1 Unused Imports
|
|
|
|
**Status:** ✅ None found
|
|
|
|
No unused imports were detected in either backend or frontend code.
|
|
|
|
### 3.2 Unused Functions
|
|
|
|
**Status:** ✅ None found
|
|
|
|
No unused functions were detected in either backend or frontend code.
|
|
|
|
### 3.3 Unused Constants
|
|
|
|
**Status:** ✅ None found
|
|
|
|
No unused constants were detected in either backend or frontend code.
|
|
|
|
### 3.4 Unused Variables
|
|
|
|
**Backend:** 1 issue (unused error value)
|
|
**Frontend:** 1 false positive (intentional destructuring pattern)
|
|
|
|
### 3.5 Unused Type Parameters
|
|
|
|
**Status:** ✅ None found
|
|
|
|
---
|
|
|
|
## 4. Recommendations
|
|
|
|
### 4.1 Immediate Actions
|
|
|
|
#### High Priority
|
|
|
|
None
|
|
|
|
#### Medium Priority
|
|
|
|
1. **Fix Backend Error Handling** (`internal/services/certificate_service_test.go:397`)
|
|
- Review the error assignment and add proper error handling
|
|
- If intentionally ignoring, use `_ = err` with a comment explaining why
|
|
|
|
### 4.2 Code Quality Improvements
|
|
|
|
#### Replace `any` Types (Low Priority)
|
|
|
|
The 56 instances of `any` type should be replaced with proper TypeScript types:
|
|
|
|
- **Test files:** Consider using `unknown` or specific mock types
|
|
- **Error handlers:** Use `Error` or `unknown` type
|
|
- **Event handlers:** Use proper React event types
|
|
- **Generic handlers:** Create proper type definitions
|
|
|
|
**Example Refactoring:**
|
|
|
|
```tsx
|
|
// Before
|
|
catch (error: any) {
|
|
console.error(error)
|
|
}
|
|
|
|
// After
|
|
catch (error: unknown) {
|
|
if (error instanceof Error) {
|
|
console.error(error.message)
|
|
} else {
|
|
console.error('Unknown error occurred')
|
|
}
|
|
}
|
|
```
|
|
|
|
#### False Positive Handling
|
|
|
|
For the `zone_filter` variable in `CredentialManager.tsx:370`, add an ESLint disable comment if the warning is bothersome:
|
|
|
|
```tsx
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const { zone_filter, ...rest } = prev
|
|
```
|
|
|
|
---
|
|
|
|
## 5. Linting Tool Outputs
|
|
|
|
### 5.1 Go Vet Output
|
|
|
|
```
|
|
Exit code: 0
|
|
```
|
|
|
|
**Result:** No issues found
|
|
|
|
### 5.2 Staticcheck Output
|
|
|
|
```
|
|
internal/services/certificate_service_test.go:397:3: this value of err is never used (SA4006)
|
|
Exit code: 1
|
|
```
|
|
|
|
**Result:** 1 issue found
|
|
|
|
### 5.3 Frontend ESLint Output
|
|
|
|
```
|
|
✖ 56 problems (0 errors, 56 warnings)
|
|
```
|
|
|
|
**Result:** 56 type safety warnings (not unused code)
|
|
|
|
### 5.4 TypeScript Type Check Output
|
|
|
|
```
|
|
Exit code: 0
|
|
```
|
|
|
|
**Result:** No type errors
|
|
|
|
---
|
|
|
|
## 6. Code Coverage Context
|
|
|
|
The project demonstrates excellent code hygiene with:
|
|
|
|
- No unused imports
|
|
- No unused functions
|
|
- Minimal unused variables
|
|
- Clean dependency management
|
|
- Good test coverage
|
|
|
|
The only actual unused code issue is a single unused error value in a test file, which is a minor oversight that should be addressed.
|
|
|
|
---
|
|
|
|
## 7. Summary and Action Items
|
|
|
|
### Critical Issues
|
|
|
|
**Count:** 0
|
|
|
|
### Important Issues
|
|
|
|
**Count:** 1
|
|
|
|
- [ ] Fix unused error value in `certificate_service_test.go:397`
|
|
|
|
### Suggested Improvements
|
|
|
|
**Count:** 57
|
|
|
|
- [ ] Replace `any` types with proper TypeScript types (56 instances)
|
|
- [ ] Consider adding ESLint directive for intentional destructuring pattern (1 instance)
|
|
|
|
### Overall Assessment
|
|
|
|
**Status:** ✅ Excellent
|
|
|
|
The codebase is remarkably clean with minimal unused code. The only true unused code issue is a single error value in a test file. The majority of linting warnings are related to type safety (use of `any`), not unused code.
|
|
|
|
---
|
|
|
|
## 8. Appendix: Tool Configuration
|
|
|
|
### Linting Tools Used
|
|
|
|
1. **Go Vet** - `go vet ./...`
|
|
2. **Staticcheck** - `staticcheck ./...`
|
|
3. **ESLint** - `npm run lint`
|
|
4. **TypeScript** - `npm run type-check`
|
|
|
|
### Excluded Patterns
|
|
|
|
- `node_modules/`
|
|
- `bower_components/`
|
|
- Generated files
|
|
- Build artifacts
|
|
|
|
---
|
|
|
|
**End of Report**
|