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

Add node pattern methods to handle dependency audits in a better way #3012

Merged
merged 1 commit into from
Aug 8, 2017

Conversation

GauthamGoli
Copy link
Contributor

@GauthamGoli GauthamGoli commented Aug 6, 2017

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

#569 and #2662
RuboCop has pattern searching macros which simplify searching/matching nodes in AST.
Found documentation for same in the source of node_pattern.rb

This PR updates depends_on audits to use such pattern matching methods, so code becomes more readable and also fixes bug in previous code which wasn't detecting dependencies.

(there is however one edge case where the value of a depends_on hash is an array, I know how exactly to implement that and will deal with that later)

Edit: How did I derive those patterns? By running the below commands and looking at the AST.
$ ruby-parse -e 'depends_on :x11 => optional'
$ ruby-parse -e 'depends_on "readline" => :recommended'

cc @ilovezfs

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question but otherwise: great work here 👍

@@ -161,6 +158,22 @@ def depends_on_name_type?(node, name = nil, type = :required)
type_match && name_match
end

def_node_search :required_dependency?, <<-PATTERN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth using EOS or EOS.undent here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

@MikeMcQuaid MikeMcQuaid merged commit fabcad3 into Homebrew:master Aug 8, 2017
@MikeMcQuaid
Copy link
Member

Thanks again @GauthamGoli!

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants