From 0e2c1a1469a79340c60504ccca799176b06a1834 Mon Sep 17 00:00:00 2001 From: RobertLD Date: Sat, 21 Mar 2026 20:31:25 -0400 Subject: [PATCH] fix(quality): eliminate negated conditions in ternary expressions (S7735) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flip four ternaries from negative-condition form to positive-condition form: - src/cli/index.ts: `documentCount !== 1 ? "s" : ""` → `=== 1 ? "" : "s"` - src/connectors/docs.ts: `closeIdx === -1 ? null : slice(...)` → `!== -1 ? slice(...) : null` - src/core/link-extractor.ts: `pipeIdx === -1 ? inner : slice(...)` → `!== -1 ? slice(...) : inner` - src/core/spider.ts: `close === -1 ? input.length : close + 1` → `!== -1 ? close + 1 : input.length` Closes #471 Co-Authored-By: Claude Sonnet 4.6 --- src/cli/index.ts | 2 +- src/connectors/docs.ts | 2 +- src/core/link-extractor.ts | 2 +- src/core/spider.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index 63c9fd1..4f270a8 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1385,7 +1385,7 @@ tagCmd console.log("No tags found. Add tags with: libscope tag add "); } else { for (const t of allTags) { - console.log(` ${t.name} (${t.documentCount} doc${t.documentCount !== 1 ? "s" : ""})`); + console.log(` ${t.name} (${t.documentCount} doc${t.documentCount === 1 ? "" : "s"})`); } } } finally { diff --git a/src/connectors/docs.ts b/src/connectors/docs.ts index eff388f..b467175 100644 --- a/src/connectors/docs.ts +++ b/src/connectors/docs.ts @@ -302,7 +302,7 @@ export function extractElementByPattern( if (matchesAttr) { const contentStart = m.index + m[0].length; const closeIdx = findClosingTagIndex(html, tagName, contentStart); - return closeIdx === -1 ? null : html.slice(contentStart, closeIdx); + return closeIdx >= 0 ? html.slice(contentStart, closeIdx) : null; } } diff --git a/src/core/link-extractor.ts b/src/core/link-extractor.ts index f0c546b..aa66f78 100644 --- a/src/core/link-extractor.ts +++ b/src/core/link-extractor.ts @@ -201,7 +201,7 @@ export function extractWikilinks(content: string): string[] { if (!inner.includes("[[")) { // [[PageName|alias]] → extract PageName (before the pipe) const pipeIdx = inner.indexOf("|"); - const pageName = (pipeIdx === -1 ? inner : inner.slice(0, pipeIdx)).trim(); + const pageName = (pipeIdx >= 0 ? inner.slice(0, pipeIdx) : inner).trim(); if (pageName) { seen.add(pageName); } diff --git a/src/core/spider.ts b/src/core/spider.ts index d581d3b..90700c6 100644 --- a/src/core/spider.ts +++ b/src/core/spider.ts @@ -234,7 +234,7 @@ function scanPastTag(input: string, start: number): number { if (ch === ">") return i + 1; if (ch === '"' || ch === "'") { const close = input.indexOf(ch, i + 1); - i = close === -1 ? input.length : close + 1; + i = close >= 0 ? close + 1 : input.length; } else { i++; }