-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
brew-audit: move style checks into main audit output #112
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
Conversation
return unless @style | ||
|
||
style_violations = nil | ||
Homebrew.check_style(@formula.path) { |rslt| style_violations = rslt } |
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.
No idea what rslt
means 😉
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.
Why not just
Homebrew.check_style(@formula.path) do |violations|
violations.each { |violation| problem violation }
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.
Sorry; shorthand for "result". I'm still learning to remember to spell everything out for brew
code.
xu-cheng's version didn't occur to me since I'm still new at Ruby. Switched to that.
A few comments but otherwise LGTM 👍 |
Homebrew.failed = !$?.success? | ||
if block_given? | ||
txt = nil | ||
Utils.popen(["rubocop", *args], "r") { |io| txt = io.read } |
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.
Utils.popen_read
?
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.
popen_read
returns the results in BINARY
and would require a separate force_encoding('UTF-8')
call and check for Ruby 1.9+. I thought just doing a popen
with a r
instead of rb
would be simpler.
Switched to "in progress" while I look at switching to Rubocop's JSON output instead of parsing their normal results output. |
I rewrote the |
Question: the |
Could just be a mistake. Feel free to address it. |
#: | ||
#: If `--online` is passed, additional slower checks that require a network | ||
#: connection are run. This should be used when creating for new formulae. | ||
#: | ||
#: `audit` exits with a non-zero status if any errors are found. This is useful, | ||
#: for instance, for implementing pre-commit hooks. | ||
|
||
# Undocumented options: |
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.
Looks like documentation to me 😉. Will this be enabled with --debug
? If so I think it can just be omitted.
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.
Surprisingly, no, because it takes a capital D
instead of a lowercase d
like --debug
. I don't know why it's different, but it's a distinct option.
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.
Weird. Given I've been working on Homebrew for a long time and had no idea I think it's worth just using ARGV.debug?
instead.
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 took a closer look at it. All this one does is turn on instrumentation for profiling the audit_*
methods. It doesn't turn on all the other verbose debugging stuff. And since it does profiling, it probably doesn't want to enable the other debugging stuff, since that would skew the timings.
I reworded the comment and factored out that bit of code to make it more understandable.
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.
Just wanted to mention that brew doctor
has the exact same feature. It is equally undocumented.
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 refactored this to share brew doctor
's implementation, and added a similar "Undocumented options" comment at the top of brew doctor
. Are you folks okay with the comment there? That way the -D
is still hidden in the man page, but when you're looking at the source there's something to indicate the intent, which, judging from this string of comments and my own experience, was not clear.
Looks good to me 👍 |
|
||
# Debugging support | ||
|
||
def instrument_module_with_method_timers(the_module) |
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 would be better to turn it to a method of FormulaAuditor
like what brew doctor
does.
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.
You could also make this method the same name as used in brew doctor
.
|
||
end | ||
|
||
def inject_dump_stats!(the_module, pattern = /.*/) |
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 prefer this to have no default for pattern
. Now that this method is used by multiple commands, it should definitely be moved out of diagnostic.rb
. Maybe utils.rb
is a sensible place, probably even better a new file in utils/
.
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, that makes sense: you'd almost never actually want to do /.*/
because there are so many small methods in most modules and classes, and if you do, it should be explicit. Removed the default and moved it to Utils.
Amended to address the latest round of output. Two significant changes: Before, the Removed the empty line between formulae in the output (and changed to 2-space indent for the bullet lists). Martin and I think it's more readable and a better use of space this way. IMHO, especially true now that New output:
The format for multi-line problems is ugly, with 2nd and later lines not being indented, like "Length..." in the following.. Going to do something about that while I'm in here.
|
return unless @style_offenses | ||
display_cop_names = ARGV.include?("--display-cop-names") | ||
@style_offenses.each do | ||
|offense| problem offense.to_s(:display_cop_name => display_cop_names) |
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.
|offense|
should be at the end of the preceding line, not at the start of this line.
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.
Fixed.
That turned out to be easier than I feared.
I think this is ready to go now, pending y'all's feedback on the output format change. |
$times = {} | ||
at_exit do | ||
col_width = [$times.keys.map(&:size).max + 2, 15].max | ||
puts $times.sort_by { |_k, v| v }.map { |method, time| |
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.
do
-end
for multi-line blocks please.
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.
Same problem as before - if I change this { ... }
to do ... end
, it will print "Enumerator<#...>
" instead of displaying the individual lines.
Maybe it's a weird parsing issue related to precedence and the fact that there are two blocks introduced in this statement?
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 it's trying to map
the result of puts
instead of vice-versa (http://stackoverflow.com/a/5513622); I guess you could add parentheses like ($times.sort_by ... )
or just stick with the braces.
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.
Sorry for the nagging! Hadn't seen your other related 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.
Actually, the most sensible solution to this style issue seems to be to move the puts
into the block (and to replace map
with each
):
$times.sort_by { |_k, v| v }.each do |method, time|
puts format("%-*s %0.4f sec", col_width, "#{method}:", time)
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 already tried sticking parentheses in a couple places there, but didn't find an arrangement that worked.
Switched to Martin's suggestion.
This collects all violations for each formula in a single place, instead of doing `brew style` outputs for all formulae first, and then the other audit checks.
Looking good to me 👍. We can always iterate after shipping. |
👍 I can think of a few minor improvements, but they can wait and I've pestered you enough in this PR. I'm really happy with the code now (and the major improvement to What I'd really like you to consider for future PRs (or even this PR, if you feel like retroactively doing this) would be not to lump all changes into a single commit. It's really hard to digest once some time has passed and you're looking at the Git history. Looking at the current code, here's what the theme of individual commits could be (they should be all independent and build on top of each other):
|
Sorry! I've gotten used to squashing to a single commit to formula changes; maybe overapplied it here. I could still break these out to multiple commits if you think it would help readability. (Some |
No need to apologize! It's just something that I noticed and I wanted to make you aware of. Just pretend for a moment that there's a breaking change in
I'd leave this decision up to you. It's obviously easier to do when things get split right from the start. I'm also fine merging it as-is, as nobody except me complained and even I did so at the very last moment. |
Turns out splitting this would take a good amount of work: I'd want to make sure each individual commit still worked, so it would take manual editing and several rounds of testing, and I'm short on time this week. Let's just merge as-is, and I'll work on organizing future PRs better. |
Shipped. Thanks for your feedback, folks! |
Checklist
brew tests
with your changes locally?Description
Breaks up the
brew style
part of the check forbrew audit --strict
and runs it separately for each formula, when that formula is being checked for other audits. This collects all violations for each formula in a single place, instead of doingbrew style
outputs for all formulae first, and then the other audit checks. Easier to read. It also makes the violation count at the end of the output include thestyle
violations.Before:
After:
This also localizes the
--fix
argument support instyle
so that it doesn't leak toaudit
. I'm not sure if that's the right thing to do, though.audit
isn't documented as supporting--fix
, but that doesn't necessarily mean it isn't supposed to do it.Considerations
audit
output style here. If someone really misses it, I could add an option to enable the old behavior, with all the style checks at the top and with coloring intact. Or we could addTty
-based coloring toaudit
's own output, and you'll get it everywhere. (Personally, I don't care. I think this much use of color is distracting instead of helpful.)brew audit --strict a*
.brew audit
actually supposed to support--fix
?