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 struct for #audit_formula args #17651

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

samford
Copy link
Member

@samford samford commented Jul 8, 2024

  • 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 style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

As discussed in #17643 (comment), adding type signatures to #audit_formula methods in formula cops would lead to verbose, repetitive signatures across the existing ~63 instances:

sig {
  override.params(
    _node:              RuboCop::AST::ClassNode,
    _class_node:        RuboCop::AST::ConstNode,
    _parent_class_node: RuboCop::AST::ConstNode,
    body_node:          RuboCop::AST::Node,
  ).void
}

This reworks #audit_formula to use a T::Struct for its arguments, which allows us to use a one-line signature for these methods. There may be room for improvement here but this seems to work as expected, at least.

@Bo98
Copy link
Member

Bo98 commented Jul 8, 2024

Not a fan of the name "args" as everything is an argument but otherwise don't have a strong opinion either way.

@dduugg
Copy link
Sponsor Member

dduugg commented Jul 8, 2024

Not a fan of the name "args" as everything is an argument but otherwise don't have a strong opinion either way.

I <3 this change, but agree that args could be improved. Maybe formula_nodes, if that seems an accurate description.

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.

Thanks again @samford! Good to 🚢 once args renamed!

Library/Homebrew/rubocops/bottle.rb Outdated Show resolved Hide resolved
Adding type signatures to `#audit_formula` methods in formula cops
would lead to verbose, repetitive signatures across the existing ~63
instances. This reworks `#audit_formula` to use a `T::Struct` for its
arguments, which allows us to use a one-line signature for these
methods.
@samford
Copy link
Member Author

samford commented Jul 8, 2024

I updated this to use FormulaNodes as the struct name and formula_nodes as the #audit_formula parameter name. Per Bo's comment, we can always rename it to something else if we ever add a non-node argument, so the "nodes" language seems fine for now (it's certainly more descriptive than args).

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.

Looks great, thanks again!

@MikeMcQuaid MikeMcQuaid merged commit d31150a into Homebrew:master Jul 8, 2024
25 checks passed
@samford samford deleted the audit_formula-struct-arg branch July 8, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants