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 Style/MagicCommentFormat
cop
#9364
Add new Style/MagicCommentFormat
cop
#9364
Conversation
1020f33
to
953c26a
Compare
7312063
to
4b2752c
Compare
Style/FrozenStringLiteralCommentCaseStyle
cop
I think it'd better is this was a cop covering all such pragmas. One cop per pragma seems like a massive overkill to me. |
That's a great point, I'll see about extending this to all magic comments 👍 |
@mattbearman ping :-) |
@mattbearman are you still interested in completing this? |
4b2752c
to
f100e51
Compare
Style/FrozenStringLiteralCommentCaseStyle
copStyle/MagicComments
cop
@bbatsov I have updated this PR to complete it. The cop is now called |
f100e51
to
3679fc2
Compare
Some tests are failing randomly and I haven't been able to repro yet. Looking into it. |
2d3f19b
to
6bd5948
Compare
Ah, figured it out, |
6bd5948
to
3a08351
Compare
config/default.yml
Outdated
# in kebab case (words separated by hyphens). | ||
# Eg: froze-string-literal: true | ||
- kebab | ||
DirectiveCapitalization: lower |
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.
Seems to me this can simply be a boolean.
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 are three options - upper
(all uppercase), lower
(all lowercase) and nil (ignore capitalization)
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, I saw this, but was on the fence for whether it makes sense for someone to disable this. I've yet to see someone not writing lowercase magic comments, but I guess they exist. :D
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.
I figured that since it's easy, having options is better 😄
|
3a08351
to
0373857
Compare
Sure, |
0373857
to
a2f19bb
Compare
Style/MagicComments
copStyle/MagicCommentFormat
cop
config/default.yml
Outdated
DirectiveCapitalization: lower | ||
ValueCapitalization: ~ | ||
SupportedCapitalizations: | ||
- lower |
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.
I think I like DirectiveCase
a bit better as capitalization
and lowercase
don't mix very well IMO. :-) Perhaps spelling out fully lowercase
and uppercase
would be best.
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.
I had DirectiveCase
first but I found it confusing with snake case and kebab case. I'll change it to the full lowercase
and uppercase
, good suggestion!
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.
Updated!
a2f19bb
to
0f0c7b9
Compare
…nsistent magic comments. This cop is designed to ensure frozen string literal comments are consistent, enforcing either snake case or kebab case, as well as capitalization. Co-authored-by: Matt Bearman <matt@mattbearman.com>
0f0c7b9
to
a425518
Compare
Magic comments in Ruby are underscore/hyphen agnostic, this can lead to codebases having inconsistent case style in the frozen string literal comment (
# frozen_string_literal: true
and# frozen-string-literal: true
)This cop allows the enforcement of either snake case (underscore separated) or kebab case (hyphen separated).
Before submitting the PR make sure the following are checked:
Commit message starts with[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.