diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc8e9b95d0..0d7f53bb413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * [#7767](https://github.com/rubocop-hq/rubocop/issues/7767): Skip array literals in `Style/HashTransformValues` and `Style/HashTransformKeys`. ([@tejasbubane][]) * [#7791](https://github.com/rubocop-hq/rubocop/issues/7791): Fix an error on auto-correction for `Layout/BlockEndNewline` when `}` of multiline block without processing is not on its own line. ([@koic][]) * [#7778](https://github.com/rubocop-hq/rubocop/issues/7778): Fix a false positive for `Layout/EndAlignment` when a non-whitespace is used before the `end` keyword. ([@koic][]) +* [#7806](https://github.com/rubocop-hq/rubocop/pull/7806): Fix an error for `Lint/ErbNewArguments` cop when inspecting `ActionView::Template::Handlers::ERB.new`. ([@koic][]) ### Changes diff --git a/lib/rubocop/cop/lint/erb_new_arguments.rb b/lib/rubocop/cop/lint/erb_new_arguments.rb index 6b32c5d9762..08174d273cc 100644 --- a/lib/rubocop/cop/lint/erb_new_arguments.rb +++ b/lib/rubocop/cop/lint/erb_new_arguments.rb @@ -84,7 +84,7 @@ class ErbNewArguments < Cop def on_send(node) erb_new_with_non_keyword_arguments(node) do |arguments| - return if correct_arguments?(arguments) + return if arguments.empty? || correct_arguments?(arguments) arguments[1..3].each_with_index do |argument, i| next if !argument || argument.hash_type? diff --git a/spec/rubocop/cop/lint/erb_new_arguments_spec.rb b/spec/rubocop/cop/lint/erb_new_arguments_spec.rb index 8ff1a5c5f2d..8ff1bd1cc2a 100644 --- a/spec/rubocop/cop/lint/erb_new_arguments_spec.rb +++ b/spec/rubocop/cop/lint/erb_new_arguments_spec.rb @@ -108,5 +108,14 @@ ERB.new(str) RUBY end + + context 'when using `ActionView::Template::Handlers::ERB.new`' do + it 'does not register an offense when using `ERB.new` ' \ + 'without arguments' do + expect_no_offenses(<<~RUBY) + ERB.new + RUBY + end + end end end