A constant or an imported binding is assigned, which throws when it runs
What it finds
const limit = 10; ... limit = 20; or import { count } from "./state"; count += 1;: constants and the bindings an ES module imports cannot be changed, and assigning to either throws a TypeError when the line runs. TypeScript rejects both when compiling; in JavaScript they show only at run time.
Plain and compound assignments, increments and destructuring assignments count. So do using declarations, TypeScript's import x = ... aliases, and writes to a member of a namespace import, as config.debug = true after import * as config, whose members are read-only as well.
From the rule's source, read_only_assign.rs.
import { count } from "./state";import * as config from "./config";import local from "./local";export function bump(items: number[]) { count += 1;tx0 reports: count is imported and cannot be assigned config.debug = true;tx0 reports: config.debug belongs to an imported namespace and cannot be assigned local.value = 2; const total = 0; for (const item of items) { total += item;tx0 reports: total is a constant and cannot be assigned } let other = 0; other = 1; return config.debug && count + total + other;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/ts:read-only-assign" = "off"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:read-only-assign] reason="..."tx0 explain tx0/ts:read-only-assign shows the same in the terminal. Found a false positive? Report it.