rsc-descendant-filter

the parts of a node of one kind enumerated as x <- descendants(t), x is Kind.

Group
Code
Runs
On by default
Level
warning
Reads
Every file
Fix
None: a deep match also offers t itself, so whether t can be a Kind is the author's to decide

Why

A deep match, /Kind x := t, offers each part of t that is a Kind, in the order descendants(t) gives them: it says what the walk keeps, and the evaluator tests the kind as it walks. It also offers t itself, which descendants(t) leaves out, so the two are the same wherever t cannot be a Kind.

The fix, as Ur suggests it: write /Kind x := t.

For agents

Write /Kind x := t for the parts of a node of one kind, not x <- descendants(t), x is Kind, wherever t itself cannot be a Kind.

Example

checks/Calls.rsc
module checks::Calls

list[Tree] calls(Function f) = [c | c <- descendants(f), c is MethodCall];
What Ur prints
$ ur lint --rule rsc-descendant-filter
warning[rsc-descendant-filter]: the parts of `f` that are `MethodCall`; write `/MethodCall c := f`
  --> ./checks/Calls.rsc:3:37 `c <- descendants(f)`
  = hint: write `/Kind x := t`
0 clone classes and 1 `rsc-descendant-filter` finding in 1 file

Try it in the playground →