- Use `sort_by` to sort the array, rather than comparing each element
to the next.
- This doesn't error with complaints about clobbering at all when run on
`homebrew/cask`, hurray. And it also handles interpolations correctly,
rather than ignoring them.
Co-authored-by: Bevan Kay <email@bevankay.me>
- Interpolating the version into a path is a common pattern, but the interpolations
trip up the alphabetization autocorrect quite spectacularly, so let's
ignore them (for now?).
- Part of issue 16323.
- Previously this was being done manually by Cask maintainers.
- While we're here, enforce that the `zap trash` path is not in `[]` if
it only contains a single element.
- This is buggy on actual Casks, hence the draft PR.
After some discussion, we decided to change the DSL to get rid of
the `plist_name` and `service_name` methods which aren't meaningful
for most users.
The new DSL looks like this:
```rb
service do
name macos: "name", linux: "name"
end
```
I also updated some specs here to reflect these changes.
There was some talk about maybe deprecating `plist_name` and `service_name`
but I think that's outside of the scope of this PR so I'm leaving
them as is for now. One benefit of this is that everything here is backwards
compatible.
It now checks for two new edge cases.
1. Are the required methods defined in the block?
2. Is the `run` command defined if we're using methods other
than `service_name` or `plist_name`?
It has also been updated to only get the list of method call nodes
once instead of doing it repeatedly for each cellar path check.
- Now that we detect correct stanza _grouping_ within `on_*` blocks in
Casks (PR 15211), correct stanza _ordering_ in `on_*` blocks was the
next logical step. For example, `url` has to come after `version` and
`sha256` in an `on_macos` or `on_intel` block for consistency with the
top-level stanza order we enforce elsewhere.
- Still not doing the nested `on_os` inside `on_arch`, that felt
excessive for an edge case that isn't present in any actual real
Casks we have. I removed the test with that specific TODO.
- This test tests nothing. And the TODO comment is wrong.
- We _could_ fix it, but it's a very edgy edge case which pertains to
`livecheck` blocks which currently don't have stanza grouping or
ordering cop support. If we decide in the future to add these, we can
add this back too (provided I remember).
- Also I think I may have got confused with the stanza grouping vs.
stanza ordering cops when writing this, rendering this test more
useless.
- Since moving `comments_hash` to `Stanza`, we've been using the wrong
kind of "comments": the comments for the _stanza_, not the comments
for the entire Cask.
- Add a test to ensure this actually works. There was previously an
infinite loop here due to the bad `comments`, visible in a `StanzaOrder`
cop test, which I speculatively added a failing test for. Turns out
that supporting nested stanza _ordering_ (vs. just grouping) is a
whole separate piece of work (there are multiple TODOs there already),
so I've backed that out and will do that separately.
- A variant of this was an ancient TODO from 2018 (with `if/else` blocks).
- Now in 2023 we have `on_*` blocks within Casks that are very common.
- The most common stanzas present inside `on_*` blocks are `version`,
`sha256` and `url`. So I feel like it's worth keeping a consistent
style for these inside and outside `on_*` blocks.
- Fixing the test expected output was unbelievably tedious.
- There's been debate about this setting being `false` but in
https://github.com/Homebrew/brew/pull/15136#issuecomment-1500063225
we decided that it was worth using the default since RuboCop behaviour changed
so we'd have had to do some horrible things to keep it as `false` -
https://github.com/Homebrew/brew/pull/15136#issuecomment-1500037278 -
and multiple maintainers specify the `--display-cop-names` option to
`brew style` themselves since it's clearer what's gone wrong.
The preferred method is opt_bin because that works
with the API and is more portable (works between versions).
Also removed the last example from the docs of `bin/"name"`
from the service block section