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
[Fix #7426] Add always_true
style to Style/FrozenStringLiteralComment
#7435
[Fix #7426] Add always_true
style to Style/FrozenStringLiteralComment
#7435
Conversation
def remove_comment(corrector, node) | ||
corrector.remove(range_with_surrounding_space(range: node.pos, | ||
side: :right)) | ||
end | ||
|
||
def enable_comment(corrector) | ||
# require "pry" | ||
# binding.pry |
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.
Old debugging code
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.
Gah, thanks!
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.
@parkerfinch : Thanks for opening this! This looks pretty good.
I think I'm leaning more toward what @olliebennett had suggested because it makes it clear that we are enforcing #frozen_string_literal: true
. Maybe use enforcetrue
instead to be even more explicit.
Thanks for taking a look @gfyoung, made the suggested name change! |
frozen
style to Style/FrozenStringLiteralCommentenforcetrue
style to Style/FrozenStringLiteralComment
b5acfaf
to
79f743c
Compare
I like the idea in general. I'm thinking that |
@bbatsov : Sounds good. Whatever term is most intuitive! |
79f743c
to
601a0c6
Compare
enforcetrue
style to Style/FrozenStringLiteralCommentalways_true
style to Style/FrozenStringLiteralComment
Thanks @bbatsov , pushed that name change! |
# | ||
# module Bar | ||
# # ... | ||
# end | ||
class FrozenStringLiteralComment < Cop | ||
include ConfigurableEnforcedStyle | ||
include FrozenStringLiteral | ||
include RangeHelp | ||
|
||
MSG = 'Missing magic comment `# frozen_string_literal: true`.' |
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.
Should we change this one since we don't strictly require # frozen_string_literal: true
unless always_true
is passed in as the configuration?
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.
Hrrmm -- I see how the current comment could be misleading, but I'm not sure what a better solution is. Maybe if we made it clear that we weren't giving the full text of the comment, e.g. Missing magic "frozen_string_literal" comment
? But I think there's some value in giving the exact syntax expected for the comment.
Do you have thoughts on what to replace this with?
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.
But I think there's some value in giving the exact syntax expected for the comment
If you're going to give exact syntax, then you should give all of the accepted values for clarity to the end user (clarity is what we're ultimately aiming for when I opened #7426). Otherwise, I would say Missing magic "frozen_string_literal" comment
and allow them to look it up in the docs, where we have more space to elaborate.
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.
Yeah, probably there should be different messages for the different enforced styles. The current message is appropriate only for the new always_true
style.
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.
Addressed in #7634
ee83527
to
59a2a86
Compare
650c715
to
2ff6b74
Compare
@parkerfinch : These changes look great! Just waiting on @bbatsov to give further feedback or merge. |
2ff6b74
to
6c35dfd
Compare
@bbatsov I think this is good to go, let me know if there's anything I can do to make this easier to review! |
6c35dfd
to
65e2e30
Compare
This adds another style to Style/FrozenStringLiteralComment that enforces that the comment is always enabled, that is, it requires that string literals are always frozen. The default style, `always`, enforces that the comment exists but does not enforce that the comment is enabled. This also differentiates the offense message for the `always` and `always_true` styles. It changes the offense message when using the `always` style to be less specific, since the old version of the message implied that the only acceptable value of the frozen_string_literal comment was `true`. In fact, in the `always` style, either `true` or `false` is acceptable. The new `always_true` style uses that preexisting message, since when using that style it is required that the value of the frozen_string_literal comment is `true`.
65e2e30
to
b586912
Compare
I would definitely love for this feature to be merged! Thanks for all the hard work @parkerfinch! |
The changes look good, but your branch has to be rebased on top of the current |
MSG = 'Missing magic comment `# frozen_string_literal: true`.' | ||
MSG_MISSING_TRUE = 'Missing magic comment `# frozen_string_literal: '\ | ||
'true`.' | ||
MSG_MISSING = 'Missing magic "frozen_string_literal" comment.' |
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.
It'd be nice if all those messages employed consistent wording. Now they look a bit weird.
Before this gets merged, I'd like to coin my 2¢. For dealing with string literals I see those sane options:
With that, I'm trying to point out that Hope you'll find this convincing enough to change how |
Opened #7634 to bring this over the finish line |
Closing in favor of #7634 |
FROM #7435: This adds another style to Style/FrozenStringLiteralComment that enforces that the comment is always enabled, that is, it requires that string literals are always frozen. The default style, `always`, enforces that the comment exists but does not enforce that the comment is enabled. This also differentiates the offense message for the `always` and `always_true` styles. It changes the offense message when using the `always` style to be less specific, since the old version of the message implied that the only acceptable value of the frozen_string_literal comment was `true`. In fact, in the `always` style, either `true` or `false` is acceptable. The new `always_true` style uses that preexisting message, since when using that style it is required that the value of the frozen_string_literal comment is `true`. === Same changes as the original PR with merge conflicts addressed. Original author: @parkerfinch Closes #7426 Closes #7435
The wording regarding missing and unnecessary string literals are aligned with each other. Addresses: #7435 (comment)
This adds another style to Style/FrozenStringLiteralComment that
enforces that the comment is always enabled, that is, requiring that
string literals are always frozen. The default style,
always
,enforces that the comment exists but does not enforce that the comment
is enabled.
@gfyoung does this line up with what you're thinking? Feel free to make any changes to this as you see fit and push up something that aligns more closely with your idea!
I had most of this put together before I saw @olliebennett's suggestion to name this
alwaystrue
-- I'm happy to change the name here, let me know if you have thoughts!I am an infrequent contributor, please let me know if I forgot any steps or could make this easier to take a look at!
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.