Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #163] Detect array indexes for Performance/Detect #167

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

dvandersluis
Copy link
Member

[1, 2, 3].detect{ ... }[0] and [1, 2, 3].detect{ ... }[-1] will now be caught and corrected by the cop as if they were first and last.

Fixes #163.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@dvandersluis dvandersluis force-pushed the detect-indexed branch 3 times, most recently from 99f79c6 to 0ac774b Compare September 11, 2020 16:13
@@ -30,5 +30,6 @@ Gem::Specification.new do |s|
}

s.add_runtime_dependency('rubocop', '>= 0.87.0')
s.add_runtime_dependency('rubocop-ast', '>= 0.4.0')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was necessary to use Sets inside node patterns on ruby 2.4. Please see rubocop/rubocop-ast#107 for more details.

For example, `[1, 2, 3].detect{ ... }[0]` will now be caught and corrected by the cop.
@dvandersluis
Copy link
Member Author

@koic are anything other changes necessary here?

@koic koic merged commit 6d7e45f into rubocop:master Sep 16, 2020
@koic
Copy link
Member

koic commented Sep 16, 2020

Yeah, this looks good. Thank you!

koic added a commit that referenced this pull request Oct 20, 2020
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.

Performance/Detect does not work with [0] or [-1]
3 participants