Skip to content

Add CollectionIndexOnNonIndexedSeq rule#159

Merged
sksamuel merged 1 commit intoscapegoat-scala:masterfrom
JoshRosen:index-on-non-indexed-seq
May 21, 2017
Merged

Add CollectionIndexOnNonIndexedSeq rule#159
sksamuel merged 1 commit intoscapegoat-scala:masterfrom
JoshRosen:index-on-non-indexed-seq

Conversation

@JoshRosen
Copy link
Copy Markdown
Contributor

@JoshRosen JoshRosen commented May 20, 2017

Inspired by https://twitter.com/jshrsn/status/865677863646658560, this patch adds a new IndexingOnANonIndexedSeq rule which raises a warning when we see code which indexes on a Seq which isn't known to be an IndexedSeq subtype. The goal here is to make it easier to prevent cases where someone writes an O(n^2) loop by accident.

This rule might have prevented the following Spark bugs:

In order to avoid false-positives from the use of .apply(0) instead of .head I chose to ignore all cases where the index is a literal.

@sksamuel sksamuel merged commit 0f66ecc into scapegoat-scala:master May 21, 2017
@sksamuel
Copy link
Copy Markdown
Collaborator

👍

@JoshRosen JoshRosen deleted the index-on-non-indexed-seq branch May 21, 2017 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants