mirror of https://github.com/buster-so/buster.git
fix: resolve remaining TypeScript errors
- Add nullish coalescing operators for optional boolean properties - Fix 'Object is possibly undefined' errors in unit tests - Ensure type compatibility between Zod schema and helper functions Co-Authored-By: Dallin Bentley <dallinbentley98@gmail.com>
This commit is contained in:
parent
116393bfb4
commit
ce9de9e4c9
|
@ -41,8 +41,9 @@ describe('grep-search', () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(result.successful_searches).toHaveLength(1);
|
expect(result.successful_searches).toHaveLength(1);
|
||||||
expect(result.successful_searches[0]?.matches).toHaveLength(1);
|
expect(result.successful_searches[0]).toBeDefined();
|
||||||
expect(result.successful_searches[0]?.matches[0]).toEqual({
|
expect(result.successful_searches[0]!.matches).toHaveLength(1);
|
||||||
|
expect(result.successful_searches[0]!.matches[0]).toEqual({
|
||||||
file: file1Path,
|
file: file1Path,
|
||||||
lineNumber: 2,
|
lineNumber: 2,
|
||||||
content: 'This is a test',
|
content: 'This is a test',
|
||||||
|
@ -66,7 +67,8 @@ describe('grep-search', () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(result.successful_searches[0]?.matches).toHaveLength(3);
|
expect(result.successful_searches[0]).toBeDefined();
|
||||||
|
expect(result.successful_searches[0]!.matches).toHaveLength(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle recursive searches', async () => {
|
it('should handle recursive searches', async () => {
|
||||||
|
@ -92,7 +94,8 @@ describe('grep-search', () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(result.successful_searches[0]?.matches).toHaveLength(2);
|
expect(result.successful_searches[0]).toBeDefined();
|
||||||
|
expect(result.successful_searches[0]!.matches).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle non-existent files', async () => {
|
it('should handle non-existent files', async () => {
|
||||||
|
@ -136,8 +139,10 @@ describe('grep-search', () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(result.successful_searches[0]?.matches).toHaveLength(1);
|
expect(result.successful_searches[0]).toBeDefined();
|
||||||
expect(result.successful_searches[0]?.matches[0]?.content).toBe('word test word');
|
expect(result.successful_searches[0]!.matches).toHaveLength(1);
|
||||||
|
expect(result.successful_searches[0]!.matches[0]).toBeDefined();
|
||||||
|
expect(result.successful_searches[0]!.matches[0]!.content).toBe('word test word');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@ export interface GrepSearchResult {
|
||||||
function executeGrepSearchLocally(search: {
|
function executeGrepSearchLocally(search: {
|
||||||
path: string;
|
path: string;
|
||||||
pattern: string;
|
pattern: string;
|
||||||
recursive: boolean;
|
recursive?: boolean;
|
||||||
ignoreCase: boolean;
|
ignoreCase?: boolean;
|
||||||
invertMatch: boolean;
|
invertMatch?: boolean;
|
||||||
lineNumbers: boolean;
|
lineNumbers?: boolean;
|
||||||
wordMatch: boolean;
|
wordMatch?: boolean;
|
||||||
fixedStrings: boolean;
|
fixedStrings?: boolean;
|
||||||
maxCount?: number | undefined;
|
maxCount?: number;
|
||||||
}): GrepSearchResult {
|
}): GrepSearchResult {
|
||||||
try {
|
try {
|
||||||
if (!existsSync(search.path)) {
|
if (!existsSync(search.path)) {
|
||||||
|
@ -33,12 +33,12 @@ function executeGrepSearchLocally(search: {
|
||||||
|
|
||||||
const grepArgs: string[] = [];
|
const grepArgs: string[] = [];
|
||||||
|
|
||||||
if (search.recursive) grepArgs.push('-r');
|
if (search.recursive ?? false) grepArgs.push('-r');
|
||||||
if (search.ignoreCase) grepArgs.push('-i');
|
if (search.ignoreCase ?? false) grepArgs.push('-i');
|
||||||
if (search.invertMatch) grepArgs.push('-v');
|
if (search.invertMatch ?? false) grepArgs.push('-v');
|
||||||
if (search.lineNumbers) grepArgs.push('-n');
|
if (search.lineNumbers ?? false) grepArgs.push('-n');
|
||||||
if (search.wordMatch) grepArgs.push('-w');
|
if (search.wordMatch ?? false) grepArgs.push('-w');
|
||||||
if (search.fixedStrings) grepArgs.push('-F');
|
if (search.fixedStrings ?? false) grepArgs.push('-F');
|
||||||
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
||||||
|
|
||||||
grepArgs.push(search.pattern);
|
grepArgs.push(search.pattern);
|
||||||
|
@ -60,7 +60,7 @@ function executeGrepSearchLocally(search: {
|
||||||
const matches: Array<{ file: string; lineNumber?: number; content: string }> = [];
|
const matches: Array<{ file: string; lineNumber?: number; content: string }> = [];
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (search.lineNumbers) {
|
if (search.lineNumbers ?? false) {
|
||||||
const match = line.match(/^([^:]+):(\d+):(.*)$/);
|
const match = line.match(/^([^:]+):(\d+):(.*)$/);
|
||||||
if (match?.[1] && match[2] && match[3] !== undefined) {
|
if (match?.[1] && match[2] && match[3] !== undefined) {
|
||||||
matches.push({
|
matches.push({
|
||||||
|
@ -119,13 +119,13 @@ function executeGrepSearchLocally(search: {
|
||||||
export async function executeGrepSearchesLocally(searches: Array<{
|
export async function executeGrepSearchesLocally(searches: Array<{
|
||||||
path: string;
|
path: string;
|
||||||
pattern: string;
|
pattern: string;
|
||||||
recursive: boolean;
|
recursive?: boolean;
|
||||||
ignoreCase: boolean;
|
ignoreCase?: boolean;
|
||||||
invertMatch: boolean;
|
invertMatch?: boolean;
|
||||||
lineNumbers: boolean;
|
lineNumbers?: boolean;
|
||||||
wordMatch: boolean;
|
wordMatch?: boolean;
|
||||||
fixedStrings: boolean;
|
fixedStrings?: boolean;
|
||||||
maxCount?: number | undefined;
|
maxCount?: number;
|
||||||
}>): Promise<{
|
}>): Promise<{
|
||||||
successful_searches: Array<{
|
successful_searches: Array<{
|
||||||
path: string;
|
path: string;
|
||||||
|
@ -213,13 +213,13 @@ export async function executeGrepSearchesLocally(searches: Array<{
|
||||||
export function generateGrepSearchCode(searches: Array<{
|
export function generateGrepSearchCode(searches: Array<{
|
||||||
path: string;
|
path: string;
|
||||||
pattern: string;
|
pattern: string;
|
||||||
recursive: boolean;
|
recursive?: boolean;
|
||||||
ignoreCase: boolean;
|
ignoreCase?: boolean;
|
||||||
invertMatch: boolean;
|
invertMatch?: boolean;
|
||||||
lineNumbers: boolean;
|
lineNumbers?: boolean;
|
||||||
wordMatch: boolean;
|
wordMatch?: boolean;
|
||||||
fixedStrings: boolean;
|
fixedStrings?: boolean;
|
||||||
maxCount?: number | undefined;
|
maxCount?: number;
|
||||||
}>): string {
|
}>): string {
|
||||||
return `
|
return `
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
@ -238,12 +238,12 @@ function executeGrepSearch(search) {
|
||||||
|
|
||||||
const grepArgs = [];
|
const grepArgs = [];
|
||||||
|
|
||||||
if (search.recursive) grepArgs.push('-r');
|
if (search.recursive ?? false) grepArgs.push('-r');
|
||||||
if (search.ignoreCase) grepArgs.push('-i');
|
if (search.ignoreCase ?? false) grepArgs.push('-i');
|
||||||
if (search.invertMatch) grepArgs.push('-v');
|
if (search.invertMatch ?? false) grepArgs.push('-v');
|
||||||
if (search.lineNumbers) grepArgs.push('-n');
|
if (search.lineNumbers ?? false) grepArgs.push('-n');
|
||||||
if (search.wordMatch) grepArgs.push('-w');
|
if (search.wordMatch ?? false) grepArgs.push('-w');
|
||||||
if (search.fixedStrings) grepArgs.push('-F');
|
if (search.fixedStrings ?? false) grepArgs.push('-F');
|
||||||
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
||||||
|
|
||||||
grepArgs.push(search.pattern);
|
grepArgs.push(search.pattern);
|
||||||
|
@ -265,7 +265,7 @@ function executeGrepSearch(search) {
|
||||||
const matches = [];
|
const matches = [];
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (search.lineNumbers) {
|
if (search.lineNumbers ?? false) {
|
||||||
const match = line.match(/^([^:]+):(\\d+):(.*)$/);
|
const match = line.match(/^([^:]+):(\\d+):(.*)$/);
|
||||||
if (match && match[1] && match[2] && match[3] !== undefined) {
|
if (match && match[1] && match[2] && match[3] !== undefined) {
|
||||||
matches.push({
|
matches.push({
|
||||||
|
|
Loading…
Reference in New Issue