Skip to content

Commit

Permalink
Add RuboCop performance (#884)
Browse files Browse the repository at this point in the history
* Add RuboCop performance

* Fix safe offenses in non-production code

- Performance/RegexpMatch
- Performance/StringIdentifierArgument

* Fix safe offenses in production code

- Performance/BlockGivenWithExplicitBlock
- Performance/RegexpMatch
- Performance/ReverseEach
- Performance/StringReplacement

* Fix unsafe offenses in non-production code

- Performance/StringInclude

* Fix unsafe offenses in production code

- Performance/RedundantMerge

* Test singleton belongs to helper

Use the helper instead of passing the `singleton: true` option for
multiple test cases.
  • Loading branch information
tagliala authored Oct 26, 2023
1 parent 8f4f445 commit 3cc9e41
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 124 deletions.
161 changes: 161 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

require:
- rubocop-performance

AllCops:
DisabledByDefault: true

Expand Down Expand Up @@ -43,5 +46,163 @@ Layout/TrailingWhitespace:
Layout/TrailingEmptyLines:
Enabled: true

Performance:
Enabled: true

Performance/AncestorsInclude:
Enabled: false

Performance/ArraySemiInfiniteRangeSlice:
Enabled: false

Performance/BigDecimalWithNumericArgument:
Enabled: true

Performance/BindCall:
Enabled: true

Performance/BlockGivenWithExplicitBlock:
Enabled: true

Performance/Caller:
Enabled: true

Performance/CaseWhenSplat:
Enabled: true

Performance/Casecmp:
Enabled: false

Performance/ChainArrayAllocation:
Enabled: false

Performance/CollectionLiteralInLoop:
Enabled: true
Exclude:
- spec/**/*

Performance/CompareWithBlock:
Enabled: true

Performance/ConcurrentMonotonicTime:
Enabled: true

Performance/ConstantRegexp:
Enabled: true

Performance/Count:
Enabled: true

Performance/DeletePrefix:
Enabled: true

Performance/DeleteSuffix:
Enabled: true

Performance/Detect:
Enabled: true

Performance/DoubleStartEndWith:
Enabled: true
IncludeActiveSupportAliases: true

Performance/EndWith:
Enabled: true

Performance/FixedSize:
Enabled: true

Performance/FlatMap:
Enabled: true
EnabledForFlattenWithoutParams: false

Performance/InefficientHashSearch:
Enabled: true

Performance/IoReadlines:
Enabled: true

Performance/MapCompact:
Enabled: false

Performance/MapMethodChain:
Enabled: false

Performance/MethodObjectAsBlock:
Enabled: true

Performance/OpenStruct:
Enabled: true

Performance/RangeInclude:
Enabled: true

Performance/RedundantBlockCall:
Enabled: false

Performance/RedundantEqualityComparisonBlock:
Enabled: false

Performance/RedundantMatch:
Enabled: true

Performance/RedundantMerge:
Enabled: true
MaxKeyValuePairs: 2

Performance/RedundantSortBlock:
Enabled: true

Performance/RedundantSplitRegexpArgument:
Enabled: true

Performance/RedundantStringChars:
Enabled: true

Performance/RegexpMatch:
Enabled: true

Performance/ReverseEach:
Enabled: true

Performance/ReverseFirst:
Enabled: true

Performance/SelectMap:
Enabled: false

Performance/Size:
Enabled: true

Performance/SortReverse:
Enabled: true

Performance/Squeeze:
Enabled: true

Performance/StartWith:
Enabled: true

Performance/StringIdentifierArgument:
Enabled: true

Performance/StringInclude:
Enabled: true

Performance/StringReplacement:
Enabled: true

Performance/Sum:
Enabled: false

Performance/TimesMap:
Enabled: true

Performance/UnfreezeString:
Enabled: true

Performance/UriDefaultParser:
Enabled: true

Style/HashSyntax:
Enabled: true
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ end

group :rubocop do
gem 'rubocop'
gem 'rubocop-performance'
end
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ GEM
net-smtp
marcel (1.0.2)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
Expand All @@ -144,6 +145,9 @@ GEM
net-protocol
nio4r (2.5.9)
nio4r (2.5.9-java)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-java)
Expand Down Expand Up @@ -226,6 +230,9 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
Expand Down Expand Up @@ -254,6 +261,7 @@ GEM
PLATFORMS
arm64-darwin-22
java
ruby
x86_64-linux

DEPENDENCIES
Expand All @@ -264,6 +272,7 @@ DEPENDENCIES
rails (~> 7.1.0)
rails-controller-testing
rubocop
rubocop-performance
simplecov
simplecov-cobertura

Expand Down
2 changes: 1 addition & 1 deletion bin/rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/rails_61/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ GEM
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
Expand All @@ -114,6 +115,9 @@ GEM
net-protocol
nio4r (2.5.9)
nio4r (2.5.9-java)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-java)
Expand Down Expand Up @@ -194,6 +198,7 @@ GEM
PLATFORMS
arm64-darwin-22
java
ruby
x86_64-linux

DEPENDENCIES
Expand Down
4 changes: 0 additions & 4 deletions gemfiles/rails_70/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ group :development do
gem 'simplecov', require: false
gem 'simplecov-cobertura'
end

group :rubocop do
gem 'rubocop'
end
32 changes: 5 additions & 27 deletions gemfiles/rails_70/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
base64 (0.1.1)
builder (3.2.4)
concurrent-ruby (1.2.2)
crass (1.0.6)
Expand All @@ -92,9 +90,6 @@ GEM
activesupport (>= 5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
json (2.6.3-java)
language_server-protocol (3.17.0.3)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -106,6 +101,7 @@ GEM
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
minitest-reporters (1.6.1)
ansi
Expand All @@ -125,16 +121,15 @@ GEM
net-protocol
nio4r (2.5.9)
nio4r (2.5.9-java)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-java)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.1)
racc (1.7.1-java)
rack (2.2.8)
Expand Down Expand Up @@ -172,27 +167,11 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.8.2)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rubocop (1.57.1)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
Expand All @@ -208,7 +187,6 @@ GEM
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-driver (0.7.6-java)
Expand All @@ -219,6 +197,7 @@ GEM
PLATFORMS
arm64-darwin-22
java
ruby
x86_64-linux

DEPENDENCIES
Expand All @@ -228,7 +207,6 @@ DEPENDENCIES
mocha
rails (~> 7.0.0)
rails-controller-testing
rubocop
simplecov
simplecov-cobertura

Expand Down
2 changes: 1 addition & 1 deletion lib/inherited_resources/blank_slate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module InheritedResources
# An object from BlankSlate simply discards all messages sent to it.
class BlankSlate
instance_methods.each do |m|
undef_method m unless m =~ /^(__|object_id)/
undef_method m unless /^(__|object_id)/.match?(m)
end

def method_missing(*args)
Expand Down
Loading

0 comments on commit 3cc9e41

Please sign in to comment.