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

rubocop: fix the Performance/TimesMap cop offenses #33

Merged
merged 1 commit into from
Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ Style/PredicateName:

Metrics/ClassLength:
Max: 120

Performance/TimesMap:
Enabled: true
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
Performance/TimesMap:
Exclude:
- 'benchmarks/payload_truncator.rb'
- 'benchmarks/payload_truncator_string_encoding.rb'

# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/payload_truncator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Generates example errors that should be truncated.
class Payload
def self.generate
5000.times.map do |i|
Array.new(5000) do |i|
{ type: "Error#{i}",
message: 'X' * 300,
backtrace: 300.times.map { 'Y' * 300 } }
backtrace: Array.new(300) { 'Y' * 300 } }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/payload_truncator_string_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def mixed
part = MAX / methods.size

methods.each do |method|
strings << part.times.map { StringGenerator.__send__(method) }
strings << Array.new(part) { StringGenerator.__send__(method) }
end

strings.flatten
Expand All @@ -89,7 +89,7 @@ def best
private

def generate(&block)
MAX.times.map(&block)
Array.new(MAX, &block)
end
end
end
Expand Down