rsc-ancestor-walk
the nearest ancestor of a kind found by matching ancestors(n) by hand.
- Group
- Code
- Runs
- On by default
- Level
- warning
- Reads
- Every file
- Fix
- None: the conditions after the match may test more than the kind, so whether
enclosingsays the same is the author's to decide
Why
[*_, a, *_] := ancestors(n), a is Kind finds the nearest ancestor of Kind, which enclosing(n, Kind) gives: the rule says what it means, and the evaluator finds the node without backtracking through every ancestor.
The fix, as Ur suggests it: write enclosing(n, Kind).
For agents
Write enclosing(n, Kind) for the nearest ancestor of a kind, not a list match over ancestors(n).
Example
checks/Owners.rscmodule checks::Owners
Tree owner(Tree n) = f when [*_, f, *_] := ancestors(n), f is Function;
$ ur lint --rule rsc-ancestor-walk
warning[rsc-ancestor-walk]: the nearest ancestor of `n` that is `Function`; write `enclosing(n, Function)`
--> ./checks/Owners.rsc:3:29 `[*_, f, *_] := ancestors(n)`
= hint: write `enclosing(n, Kind)`
0 clone classes and 1 `rsc-ancestor-walk` finding in 1 file