rsc-spelled-comparison

a node's text compared with a literal, as unparse(x) == "pub".

Group
Code
Runs
On by default
Level
warning
Reads
Every file
Fix
--fix fixes it: compares the node itself, which compares what it spells

Why

A node compared with a str is compared by what it spells, so x == "pub" holds where unparse(x) == "pub" does, and x in {"a", "b"} where unparse(x) in {"a", "b"} does: the unparse only says again what the comparison already does.

The fix, as Ur suggests it: drop the unparse.

For agents

Compare a node with a string literal, or a set of them, directly: write x == "pub", not unparse(x) == "pub".

Example

checks/Names.rsc
module checks::Names

bool isMain(Function f) = unparse(f.name) == "main";
What Ur prints
$ ur lint --rule rsc-spelled-comparison
warning[rsc-spelled-comparison]: write `f.name == "main"`
  --> ./checks/Names.rsc:3:27 `unparse(f.name) == "main"`
  = hint: drop the `unparse`; `--fix` does this
0 clone classes and 1 `rsc-spelled-comparison` finding in 1 file

Try it in the playground →