Conversation
TODOs include README updates, plus more thinking about interaction with other existing rules.
|
|
||
| case Apply(Select(seq, _apply), List(index)) | ||
| if methodImplements(tree.symbol, SeqLikeApply) | ||
| && !isLiteral(index) |
There was a problem hiding this comment.
The idea behind ignoring Seq.apply(<literal>) was to prevent this rule from masking the UseHeadNotApply rule for things like x(1).
|
Running this on Spark turned up a lot of cases. After manual inspection it looks like most are non-issues, but I may have spotted some bad ones:
Those are just the first two that jump out to me from skimming the results; there may be others which are less obvious. |
Inspired by https://twitter.com/jshrsn/status/865677863646658560, this patch adds a new
IndexingOnANonIndexedSeqrule which raises a warning when we see code which indexes on aSeqwhich isn't known to be anIndexedSeqsubtype. The goal here is to make it easier to prevent cases where someone writes anO(n^2)loop by accident.I'm opening this PR against my own fork rather than upstream because this is still an early draft which needs self-review and testing (plus I don't have time now to get it ready for full upstream standards, such as README documentation and examples, etc.; plus it might not be as generally applicable / useful outside of Spark's needs).
This rule should have prevented the following Spark bugs:
For comparision, here is the same rule implemented in
scapegoat: JoshRosen/scapegoat#1