Skip to content

ci: check-empty-catch ignores catch {} inside comments and literals (#213) - #266

Merged
Birfy merged 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/213-empty-catch-literals
Oct 18, 2026
Merged

Birfy merged 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/213-empty-catch-literals

Conversation

@Birfy

@Birfy Birfy commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Part of #213: this is item 2, the mechanical fix. Item 1, the promise-form rule, still needs a decision, so #213 stays open.

What changed. check-empty-catch.mjs now masks the source before it matches. maskSource() returns two copies of the source, each with the same length and line breaks:

  • bare blanks every comment and the inside of every string, template and regex literal. The quotes stay, so a string statement still counts as code.
  • commented blanks only the literals, so the comments can still be read.

A catch {} written inside a comment or a literal is no longer reported.

Also fixed:

  • Brace counting. The block walk now runs on the masked text, so a } inside a string can no longer end a block early.
  • Template expressions. Code inside ${…} is still scanned.

Fail-safe kept. A quote or / that does not close on its own line is treated as code, so a misread costs at most one line and never hides the rest of the file.

Tokenizer check. All 551 tracked .js/.mjs files come out with balanced {} and () after masking. The shipped sources still have no bare catch.

Tests: catch {} in each kind of comment and literal, nested templates, regex literals vs. division, a real bare catch after every kind of literal, } inside a string in the block, a bare catch inside a template expression, an unclosed quote, and UTF-16 length with astral characters. docs/code-standards.md notes the rule. No changelog fragment, because users cannot see this change.

Checks (tip of this branch): TZ=UTC ARCH_DOCS_BASE=upstream/main npm run verify passed (core 803/803, social 185/185, tree 56/56, .github/scripts 81/81, timeline/interop/live-e2e green, arch-docs OK).

Item 1 needs a decision. There are about 51 bare non-void .catch(() => {} | undefined | null) calls in the shipped sources. Many of them, like .catch(() => undefined) used as a value fallback, are deliberate. One possible rule: a .catch(() => {}) whose result is dropped (a statement or an await statement) needs a void prefix or a why-comment, while .catch(() => undefined) used as a value stays allowed. I have not started that.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T04:26:55.992879Z — PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Birfy
Birfy added this pull request to the merge queue Oct 18, 2026
Merged via the queue into ThinkFlowLab:main with commit 372286a Oct 18, 2026
8 checks passed
@Birfy
Birfy deleted the fix/213-empty-catch-literals branch October 18, 2026 04:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const end = closeOnLine(at + 1, char)
if (end !== -1) { blank(at + 1, end); last = char; at = end + 1; continue }
}
if (char === '/' && (last === '' || REGEX_AFTER.has(last) || REGEX_KEYWORDS.test(source.slice(Math.max(0, at - 12), at).trimEnd()))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Distinguish division from regex before masking source

With valid const hit = total / /catch {}/.test(s), the first division leaves last as /, so the second slash is not considered a regex opener and scanSource falsely reports the regex text; valid if (ok) /catch {}/.test(s) has the same result. The heuristic also fails in the other direction: obj.return / value; try {} catch {} /tail/ treats the division after a property named return as a regex and blanks the real empty catch, so the CI gate can both reject valid source and let the prohibited construct ship. Track lexical operand context and add both cases to the regression suite instead of relying on a last character and 12-character suffix.

AGENTS.md reference: AGENTS.md:L18-L18

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant