Skip to content

Commit 40087d7

Browse files
committed
fix: remove unused import and replace any types with proper types
**ESLint/TypeScript Fixes:** - Remove unused REPOS_CACHE_DIR import from actions.ts - Replace `any` types in gitApi.test.ts with proper generic types: - Use generic function signatures for mock implementations - Use `unknown` for type guards (matches actual isServiceError signature) - Use `as unknown as vi.Mock` for mocked functions - Use explicit object types instead of `any` for type assertions - Replace `any` types in gitApi.ts with proper types: - Import PrismaClient type from @sourcebot/db - Type prisma parameter as PrismaClient in resolveRepoId - Type logOptions as Record<string, string | number | null> **Why These Changes:** - Follows TypeScript best practices for type safety - Matches the actual type signatures used in the codebase - Satisfies @typescript-eslint/no-explicit-any linting rule - Maintains type safety while allowing proper mocking in tests Fixes the CI build failures from Next.js linting step. Signed-off-by: Wayne Sun <gsun@redhat.com>
1 parent f2d33ab commit 40087d7

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/web/src/actions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { getAuditService } from "@/ee/features/audit/factory";
44
import {
55
env,
6-
REPOS_CACHE_DIR,
76
ACTIVITY_FILTER_MAX_SCAN_LIMIT,
87
ACTIVITY_FILTER_CONCURRENCY_LIMIT,
98
generateApiKey,

packages/web/src/features/search/gitApi.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ vi.mock('@/lib/serviceError', () => ({
1515
}),
1616
}));
1717
vi.mock('@/actions', () => ({
18-
sew: async (fn: () => any) => {
18+
sew: async <T>(fn: () => Promise<T> | T): Promise<T> => {
1919
try {
2020
return await fn();
2121
} catch (error) {
2222
// Mock sew to convert thrown errors to ServiceError
2323
return {
2424
errorCode: 'UNEXPECTED_ERROR',
2525
message: error instanceof Error ? error.message : String(error),
26-
};
26+
} as T;
2727
}
2828
},
2929
}));
3030
// Create a mock findFirst function that we can configure per-test
3131
const mockFindFirst = vi.fn();
3232

3333
vi.mock('@/withAuthV2', () => ({
34-
withOptionalAuthV2: async (fn: (args: any) => any) => {
34+
withOptionalAuthV2: async <T>(fn: (args: { org: { id: number; name: string }; prisma: unknown }) => Promise<T>): Promise<T> => {
3535
// Mock withOptionalAuthV2 to provide org and prisma context
3636
const mockOrg = { id: 1, name: 'test-org' };
3737
const mockPrisma = {
@@ -43,8 +43,8 @@ vi.mock('@/withAuthV2', () => ({
4343
},
4444
}));
4545
vi.mock('@/lib/utils', () => ({
46-
isServiceError: (obj: any) => {
47-
return obj && typeof obj === 'object' && 'errorCode' in obj;
46+
isServiceError: (obj: unknown): obj is { errorCode: string } => {
47+
return obj !== null && typeof obj === 'object' && 'errorCode' in obj;
4848
},
4949
}));
5050

@@ -54,8 +54,8 @@ import { existsSync } from 'fs';
5454

5555
describe('searchCommits', () => {
5656
const mockGitLog = vi.fn();
57-
const mockSimpleGit = simpleGit as any;
58-
const mockExistsSync = existsSync as any;
57+
const mockSimpleGit = simpleGit as unknown as vi.Mock;
58+
const mockExistsSync = existsSync as unknown as vi.Mock;
5959

6060
beforeEach(() => {
6161
vi.clearAllMocks();
@@ -465,7 +465,7 @@ describe('searchCommits', () => {
465465
errorCode: 'UNEXPECTED_ERROR',
466466
});
467467
expect(result).toHaveProperty('message');
468-
const message = (result as any).message;
468+
const message = (result as { message: string }).message;
469469
expect(message).toContain('999');
470470
expect(message).toContain('not found on Sourcebot server disk');
471471
expect(message).toContain('cloning process may not be finished yet');

packages/web/src/features/search/gitApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { sew } from '@/actions';
77
import { toGitDate, validateDateRange } from './dateUtils';
88
import { withOptionalAuthV2 } from '@/withAuthV2';
99
import { isServiceError } from '@/lib/utils';
10+
import type { PrismaClient } from '@sourcebot/db';
1011

1112
const createGitClientForPath = (repoPath: string) => {
1213
return simpleGit({
@@ -31,7 +32,7 @@ const createGitClientForPath = (repoPath: string) => {
3132
const resolveRepoId = async (
3233
identifier: string | number,
3334
orgId: number,
34-
prisma: any
35+
prisma: PrismaClient
3536
): Promise<number | ServiceError> => {
3637
// If already numeric, return as-is
3738
if (typeof identifier === 'number') {
@@ -134,7 +135,7 @@ export const searchCommits = async ({
134135
const git = createGitClientForPath(repoPath);
135136

136137
try {
137-
const logOptions: any = {
138+
const logOptions: Record<string, string | number | null> = {
138139
maxCount,
139140
};
140141

0 commit comments

Comments
 (0)