Skip to content
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

Use Rubocop for some brew audits #569

Closed
MikeMcQuaid opened this issue Jul 21, 2016 · 16 comments
Closed

Use Rubocop for some brew audits #569

MikeMcQuaid opened this issue Jul 21, 2016 · 16 comments
Labels
features New features gsoc-outreachy Google Summer of Code or Outreachy outdated PR was locked due to age

Comments

@MikeMcQuaid
Copy link
Member

We should investigate using Rubocop for some (maybe all) brew audits rather than just regex as Rubocop can actually parse Ruby.

@MikeMcQuaid MikeMcQuaid added the help wanted We want help addressing this label Jul 21, 2016
@MikeMcQuaid MikeMcQuaid added the features New features label Sep 11, 2016
@maxnordlund
Copy link
Contributor

I might be able to take a stab at this, seems doable. But I would like some pointers though. May I please have some? (Also maybe you could ping the right persons @MikeMcQuaid)

@jawshooah
Copy link
Contributor

Take a look at rubocop-cask as an example of custom cops and parsing logic.

@maxnordlund
Copy link
Contributor

Nice, will do 👍 . But should I then point a PR to that repo or put inside here somewhere (and then what is a good place)?

@maxnordlund
Copy link
Contributor

Or make a new repo, but that seems like overkill.

@MikeMcQuaid
Copy link
Member Author

@maxnordlund That would be so great! I agree that probably having it inside this repo would be ideal, if that's possible (similarly maybe with rubocop-cask one day). @jawshooah any thoughts on why you made it a separate repo to avoid hitting any issues you may have hit?

Regardless, I wouldn't worry too much about location or even completeness for now; I'd pick a single rule from brew audit that looks like a good candidate for Rubocop and try and get the flow working end-to-end and then we can look at porting other rules across.

@maxnordlund
Copy link
Contributor

Sounds like a plan, I'll make a new repo and steal/borrow the cask rubocop structure and do as you say and implement a single rule. We can always move the code around if needed I guess.

@MikeMcQuaid
Copy link
Member Author

A suggestion for an easy single rule that requires understanding Ruby more than audit really can currently: revision in a bottle do block should be renamed to rebuild and Rubocop should autocorrect it to rebuild.

@maxnordlund
Copy link
Contributor

I haven't been able to get this rolling because a lot of stuff have cropped up at work. I still will try to do this, but it may take quite some time.

@MikeMcQuaid
Copy link
Member Author

@maxnordlund No worries or rush.

@GauthamGoli
Copy link
Contributor

GauthamGoli commented Jan 11, 2017

@MikeMcQuaid I could work on implementing this feature. I implemented a basic cop that you mentioned above.

revision in a bottle do block should be renamed to rebuild and Rubocop should autocorrect it to rebuild

I tested it on a formula and its working fine. The link to the code: https://github.com/GauthamGoli/rubocop-brew . Please let me know what you think
as I'm still trying to understand how to write custom cops, and also am a ruby novice.

Command to run the custom cop
$rubocop --require /absolute/path/to/custom_cop.rb --only CustomCops/CorrectBottleBlock --auto-correct /path/to/test/formula.rb

@MikeMcQuaid
Copy link
Member Author

@GauthamGoli That looks like a great start, nice work! Next step and I'd consider this done would be to submit a PR to add bottle_block_cop.rb to Homebrew somewhere so it can be run without needing manual arguments. @jawshooah may have input on how to (or how best to) do this such that it'll also work for people running rubocop locally without configuration (that's my end goal/dream).

@GauthamGoli
Copy link
Contributor

@MikeMcQuaid We can place bottle_block_cop.rb (and other custom cops) in a directory, I used Library/Homebrew/cops/ and then used the require directive in .rubocop.yml file to specify them. Without further configuration, the custom cop was getting executed locally and detecting violations when --strict argument is passed to brew audit. There is one final issue though, --strict just checks for cop violations, but for autocorrecting the code, may be a new option should be added to brew audit, let's say --fix may be ?

@MikeMcQuaid
Copy link
Member Author

I used Library/Homebrew/cops/ and then used the require directive in .rubocop.yml file to specify them.

Nice! I think Library/Homebrew/rubocops/ would be best.

There is one final issue though, --strict just checks for cop violations, but for autocorrecting the code, may be a new option should be added to brew audit, let's say --fix may be ?

Yeh, that works. It's already there on brew style: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cmd/style.rb#L8-L9

@MikeMcQuaid MikeMcQuaid added in progress Maintainers are working on this and removed help wanted We want help addressing this labels Feb 7, 2017
@GauthamGoli
Copy link
Contributor

@MikeMcQuaid Can porting audit rules to use Rubo Cop be a GSoC project?

@MikeMcQuaid
Copy link
Member Author

@GauthamGoli Yep, that seems like a good one 👍

@MikeMcQuaid
Copy link
Member Author

Going to consider this basically done at this point. Great work again, @GauthamGoli and hope that you'll keep doing some bits on this!

@ghost ghost removed the in progress Maintainers are working on this label Sep 29, 2017
@lock lock bot added the outdated PR was locked due to age label Jan 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
features New features gsoc-outreachy Google Summer of Code or Outreachy outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

5 participants