diff --git a/changelog/new_add_new_style_empty_heredoc_cop.md b/changelog/new_add_new_style_empty_heredoc_cop.md new file mode 100644 index 00000000000..f1d30f78375 --- /dev/null +++ b/changelog/new_add_new_style_empty_heredoc_cop.md @@ -0,0 +1 @@ +* [#10820](https://github.com/rubocop/rubocop/pull/10820): Add new `Style/EmptyHeredoc` cop. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index a430621397b..35155722bbc 100644 --- a/config/default.yml +++ b/config/default.yml @@ -3514,6 +3514,11 @@ Style/EmptyElse: - both AllowComments: false +Style/EmptyHeredoc: + Description: 'Checks for using empty heredoc to reduce redundancy.' + Enabled: pending + VersionAdded: '<>' + Style/EmptyLambdaParameter: Description: 'Omit parens for empty lambda parameters.' Enabled: true diff --git a/lib/rubocop.rb b/lib/rubocop.rb index 126274caeb2..eaac41af88e 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -481,6 +481,7 @@ require_relative 'rubocop/cop/style/empty_block_parameter' require_relative 'rubocop/cop/style/empty_case_condition' require_relative 'rubocop/cop/style/empty_else' +require_relative 'rubocop/cop/style/empty_heredoc' require_relative 'rubocop/cop/style/empty_lambda_parameter' require_relative 'rubocop/cop/style/empty_literal' require_relative 'rubocop/cop/style/empty_method' diff --git a/lib/rubocop/cop/style/empty_heredoc.rb b/lib/rubocop/cop/style/empty_heredoc.rb new file mode 100644 index 00000000000..2109ecab2cf --- /dev/null +++ b/lib/rubocop/cop/style/empty_heredoc.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Style + # Checks for using empty heredoc to reduce redundancy. + # + # @example + # + # # bad + # <<~EOS + # EOS + # + # <<-EOS + # EOS + # + # <