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

Rubocops compatible with Ruby 2.4+ #1840

Merged
merged 14 commits into from
Mar 1, 2023
Merged
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Performance/StringIdentifierArgument: # new in 1.13
Enabled: true
Performance/StringInclude: # new in 1.7
Enabled: true
Performance/Sum: # new in 1.8
Enabled: true


# Old cops
Expand Down
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ Minitest/EmptyLineBeforeAssertionMethods:
- 'test/new_relic/agent_test.rb'
- 'test/new_relic/cli/commands/deployments_test.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: OnlySumOrWithInitialValue.
Performance/Sum:
Exclude:
- 'lib/new_relic/agent/system_info.rb'

# Offense count: 72
# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/UnfreezeString:
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/agent/system_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def self.parse_cpuinfo(cpuinfo)

num_physical_packages = cores.keys.map(&:first).uniq.size
num_physical_cores = cores.size
num_logical_processors = cores.values.reduce(0, :+)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This cop is unsafe if sum is called on an object that doesn't have a sum method, such as a String. cores.values should always be an array of integers based on the default values of the Hash defined on line 110

num_logical_processors = cores.values.sum

if num_physical_cores == 0
num_logical_processors = total_processors
Expand Down