Skip to content
Closed
6 changes: 6 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"no-console": "error"
}
},
{
"files": ["packages/cli/**/*.{ts,tsx,js,mjs,cjs}"],
"rules": {
"typescript/no-unnecessary-condition": "error"
}
},
{
"files": ["packages/cli/script/**/*.ts"],
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/script/check-doc-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function resolve(
let target: RouteTarget = routes as unknown as RouteMap;
let i = 0;
while (isRouteMap(target)) {
const word = tokens[i];
const word = tokens[i] as string | undefined;
if (word === undefined || word.startsWith("-")) {
const fallback = target.getDefaultCommand?.();
if (fallback && isCommand(fallback)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/script/check-env-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ for (const file of files) {
const content = await readFile(file, "utf-8");
fileContents.set(file, content);
for (const match of content.matchAll(ENV_CONST_RE)) {
const value = match[2] ?? match[3];
const value = match[2] || match[3];
if (value && isUserFacing(value)) {
constMap.set(match[1], value);
}
Expand All @@ -139,7 +139,7 @@ for (const [file, content] of fileContents) {
for (const match of content.matchAll(ENV_BRACKET_RE)) {
const ident = match[3];
const name =
match[1] ?? match[2] ?? (ident ? constMap.get(ident) : undefined);
match[1] || match[2] || (ident ? constMap.get(ident) : undefined);
if (name) {
record(name, file, content, match.index);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/script/check-installer-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Installer = {
};

function matchAll(re: RegExp, text: string): Set<string> {
return new Set([...text.matchAll(re)].map((m) => m[1] ?? ""));
return new Set([...text.matchAll(re)].map((m) => m[1]));
}

async function loadBash(): Promise<Installer> {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/script/generate-docs-sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ function readGrammarAnnotations(lines: string[]): GrammarAnnotation[] {
annotations.push({
start: index + 1,
end: index + 1,
kind: annotation[1] ?? "",
text: annotation[2] ?? "",
kind: annotation[1],
text: annotation[2],
});
} else if (continuation && previous?.end === index) {
previous.text += ` ${continuation[1]}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/script/generate-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function inferFlagType(def: FlagDef): {

/** Extract SDK-relevant flag info from a Stricli Command's parameters. */
function extractSdkFlags(command: Command): SdkFlagInfo[] {
const flagDefs = command.parameters?.flags;
const flagDefs = command.parameters.flags;
if (!flagDefs) {
return [];
}
Expand Down Expand Up @@ -211,7 +211,7 @@ type PositionalInfo =
| { name: string; variadic: true };

function derivePositional(command: Command): PositionalInfo {
const params = command.parameters?.positional;
const params = command.parameters.positional;
if (!params) {
return null;
}
Expand All @@ -222,7 +222,7 @@ function derivePositional(command: Command): PositionalInfo {
return { name, variadic: true };
}

if (params.kind === "tuple" && params.parameters.length > 0) {
if (params.parameters.length > 0) {
// One param per tuple entry. A compound placeholder is a single entry whose own parser
// splits it ("org/version" → orgVersion), but separate entries are separate argv tokens:
// joining them into one param made every multi-positional command unusable, because the
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/script/lib/output-schema-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ function valibotTypeToString(input: ValibotSchemaNode): {
} {
// Resolve `pipe(...)` schemas (incl. the coercion pattern) to their output
// schema before inspecting the type.
const schema = input ? unwrapPipe(input) : input;
if (!schema?.type) {
return { type: "unknown", optional: false };
}
const schema = unwrapPipe(input);
Comment thread
BYK marked this conversation as resolved.
Resolved

// Unwrap wrapper types recursively.
if (schema.type === "optional" && schema.wrapped) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/script/sdk-run-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function exampleTagBodies(comment: string): string[] {
true,
ts.ScriptKind.TS,
);
const statement = source.statements[0];
const statement = source.statements[0] as ts.Statement | undefined;
if (!statement) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/script/text-import-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const textImportPlugin: Plugin = {
}));

build.onResolve({ filter: ANY_FILTER }, (args) => {
if (args.with?.type === "text") {
if (args.with.type === "text") {
return {
path: resolvePath(args.resolveDir, args.path),
namespace: TEXT_IMPORT_NS,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/alert/issues/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export const editCommand = buildCommand({
...updated,
org: target.org,
project: target.project,
id: stringifyUnknown(updated.id ?? rule.id),
id: stringifyUnknown(updated.id),
// The workflows endpoint returns `enabled` rather than `status`; map it
// back to a status label so human/JSON output matches the create path.
status: !updated.enabled ? "disabled" : "active",
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/alert/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ async function handleResolvedTargets(
);
const filteredRows = flags.query
? allRows.filter((row) =>
(row.rule.name ?? "")
.toLowerCase()
.includes(flags.query?.toLowerCase() ?? ""),
row.rule.name.toLowerCase().includes(flags.query?.toLowerCase() ?? ""),
)
: allRows;

Expand Down Expand Up @@ -453,7 +451,7 @@ function formatIssueAlertListHuman(result: IssueAlertListResult): string {

const tableRows: Row[] = rows.map(({ rule: r, target }) => ({
id: r.id,
name: tableCell(r.name ?? "(untitled)"),
name: tableCell(r.name),
...(isMultiProject && {
project: `${target.org}/${target.project}`,
}),
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/alert/metrics/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ export const createCommand = buildCommand({
dataset,
timeWindow: flags["time-window"],
triggers,
projects,
};
if (projects && projects.length > 0) {
body.projects = projects;
}
if (flags.environment !== undefined) {
body.environment = flags.environment;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/alert/metrics/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export const editCommand = buildCommand({
yield new CommandOutput({
...updated,
org: orgSlug,
id: stringifyUnknown(updated.id ?? rule.id),
id: stringifyUnknown(updated.id),
// The detectors endpoint returns `enabled` rather than `status`.
status: !updated.enabled ? "disabled" : "active",
} satisfies MetricAlertEditOutput);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/alert/metrics/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
);
const filteredRows = flags.query
? allRows.filter((row) =>
(row.rule.name ?? "")
((row.rule.name as string | null) ?? "")
.toLowerCase()
.includes(flags.query?.toLowerCase() ?? ""),
)
Expand Down Expand Up @@ -464,7 +464,7 @@

const tableRows: Row[] = rows.map(({ rule: r, orgSlug }) => ({
id: r.id,
name: tableCell(r.name ?? "(untitled)"),
name: tableCell(r.name),

Check warning on line 467 in packages/cli/src/commands/alert/metrics/list.ts

View check run for this annotation

@sentry/warden / warden: code-review

Null metric alert name crashes human list output

When the detectors API returns a null `name`, human-formatted `alert metrics list` passes it to `tableCell()` and throws a `TypeError` instead of displaying the rule.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null metric alert name crashes human list output

When the detectors API returns a null name, human-formatted alert metrics list passes it to tableCell() and throws a TypeError instead of displaying the rule.

Evidence
  • listMetricAlertsPaginated treats the detector response as MetricDetector[] without runtime validation, and mapDetectorToMetricAlertRule copies detector.name; test/commands/alert/metrics/list.test.ts supplies a detector with name: null.
  • Human output maps display rows through tableCell(r.name) with no null fallback. tableCell calls toSingleLine, which calls value.replace, so a null name throws.
  • The existing null-name test filters in JSON mode; it does not cover the unfiltered human-output path.

Identified by Warden · code-review · SX4-WJ2

...(isMultiOrg && { org: orgSlug }),
aggregate: r.aggregate,
dataset: r.dataset,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ function parseUrlEncodedParams(
* @internal Exported for testing
*/
export function dataToQueryParams(
data: Record<string, unknown> | unknown[] | string,
data: unknown,
): Record<string, string | string[]> {
if (typeof data === "string") {
return parseUrlEncodedParams(data);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/cli/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export const defaultsCommand = buildCommand({
if (canonical === "telemetry") {
const effective = computeTelemetryEffective();
if (
effective?.source.startsWith("env:") &&
effective.source.startsWith("env:") &&
effective.enabled !== (newValue === "on")
) {
log.warn(
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/cli/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,13 +1360,15 @@ export const upgradeCommand = buildCommand({
database,
});
} else {
// Library mode's process stand-in has no argv.
const argv = this.process.argv as readonly string[] | undefined;
await executeStandardUpgrade({
method,
channel,
versionArg,
target,
execPath: this.process.execPath,
entryPath: this.process.argv?.[1],
entryPath: argv?.[1],
pathEnv: this.process.env.PATH,
offline,
json: flags.json,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dashboard/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function resolveDashboardId(
* @returns Resolved widget index
*/
export function resolveWidgetIndex(
widgets: DashboardWidget[],
widgets: readonly { title?: string }[],
index: number | undefined,
title: string | undefined,
): number {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dashboard/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export const viewCommand = buildCommand({

// Library mode: honor external abort signal (e.g., consumer break)
const externalSignal = (this.process as { abortSignal?: AbortSignal })
?.abortSignal;
.abortSignal;
if (externalSignal) {
externalSignal.addEventListener("abort", stop, { once: true });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/event/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function buildFilePayload(
try {
const firstLine = new TextDecoder().decode(bytes).split("\n")[0] ?? "{}";
const header = JSON.parse(firstLine) as Record<string, unknown>;
eventId = (header.event_id as string) ?? "";
eventId = typeof header.event_id === "string" ? header.event_id : "";
} catch (err) {
log.debug("Could not extract event_id from envelope header", err);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/feedback/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const viewCommand = buildCommand({
: [];

yield new CommandOutput({
org: org ?? null,
org,
feedback,
event: event ?? null,
replayIds,
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/commands/issue/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,11 +1613,7 @@ function jsonTransformIssueList(
const transformed = jsonTransformListResult(result, fields);
// Only inject into empty paginated envelopes — helps agents discover
// query syntax when their search returned nothing.
if (
transformed &&
typeof transformed === "object" &&
!Array.isArray(transformed)
) {
if (!Array.isArray(transformed)) {
const envelope = transformed as Record<string, unknown>;
const data = envelope.data;
if (Array.isArray(data) && data.length === 0) {
Expand Down Expand Up @@ -1801,7 +1797,7 @@ export const listCommand = buildListCommand("issue", {
const displayRows: IssueTableRow[] = [
{
issue,
orgSlug: org ?? "",
orgSlug: org,
formatOptions: {
projectSlug: issue.project?.slug ?? "",
isMultiProject: false,
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/issue/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function mapIssueArgsConcurrently<T>(

const values: T[] = [];
for (const result of settled) {
if (result?.status === "fulfilled") {
if (result.status === "fulfilled") {
values.push(result.value);
}
}
Expand Down Expand Up @@ -308,8 +308,8 @@ async function resolveProjectSearchFallback(
// due to a transient error (5xx, timeout); retrying here either succeeds
// or propagates the real error to the user.
const matchedProject = projects[0];
const matchedOrg = matchedProject?.orgSlug;
if (matchedOrg && matchedProject) {
if (matchedProject?.orgSlug) {
const matchedOrg = matchedProject.orgSlug;
const retryShortId = expandToFullShortId(suffix, matchedProject.slug);
const issue = await getIssueByShortId(matchedOrg, retryShortId, {
collapse: ISSUE_DETAIL_COLLAPSE,
Expand Down Expand Up @@ -348,9 +348,7 @@ async function findIssuesByShortId(
// Only throw when ALL results are errors — if some orgs returned clean
// 404s ({ok: true, value: null}), fall through to the fallback for a
// precise error message.
const realErrors = results.filter(
(r): r is AuthGuardFailure => r !== undefined && !r.ok,
);
const realErrors = results.filter((r): r is AuthGuardFailure => !r.ok);
if (realErrors.length === results.length && realErrors.length > 0) {
const firstError = realErrors[0]?.error;
if (firstError instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/issue/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async function buildSingleIssueViewData(
: await fetchIssueDetails(orgSlug, issue.id, spans);

return {
org: orgSlug ?? null,
org: orgSlug,
issue,
event: event ?? null,
...details,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/local/control-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export function createLocalControlPlane({
contentType: container.getContentType(),
itemTypes:
parsed?.envelope[1]
.map((item) =>
.map((item: unknown) =>
Array.isArray(item) && typeof item[0] === "object" && item[0]
? stringifyUnknown(
(item[0] as { type?: unknown }).type ?? "unknown",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/local/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function startupLockPath(directory: string): string {
function shutdownServer(server: Server): Promise<void> {
return new Promise((resolve) => {
server.close(() => resolve());
server.closeAllConnections?.();
server.closeAllConnections();
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/local/receiver-ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function readReceiverBody(
const chunks: Uint8Array[] = [];
let size = 0;
try {
while (true) {
for (;;) {
const { done, value } = await reader.read();
if (done) return Buffer.concat(chunks, size);
size += value.byteLength;
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/local/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ async function gracefulKill(child: ChildProcess): Promise<void> {
}),
]);
clearTimeout(graceTimer);
// oxlint-disable-next-line typescript/no-unnecessary-condition -- exitCode changes while awaiting; TS keeps the earlier narrowing
if (!exited && child.exitCode === null) {
try {
child.kill("SIGKILL");
Expand All @@ -705,6 +706,7 @@ async function gracefulKill(child: ChildProcess): Promise<void> {
}
// Only await close if the child hasn't exited yet — avoids hanging
// if close fired between SIGKILL and listener attachment.
// oxlint-disable-next-line typescript/no-unnecessary-condition -- exitCode changes while awaiting; TS keeps the earlier narrowing
if (child.exitCode === null) {
await new Promise<void>((r) => child.on("close", () => r()));
}
Expand Down Expand Up @@ -775,7 +777,7 @@ async function* runWithVerify(
);
}

let signalReceived: NodeJS.Signals | null = null;
let signalReceived = null as NodeJS.Signals | null;
const onSigint = () => {
signalReceived = "SIGINT";
child.kill("SIGINT");
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/local/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
},
});

// oxlint-disable-next-line typescript/no-unnecessary-condition -- the signal can abort during the await; TS keeps the loop condition's narrowing
if (signal.aborted || result === "retained") {
return;
}
Expand Down Expand Up @@ -828,7 +829,7 @@ export async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
async function attemptSSEConnection(
opts: ConsumeSSEOnceOptions,
): Promise<"no-connection" | "connected-then-lost" | "retained"> {
let wasConnected = false;
let wasConnected = false as boolean;
const augmented = {
...opts,
onConnected: () => {
Expand Down Expand Up @@ -909,7 +910,7 @@ async function consumeSSEOnce(

const decoder = new TextDecoder();
const state: SSEParserState = { eventType: "", dataLines: [], id: "" };
let retained = false;
let retained = false as boolean;
const onEvent = (type: string, data: string, id: string) => {
if (id) {
onId(id);
Expand Down
Loading
Loading