-
Notifications
You must be signed in to change notification settings - Fork 45
WIP: cyclomatic complexity: indicate full method in location #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Monkey patching! Here be dragons. | ||
module RuboCop | ||
module Cop | ||
module MethodComplexity | ||
# RuboCop's default implementation of `add_offense` in `Cop` only gets the | ||
# location of the keyword associated with the problem which, for things | ||
# like complexity checkers, is just the method def line. This isn't very | ||
# useful for checkers where the entire method body is relevant. Fetching | ||
# this information from an `Offense` instance is difficult, since the | ||
# original AST is no longer available. So it's easier to monkey-path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like the detail in this explanation. If you prefer brevity, what about something like:
|
||
# this method on complexity checkers to send the location of the entire | ||
# method to the created `Offense`. | ||
def add_offense(node, loc, message = nil, severity = nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of adding a comment here about what/why this is? Similar to what you have in the commit message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, thanks, I agree. Want to keep it shorter than the commit message explanation, and not sure how I want to word it yet. I'll ping you when I have something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW: I'm a big fan of good commit messages and a team that goes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I've added a comment now, but it's not short. I'm not sure how much briefer it can be & still be good english without just cutting it down to "see commit message for why this is begin done." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel strongly, I think this is fine as-is. |
||
super(node, node.loc, message, severity) | ||
end | ||
end | ||
end | ||
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.
I'd define this as:
Reason: If any of these module names change, it will fail fast.
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.
Or: