-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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 a DisableComment Cop #18842
base: master
Are you sure you want to change the base?
Add a DisableComment Cop #18842
Conversation
Evidently, something failed when I ran Good to see that the rule is working though! |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Not stale, I'll help @koddsson with this some more after the holidays. |
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! It works, as evidenced by the syntax check failing because a lot of our disables don’t have comments (yet). I’ll take a bit of time over 🎄 to add comments in a separate PR, since you probably don’t want to acquire the context to do that @koddsson. 😅
I’ve added some “nit” comments and some Sorbet type sigs in this review.
For the problems you were having running the test, it should work if you cd $(brew --repo); gh pr checkout 18842; brew tests --only=rubocops/disable_comment
.
end | ||
end | ||
|
||
it "register a offencse" do |
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.
(nit)
it "register a offencse" do | |
it "registers an offense" do |
RUBY | ||
end | ||
|
||
it "doesn't register an offencse" do |
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.
(nit)
it "doesn't register an offencse" do | |
it "doesn't register an offense" do |
class DisableComment < Base | ||
MSG = "Add a clarifying comment to the RuboCop disable comment" | ||
|
||
def on_new_investigation |
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.
def on_new_investigation | |
sig { void } | |
def on_new_investigation |
def disable_comment?(comment) | ||
comment.text.start_with? "# rubocop:disable" | ||
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.
sig { params(line: String).returns(T::Boolean) } |
|
||
private | ||
|
||
def disable_comment?(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.
def disable_comment?(comment) | |
sig { params(comment: Parser::Source::Comment).returns(T::Boolean) | |
def disable_comment?(comment) |
@@ -0,0 +1,32 @@ | |||
# typed: strict |
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.
As this is Sorbet typed: strict
, I’ve added type signatures in-line.
Hey 👋🏻!
I wrote this rule at work where we have a very similar codebase and @MikeMcQuaid suggested that it could be useful in Homebrew as well so I essentially just copied it over here.
The rule enforces that any
robocop:disable
have a preceding comment that explains why the rule was disabled. This can be very useful when things are disabled for seemingly obvious reasons, but they become less and less obvious over time.Everything looks good except for when I try to run the test I wrote, the test runner doesn't seem to find the test file 🤔. See the output log below.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?I feel like I'm probably holding it wrong?