-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Change the start label of a heredocument to be enclosed in single quotes #1543
Conversation
context 'the display name not present' do | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\\b/, /^with\\b/, or /^without\\b/. | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Context description should match /^when\b/, /^with\b/, or /^without\b/. |
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.
There is a difference at a glance. Wondering how it turns out that both work 🤔
<<~A
/^when\b/
A
=> "/^when\b/\n"
<<~'A'
/^when\b/
A
=> "/^when\\b/\n"
Maybe there's some escaping logic in expect_offense
? I can't find any code in expect_offense
and there are no specs for this method or AnnotatedSource
in rubocop
specs.
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.
The argument of expect_offense
is a heap document, so a heap document enclosed in single quotes is completely a string as written. So the following would be the same.
irb(main):001:0" <<~A
irb(main):002:0" /^when\\b/
irb(main):003:0> A
=> "/^when\\b/\n"
irb(main):004:0' <<~'A'
irb(main):005:0' /^when\b/
irb(main):006:0> A
=> "/^when\b/\n"
Am I missing something?
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.
Oh, please accept my apologies, I've missed the point that you've changed the contents of the string and removed unnecessary escaping.
Looks much better this way indeed!
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.
The title of this PR was misleading. My apologies.
Thanks for the review!
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.
Please add to the PR description what the benefit/downside is of either syntax. I always forget which is which.
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.
Thank you for review. I updated description.
describe '#mymethod ' \ | ||
'(is cool)' do | ||
end |
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.
<<-A
a \
b
A
=> "a b\n"
The \
part is lost, and that undermines the very existence of this example which is purposed to test "-separated multiline strings".
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.
The results seem to be the same here as well.
irb(main):001:0" <<-A
irb(main):002:0" a \\
irb(main):003:0" b
irb(main):004:0> A
=> "a \\\nb\n"
irb(main):005:0' <<-'A'
irb(main):006:0' a \
irb(main):007:0' b
irb(main):008:0> A
=> "a \\\nb\n"
This PR is change as follows ```ruby expect_offense(<<-RUBY) # ... end expect_offense(<<-'RUBY') # ... end ```
deace2e
to
aa0a9e3
Compare
The title of the PR was incorrect and has been corrected. |
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.
Much easier to read now, thank you!
This PR is change as follows
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).