-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
dev-cmd/edit: Move path specific functions to Pathname #16029
Conversation
617272d
to
e31d6a2
Compare
CI fails with |
Thinking about this a little more I think we should check that the paths are valid before checking to see if we want to print the install warning. |
@apainintheneck moved path validation before checking for warning message. The code for error message is also in a new method, so the logic should be even more readable now. The last two offences are not easy to fix, though.
|
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.
Thanks for the PR and work so far!
d4a5f4b
to
63c60d2
Compare
I guess I addressed all review comments. |
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.
Thanks again! A few more thoughts.
Library/Homebrew/dev-cmd/edit.rb
Outdated
@@ -28,6 +54,40 @@ def edit_args | |||
end | |||
end | |||
|
|||
sig { params(path: Pathname, cask: T::Boolean).void } | |||
def fail_with_message(path, cask) |
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.
def fail_with_message(path, cask) | |
def raise_unless_existing!(path, cask) |
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.
@abitrolly Still prefer this naming or at least something with raise
and the !
to be more in keeping with typical Ruby behaviour.
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.
Renamed to raise_with_message!
Library/Homebrew/dev-cmd/edit.rb
Outdated
end | ||
expanded_paths = args.named.to_paths | ||
expanded_paths.each do |path| | ||
fail_with_message(path, args.cask?) unless path.exist? |
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.
How about moving the unless path.exist?
into raise_unless_existing
?
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 can be done, but I would rather declare fail_with_message
as T.noreturn
to keep the branch flow in edit
. So what is your decision?
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 can still have it as void
as long as the return value is not used by callers.
Co-authored-by: Mike McQuaid <[email protected]>
I'm fine with this once the linter is happy. If it's too difficult to make the linter happy, you could just keep the original loop logic minus the select statement and add the |
@apainintheneck I reworked the warning message test to use |
I don't think I am able to fix the typecheck error for this code. I opened sorbet/sorbet#7350 to get better docs about what to do with refinements, but for now it is beyond my abilities. |
CC @dduugg @reitermarkus for ideas and thoughts here on how best to handle things. Would prefer to use Refinements if possible but if we can't with Sorbet: so be it (and then I think the old approach is better than moving to |
Genuinely curious, why do you prefer refinements @MikeMcQuaid ? IIUC they're a fix intended to scope legacy monkey-patches to where they are used, not a good idea for new code. They're banned at Shopify and Stripe. Sorbet doesn't support refinements. The workaround I used in |
Maybe https://ruby-doc.org/stdlib-2.2.1/libdoc/delegate/rdoc/SimpleDelegator.html can be used to wrap EDIT: |
I prefer them to adding mode global monkeypatches to |
All green. Let me know if there is anything else left. |
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 good! Thanks again @abitrolly and sorry for all the back and forth.
No problem. I am glad it helped. ) |
This PR reduces
edit.rb
complexity to solve #16015.Pathname
the logic that checks if the path is core tap, cask or formula.This makes the code easier to read to fix the name conflict between formula and existing directory.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?