diff --git a/changelog/new_add_new_rails_strip_heredoc_cop.md b/changelog/new_add_new_rails_strip_heredoc_cop.md new file mode 100644 index 0000000000..6bf5fcfc43 --- /dev/null +++ b/changelog/new_add_new_rails_strip_heredoc_cop.md @@ -0,0 +1 @@ +* [#704](https://github.com/rubocop/rubocop-rails/issues/704): Add new `Rails/StripHeredoc` cop. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 09b40ecc50..4d18adfdf0 100644 --- a/config/default.yml +++ b/config/default.yml @@ -871,6 +871,12 @@ Rails/SquishedSQLHeredocs: # to be preserved in order to work, thus autocorrection is not safe. SafeAutoCorrect: false +Rails/StripHeredoc: + Description: 'Enforces the use of squiggly heredoc over `strip_heredoc`.' + StyleGuide: 'https://rails.rubystyle.guide/#prefer-squiggly-heredoc' + Enabled: pending + VersionAdded: '<>' + Rails/TableNameAssignment: Description: >- Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead. diff --git a/lib/rubocop/cop/rails/strip_heredoc.rb b/lib/rubocop/cop/rails/strip_heredoc.rb new file mode 100644 index 0000000000..1c26b83839 --- /dev/null +++ b/lib/rubocop/cop/rails/strip_heredoc.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Rails + # Enforces the use of squiggly heredoc over `strip_heredoc`. + # + # @example + # + # # bad + # <= 2.3', :ruby23 do + it 'registers an offense when using `strip_heredoc` with `<<`' do + expect_offense(<<~RUBY) + <