style: call rubocop directly#10583
style: call rubocop directly#10583Rylan12 merged 4 commits intoHomebrew:masterfrom Rylan12:call-rubocop-directly
Conversation
|
Review period will end on 2021-02-11 at 00:09:01 UTC. |
|
Does running it in a more isolated environment (i.e. a new Ruby process running a custom The one new style warning it raises in the CI does seem correct - not entirely sure why it wasn't caught before though. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Great work here so far @Rylan12!
Library/Homebrew/style.rb
Outdated
There was a problem hiding this comment.
I wonder if there's any APIs that allow the JSON output to be obtained directly?
There was a problem hiding this comment.
Possibly. I've been looking through the code and slowly starting to wrap my head around it. I'd like to avoid using any of the private API (just seems like good practice) so that may be a limiting factor. So far, I know that RuboCop::CLI#run is part of the public API while other parts that may be helpful (like RuboCop::Runner) are private. I'll look into the JSON stuff, though.
Yes, no idea what's happening here.
Can you elaborate on with an example here?
I'd be surprised if it did but copying the code in the bin stub ( |
I think the change is that style warnings (as opposed to style errors) weren't shown by
I'll give it a shot
Thanks for the tip. I'll see what I can do. Totally venturing into new waters here so I may need some guidance. |
Agreed 👍🏻
Happy to help however I can! |
|
Just realized that I forgot to give an example of the issues not being reported. What I did was add a line with something like |
Hmm, that seems non-ideal unless we can figure out a way to optionally show it again. |
|
Agreed. This is its current state is not something that should be merged. I'd rather live with a warning than have errors silenced. I looked at the code a little more. It looks like the error message are displayed using the |
It's because we run The |
|
Bingo, thanks! I modified this to use $ brew style
An error occurred while FormulaAudit/Homepage cop was inspecting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/htop.rb:1:0.
To see the complete backtrace run rubocop -d.
An error occurred while FormulaAudit/Homepage cop was inspecting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/htop.rb:1:0.
To see the complete backtrace run rubocop -d.
1 file inspected, no offenses detected
1 error occurred:
An error occurred while FormulaAudit/Homepage cop was inspecting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/htop.rb:1:0.
undefined method `metadata' for nil:NilClass
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:79:in `display_error_summary'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:58:in `display_summary'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:27:in `block in execute_runner'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubocop-1.9.1/lib/rubocop/cli.rb:41:in `run'
/usr/local/Homebrew/Library/Homebrew/style.rb:147:in `block in run_rubocop'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.1/lib/active_support/core_ext/kernel/reporting.rb:28:in `with_warnings'
/usr/local/Homebrew/Library/Homebrew/style.rb:146:in `run_rubocop'
/usr/local/Homebrew/Library/Homebrew/style.rb:54:in `check_style_impl'
/usr/local/Homebrew/Library/Homebrew/style.rb:16:in `check_style_and_print'
/usr/local/Homebrew/Library/Homebrew/dev-cmd/style.rb:75:in `style'
/usr/local/Homebrew/Library/Homebrew/brew.rb:122:in `<main>'It seems unable to display the normal rubocop error message: The traceback points here. Looks like a gem issue. I need to research more here I'm not that familiar with how gems interact with ruby code, etc. Also, |
|
Bundler's standalone |
|
Basically, Bundler's standalone mode is a very basic version of how gem loading works so it doesn't support the full feature set. But it means that it works without having Bundler/Rubygems installed. Which matters less nowadays because Bundler ships with Ruby now. In fact, |
|
Review period ended. |
I went back to give this a try and it worked! I've updated the PR to implement this. Interestingly, though, the warning that reappeared is now gone again. Not sure why. I didn't know where to put the If this looks good, I'll try to do a similar thing with |
Probably because Rubocop doesn't know what a
I think |
👍 makes sense
Thanks, sounds good |
| module Warning | ||
| module Processor | ||
| # Map of symbols to regexps for warning messages to ignore. | ||
| IGNORE_MAP = { |
There was a problem hiding this comment.
Ooo, nice. I wonder if we can use this to get -W0 removed entirely. Opened #10593 as another issue to track this.
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
|
One other thing I just noticed: should I quickly tried to modify the Edit: looking again at the test, I'm not sure this should be changed after all. It says Edit 2: and.... the reason it wasn't working was that I was trying to run from the |
Agreed 👍🏻 Another thing that I don't think requires a fix but is just worth thinking about is |
I just modified it to also use the rubocop utility and that seems to work with no warnings (or significant slowdowns), so let's give it a go! |
brew stylewith your changes locally?brew typecheckwith your changes locally?brew testswith your changes locally?brew manlocally and committed any changes?This PR attempts to solve part of #10505
The idea is that we can initiate rubocop by calling
RuboCop::CLI.new.runinstead of using asystemcall to rubocop. Once this is done, we can selectively ignore the warnings to remove the message.It appears that this first draft works well. I've noticed two issues, though:
brew styleusers, but for those who create and modify style rules, this lack of indication of a rubocop problem would be problematic.I'm going to keep poking at this to see if I can figure it out. If anyone has any ideas, please share.