A comment holds code that was switched off
What it finds
Code switched off by turning it into comments stays in the file without being compiled, tested or kept up to date. Version control keeps old code; the comment only leaves a reader to wonder whether it should come back.
A // comment is reported when it reads as a statement: it ends with ;, { or } and contains a call, an assignment or a keyword that starts a statement, or it is a lone closing brace. Prose rarely has that shape. Block comments, which also hold documentation with code examples, are left alone, and so are comments with a lint or compiler directive.
From the rule's source, disabled_code_comment.rs.
export function f(items: number[]) { // const old = items.map((x) => x * 2);tx0 reports: holds code that was switched off // console.log(old);tx0 reports: holds code that was switched off // This explains why the list is sorted. return items.sort();} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:disabled-code-comment" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:disabled-code-comment] reason="..."tx0 explain tx0/ts:disabled-code-comment shows the same in the terminal. Found a false positive? Report it.