diff --git a/.rubocop.yml b/.rubocop.yml index 3c74ba85..ad6b2331 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,8 @@ --- -require: rubocop-packaging +require: + - rubocop-packaging + - rubocop-performance AllCops: DisabledByDefault: true @@ -25,6 +27,164 @@ Layout/TrailingEmptyLines: Layout/TrailingWhitespace: 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/FrozenStringLiteralComment: Enabled: true Exclude: diff --git a/Gemfile b/Gemfile index 28ef3ca6..d904da94 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ end group :rubocop do gem 'rubocop' gem 'rubocop-packaging' + gem 'rubocop-performance' end group :rails do diff --git a/Gemfile.lock b/Gemfile.lock index bb0a3960..9d0f076e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -257,6 +257,9 @@ GEM parser (>= 3.2.1.0) rubocop-packaging (0.5.2) rubocop (>= 1.33, < 2.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) @@ -301,6 +304,7 @@ DEPENDENCIES rspec-rails rubocop rubocop-packaging + rubocop-performance simplecov simplecov-cobertura diff --git a/gemfiles/rails_61/Gemfile b/gemfiles/rails_61/Gemfile index 0a4eb15d..960dc8cd 100644 --- a/gemfiles/rails_61/Gemfile +++ b/gemfiles/rails_61/Gemfile @@ -10,11 +10,6 @@ group :test do gem 'pry' end -group :rubocop do - gem 'rubocop' - gem 'rubocop-packaging' -end - group :rails do gem 'rails', '~> 6.1.0' gem 'rspec-rails' diff --git a/gemfiles/rails_61/Gemfile.lock b/gemfiles/rails_61/Gemfile.lock index dcabd615..90308b10 100644 --- a/gemfiles/rails_61/Gemfile.lock +++ b/gemfiles/rails_61/Gemfile.lock @@ -69,8 +69,6 @@ GEM zeitwerk (~> 2.3) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) - ast (2.4.2) - base64 (0.1.1) builder (3.2.4) capybara (3.39.2) addressable @@ -98,9 +96,6 @@ GEM activesupport (>= 6.1) 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.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -131,10 +126,6 @@ GEM racc (~> 1.4) nokogiri (1.15.4-java) racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.4) - ast (~> 2.4.1) - racc pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -176,7 +167,6 @@ GEM method_source rake (>= 12.2) thor (~> 1.0) - rainbow (3.1.1) rake (13.0.6) regexp_parser (2.8.2) rexml (3.2.6) @@ -201,23 +191,6 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - 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) - rubocop-packaging (0.5.2) - rubocop (>= 1.33, < 2.0) - ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.22.0) docile (~> 1.1) @@ -241,7 +214,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) @@ -264,8 +236,6 @@ DEPENDENCIES rake rspec rspec-rails - rubocop - rubocop-packaging simplecov simplecov-cobertura diff --git a/gemfiles/rails_70/Gemfile b/gemfiles/rails_70/Gemfile index a562713b..dfe47c03 100644 --- a/gemfiles/rails_70/Gemfile +++ b/gemfiles/rails_70/Gemfile @@ -10,11 +10,6 @@ group :test do gem 'pry' end -group :rubocop do - gem 'rubocop' - gem 'rubocop-packaging' -end - group :rails do gem 'rails', '~> 7.0.8' gem 'rspec-rails' diff --git a/gemfiles/rails_70/Gemfile.lock b/gemfiles/rails_70/Gemfile.lock index 88d7b379..1378b2f9 100644 --- a/gemfiles/rails_70/Gemfile.lock +++ b/gemfiles/rails_70/Gemfile.lock @@ -75,8 +75,6 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) - ast (2.4.2) - base64 (0.1.1) builder (3.2.4) capybara (3.39.2) addressable @@ -104,9 +102,6 @@ GEM activesupport (>= 6.1) 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.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -137,10 +132,6 @@ GEM racc (~> 1.4) nokogiri (1.15.4-java) racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.4) - ast (~> 2.4.1) - racc pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -182,7 +173,6 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) - rainbow (3.1.1) rake (13.0.6) regexp_parser (2.8.2) rexml (3.2.6) @@ -207,23 +197,6 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) - 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) - rubocop-packaging (0.5.2) - rubocop (>= 1.33, < 2.0) - ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) simplecov (0.22.0) docile (~> 1.1) @@ -240,7 +213,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) @@ -263,8 +235,6 @@ DEPENDENCIES rake rspec rspec-rails - rubocop - rubocop-packaging simplecov simplecov-cobertura diff --git a/lib/arbre/context.rb b/lib/arbre/context.rb index b197e630..16a1b4b9 100644 --- a/lib/arbre/context.rb +++ b/lib/arbre/context.rb @@ -44,7 +44,7 @@ def initialize(assigns = {}, helpers = nil, &block) @_current_arbre_element_buffer = [self] super(self) - instance_eval(&block) if block_given? + instance_eval(&block) if block end def arbre_context diff --git a/lib/arbre/element/builder_methods.rb b/lib/arbre/element/builder_methods.rb index a9ffe9ab..89aafb1c 100644 --- a/lib/arbre/element/builder_methods.rb +++ b/lib/arbre/element/builder_methods.rb @@ -25,11 +25,11 @@ def build_tag(klass, *args, &block) tag.parent = current_arbre_element with_current_arbre_element tag do - if block_given? && block.arity > 0 + if block && block.arity > 0 tag.build(*args, &block) else tag.build(*args) - append_return_block(yield) if block_given? + append_return_block(yield) if block end end diff --git a/lib/arbre/html/tag.rb b/lib/arbre/html/tag.rb index f33b86ba..12b334f8 100644 --- a/lib/arbre/html/tag.rb +++ b/lib/arbre/html/tag.rb @@ -165,7 +165,7 @@ def dom_class_name_for(record) if record.class.respond_to?(:model_name) record.class.model_name.singular else - record.class.name.underscore.gsub("/", "_") + record.class.name.underscore.tr("/", "_") end end