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

Make some cops aware of safe navigation operator #420

Merged

Conversation

koic
Copy link
Member

@koic koic commented Dec 7, 2023

Fixes #403, #404, #405, #406, #408, #411, #412, #413, #415, #416, and #417.

This PR makes Performance/Count, Performance/FixedSize, Performance/FlatMap, Performance/InefficientHashSearch, Performance/RangeInclude, Performance/RedundantSortBlock, Performance/ReverseFirst, Performance/SelectMap, Performance/Size Performance/SortReverse, and Performance/TimesMap cops aware of safe navigation operator.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Fixes rubocop#403, rubocop#404, rubocop#405, rubocop#406, rubocop#408, rubocop#411, rubocop#412, rubocop#413, rubocop#415, rubocop#416, and rubocop#417.

This PR makes `Performance/Count`, `Performance/FixedSize`, `Performance/FlatMap`,
`Performance/InefficientHashSearch`, `Performance/RangeInclude`, `Performance/RedundantSortBlock`,
`Performance/ReverseFirst`, `Performance/SelectMap`, `Performance/Size` `Performance/SortReverse`,
and `Performance/TimesMap` cops aware of safe navigation operator.
@koic koic merged commit 8834ff4 into rubocop:master Dec 9, 2023
12 checks passed
@koic koic deleted the make_some_cop_aware_of_safe_navigation_operator branch December 9, 2023 01:28
RUBY

expect_correction(<<~RUBY)
Array.new(4) { |i| i.to_s }
Copy link
Contributor

Choose a reason for hiding this comment

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

@koic

There seems to be an error.

ydakuka@yauhenid:~$ irb
2.7.6 :001 > 4&.times&.map(&:to_s)
 => ["0", "1", "2", "3"] 
2.7.6 :002 > Array.new(4) { |i| i.to_s }
 => ["0", "1", "2", "3"] 
2.7.6 :003 > nil&.times&.map(&:to_s)
 => nil 
2.7.6 :004 > Array.new(nil) { |i| i.to_s }
Traceback (most recent call last):
        6: from /home/ydakuka/.rvm/rubies/ruby-2.7.6/bin/irb:23:in `<main>'
        5: from /home/ydakuka/.rvm/rubies/ruby-2.7.6/bin/irb:23:in `load'
        4: from /home/ydakuka/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        3: from (irb):4
        2: from (irb):4:in `new'
        1: from (irb):4:in `initialize'
TypeError (no implicit conversion from nil to integer)

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.

Make Performance/SortReverse aware of safe navigation operator
2 participants