-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new Rails/SquishedSQLHeredocs
cop
#291
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
Rails/SquishedHeredocs
copRails/SquishedSQLHeredocs
cop
Sorry @mobilutz, I just realised that my earlier suggestion about single-line heredocs was wrong. Even when a heredoc is only a single line, it still always has a trailing newline character: $ ruby -e "puts <<~SQL.inspect
SELECT * FROM posts
SQL"
"SELECT * FROM posts\n" Since the point of the style guide entry is to avoid logging newline characters, I think we should actually enforce |
Thanks for testing it out again, I totally did not do that. |
@eugeneius Any chance you could review this again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a few changes that make the inline case work correctly:
diff --git a/spec/rubocop/cop/rails/squished_sql_heredocs_spec.rb b/spec/rubocop/cop/rails/squished_sql_heredocs_spec.rb
index 340d317a3..a3b132c00 100644
--- a/spec/rubocop/cop/rails/squished_sql_heredocs_spec.rb
+++ b/spec/rubocop/cop/rails/squished_sql_heredocs_spec.rb
@@ -58,8 +58,16 @@ RSpec.describe RuboCop::Cop::Rails::SquishedSQLHeredocs, :config do
context 'with heredocs as method parameters' do
it 'does not register an offense' do
- expect_no_offenses(<<-RUBY)
+ expect_offense(<<~RUBY)
execute(<<~SQL, "Post Load")
+ ^^^^^^ Use `<<~SQL.squish` instead of `<<~SQL`.
+ SELECT * FROM posts
+ WHERE post_id = 1
+ SQL
+ RUBY
+
+ expect_correction(<<~RUBY)
+ execute(<<~SQL.squish, "Post Load")
SELECT * FROM posts
WHERE post_id = 1
SQL
@eugeneius Thank you very much for the great input! Now even method-parameter Heredocs are working!!! I rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me! I added a few more suggestions.
@mobilutz Can you update this PR? |
Thanks for the reminder. @eugeneius Thanks for your great reviews! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for sticking with this @mobilutz!
Thank you! |
@koic It seems, that the changelog entry is not in the correct place 😦 PS: I create a new PR to fix this: #333 |
This cops check
<<-SQL
SQL-heredocs if they use.squish
or not.Base is this styleguide: Squished Heredocs
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.