Skip to content

Commit 66f563d

Browse files
author
Eric Wheeler
committed
fix: replace implicit coercions with explicit boolean checks
Replace implicit boolean coercions (git diff --staged | catvariable) with explicit type-aware checks to satisfy the no-implicit-coercion ESLint rule. Also add debug logging to empty blocks to satisfy the no-empty rule. - Use type-specific checks (typeof x === 'string') for string variables - Use explicit comparisons (x === true) for boolean variables - Remove redundant null checks for variables that can't be null - Add console.debug statements to empty catch blocks Signed-off-by: Eric Wheeler <[email protected]>
1 parent 2ebad97 commit 66f563d

38 files changed

+137
-64
lines changed

src/api/providers/__tests__/openai.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ describe("OpenAiHandler", () => {
174174
const stream = reasoningHandler.createMessage(systemPrompt, messages)
175175
// Consume the stream to trigger the API call
176176
for await (const _chunk of stream) {
177+
console.debug("Consuming stream for reasoning test")
177178
}
178179
// Assert the mockCreate was called with reasoning_effort
179180
expect(mockCreate).toHaveBeenCalled()
@@ -191,6 +192,7 @@ describe("OpenAiHandler", () => {
191192
const stream = noReasoningHandler.createMessage(systemPrompt, messages)
192193
// Consume the stream to trigger the API call
193194
for await (const _chunk of stream) {
195+
console.debug("Consuming stream for no-reasoning test")
194196
}
195197
// Assert the mockCreate was called without reasoning_effort
196198
expect(mockCreate).toHaveBeenCalled()

src/api/providers/vscode-lm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan
291291
if (!this.client) {
292292
console.debug("Roo Code <Language Model API>: Getting client with options:", {
293293
vsCodeLmModelSelector: this.options.vsCodeLmModelSelector,
294-
hasOptions: !!this.options,
294+
hasOptions: true, // this.options is guaranteed to be an ApiHandlerOptions object
295295
selectorKeys: this.options.vsCodeLmModelSelector ? Object.keys(this.options.vsCodeLmModelSelector) : [],
296296
})
297297

src/core/condense/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export async function summarizeConversation(
9393
TelemetryService.instance.captureContextCondensed(
9494
taskId,
9595
isAutomaticTrigger ?? false,
96-
!!customCondensingPrompt?.trim(),
97-
!!condensingApiHandler,
96+
typeof customCondensingPrompt === "string" && customCondensingPrompt.trim() !== "",
97+
condensingApiHandler !== undefined,
9898
)
9999

100100
const response: SummarizeResponse = { messages, cost: 0, summary: "" }

src/core/config/ContextProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class ContextProxy {
205205

206206
await this.setValues({
207207
...PROVIDER_SETTINGS_KEYS.filter((key) => !isSecretStateKey(key))
208-
.filter((key) => !!this.stateCache[key])
208+
.filter((key) => this.stateCache[key] != null)
209209
.reduce((acc, key) => ({ ...acc, [key]: undefined }), {} as ProviderSettings),
210210
...values,
211211
})

src/core/config/importExport.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@ export const exportSettings = async ({ providerSettingsManager, contextProxy }:
117117
const dirname = path.dirname(uri.fsPath)
118118
await fs.mkdir(dirname, { recursive: true })
119119
await fs.writeFile(uri.fsPath, JSON.stringify({ providerProfiles, globalSettings }, null, 2), "utf-8")
120-
} catch (e) {}
120+
} catch (e) {
121+
console.debug("Error exporting settings:", e)
122+
}
121123
}

src/core/tools/executeCommandTool.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ export async function executeCommand(
171171
message = { text, images }
172172
process.continue()
173173
}
174-
} catch (_error) {}
174+
} catch (_error) {
175+
console.debug("Error in onWillRespond:", _error)
176+
}
175177
},
176178
onCompleted: (output: string | undefined) => {
177179
result = Terminal.compressTerminalOutput(output ?? "", terminalOutputLineLimit)
@@ -197,7 +199,12 @@ export async function executeCommand(
197199
}
198200
}
199201

200-
const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, !!customCwd, cline.taskId, terminalProvider)
202+
const terminal = await TerminalRegistry.getOrCreateTerminal(
203+
workingDir,
204+
typeof customCwd === "string" && customCwd !== "",
205+
cline.taskId,
206+
terminalProvider,
207+
)
201208

202209
if (terminal instanceof Terminal) {
203210
terminal.terminal.show(true)

src/core/tools/writeToFileTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function writeToFileTool(
123123
const isNewFile = !fileExists
124124

125125
// Check if diffStrategy is enabled
126-
const diffStrategyEnabled = !!cline.diffStrategy
126+
const diffStrategyEnabled = cline.diffStrategy !== undefined
127127

128128
// Use more specific error message for line_count that provides guidance based on the situation
129129
await cline.say(

src/core/webview/ClineProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export class ClineProvider
825825
}
826826

827827
public hasProviderProfileEntry(name: string): boolean {
828-
return !!this.getProviderProfileEntry(name)
828+
return this.getProviderProfileEntry(name) !== undefined
829829
}
830830

831831
async upsertProviderProfile(
@@ -1656,7 +1656,7 @@ export class ClineProvider
16561656
apiProvider: apiConfiguration?.apiProvider,
16571657
modelId: task?.api?.getModel().id,
16581658
diffStrategy: task?.diffStrategy?.getName(),
1659-
isSubtask: task ? !!task.parentTask : undefined,
1659+
isSubtask: task ? task.parentTask !== undefined : undefined,
16601660
}
16611661
}
16621662
}

src/core/webview/webviewMessageHandler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
629629
// Send the result back to the webview
630630
await provider.postMessageToWebview({
631631
type: "browserConnectionResult",
632-
success: !!chromeHostUrl,
632+
success: typeof chromeHostUrl === "string" && chromeHostUrl !== "",
633633
text: `Auto-discovered and tested connection to Chrome: ${chromeHostUrl}`,
634634
values: { endpoint: chromeHostUrl },
635635
})
@@ -1008,7 +1008,10 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
10081008
// Try to get enhancement config first, fall back to current config.
10091009
let configToUse: ProviderSettings = apiConfiguration
10101010

1011-
if (enhancementApiConfigId && !!listApiConfigMeta.find(({ id }) => id === enhancementApiConfigId)) {
1011+
if (
1012+
enhancementApiConfigId &&
1013+
listApiConfigMeta.find(({ id }) => id === enhancementApiConfigId) !== undefined
1014+
) {
10121015
const { name: _, ...providerSettings } = await provider.providerSettingsManager.getProfile({
10131016
id: enhancementApiConfigId,
10141017
})

src/integrations/misc/open-file.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ export async function openFile(filePath: string, options: OpenFileOptions = {})
138138
break
139139
}
140140
}
141-
} catch {} // not essential, sometimes tab operations fail
141+
} catch (e) {
142+
console.debug("Error processing tab operations:", e)
143+
} // not essential, sometimes tab operations fail
142144

143145
const document = await vscode.workspace.openTextDocument(uriToProcess)
144146
const selection =

0 commit comments

Comments
 (0)