Refactor: Eliminate no-unsafe-return suppressions via strict type validation (#20668)

Signed-off-by: M-DEV-1 <mahadevankizhakkedathu@gmail.com>
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
mahadevan
2026-05-13 05:15:58 +05:30
committed by GitHub
parent 8f03aa320e
commit 31d5947d37
23 changed files with 184 additions and 115 deletions
@@ -9,7 +9,7 @@ import picomatch from 'picomatch';
import { loadIgnoreRules, type Ignore } from './ignore.js';
import { ResultCache } from './result-cache.js';
import { crawl } from './crawler.js';
import { AsyncFzf, type FzfResultItem } from 'fzf';
import { AsyncFzf } from 'fzf';
import { unescapePath } from '../paths.js';
import type { FileDiscoveryService } from '../../services/fileDiscoveryService.js';
import { FileWatcher, type FileWatcherEvent } from './fileWatcher.js';
@@ -270,7 +270,7 @@ class RecursiveFileSearch implements FileSearch {
pattern = unescapePath(pattern) || '*';
let filteredCandidates;
let filteredCandidates: string[];
const { files: candidates, isExactMatch } =
await this.resultCache.get(pattern);
@@ -282,17 +282,27 @@ class RecursiveFileSearch implements FileSearch {
if (pattern.includes('*') || !this.fzf) {
filteredCandidates = await filter(candidates, pattern, options.signal);
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
filteredCandidates = await this.fzf
.find(pattern)
.then((results: Array<FzfResultItem<string>>) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
results.map((entry: FzfResultItem<string>) => entry.item),
)
.catch(() => {
try {
const fzfResult: unknown = await this.fzf.find(pattern);
if (Array.isArray(fzfResult)) {
filteredCandidates = fzfResult.map((entry: unknown) => {
if (
typeof entry === 'object' &&
entry !== null &&
'item' in entry
) {
return String((entry as { item: unknown }).item);
}
return String(entry);
});
} else {
shouldCache = false;
return [];
});
filteredCandidates = [];
}
} catch {
shouldCache = false;
filteredCandidates = [];
}
}
if (shouldCache) {
+2 -4
View File
@@ -27,8 +27,7 @@ export function safeJsonStringify(
}
seen.add(value);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
return value as unknown;
},
space,
);
@@ -61,8 +60,7 @@ export function safeJsonStringifyBooleanValuesOnly(obj: any): string {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
if ((value as Config) !== null && !configSeen) {
configSeen = true;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
return value as unknown;
}
if (typeof value === 'boolean') {
return value;