- Previously this components order cop only checked for correct stanza
order inside `on_*` blocks. This commit extends this cop to also check
for correct stanza order inside `head` and `resource` blocks. This is
a positive change since it standardizes the order of stanzas in all of
the places, making formulae more readable.
- Fixes issue 14017.
- This still doesn't pass `brew readall` for Casks, but it gets us a
little closer since if `url` has a `version` interpolated in it, the
`version` stanza has to come first.
- See https://github.com/Homebrew/homebrew-cask/pull/143201 for the
current failures.
- This, ie Mojave first, is more common in real Casks than the
alternative of newest to oldest ie Ventura first.
- Doing it this way reduces the number of offenses from ~500 to ~200.
- Complaining about only `on_arm` and `on_intel` was too restrictive
since casks can have many `on_system` blocks (`on_#{arch}` and
`on_#{os}`).
- We're a bit of the way there, anyway. Still doesn't support stanza
ordering within blocks, but that's for another time (there's a
separate issue that's been open for a while - 14017).
- These were previously being manually fixed which is time maintainers
could have spent fixing more important problems.
- I don't work with Casks much at all, so I was unsure as to what the
existing "arch" and "on_arch_conditional" parts were, if they're
deprecated or if things were eventually going to migrate to
`on_#{arch}` blocks?
- This skips over stanza names that are not overrideable in `on_*`
blocks, with the positive side effect that `on_*` blocks themselves
aren't in the list so we can get rid of another conditional.
- Stanzas overrideable in blocks are defined in `Cask::DSL` by each of
the methods calling `set_unique_stanza`.
- This came up in Cask `simply-fortran`:
```
Scanning /opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/simply-fortran.rb
send_node: s(:send, nil, :arch), send_node.parent: s(:begin,
s(:send, nil, :arch)), send_node.parent.parent: (regexp
(str "href=.*?simplyfortran[._-]v?(\\d+(?:\\.\\d+)+)")
(begin
(send nil :arch))
(str "\\.dmg")
(regopt :i))
Casks/simply-fortran.rb:2:3: C: Cask/NoOverrides: Do not use a top-level arch stanza as the default. Add it to an on_{system} block instead.
Use :or_older or :or_newer to specify a range of macOS versions.
arch arm: "-arm64", intel: "-x86_64"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected
```
- This passes the previously failing test for `on_*` blocks with
`livecheck` blocks with multiple stanzas inside them (eg `url` and
`strategy`) that weren't being correctly skipped because we weren't
detecting high enough up the ancestry.
- The Cask `little-snitch4` in `Homebrew/homebrew-cask-versions` was
failing and it took me a while to figure out _how_. Add a test for
easier further debugging (and to prevent breakage once the bug is
fixed).
```
❯ brew tests --only=rubocops/cask/no_overrides
Randomized with seed 29917
1 process for 1 spec, ~ 1 spec per process
F
Failures:
1) RuboCop::Cop::Cask::NoOverrides when there are livecheck blocks within `on_*` blocks, ignore their contents does not report any offenses
Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }
expected `[#<RuboCop::Cop::Offense:0x000000012de636c8 @severity=#<RuboCop::Cop::Severity:0x000000012de636a0 @name=:convention>, @location=#<Parser::Source::Range (string) 244...273>, @message="Do not use a top-level `url` stanza as the default. Add it to an `on_{system}` block instead.\nUse `:or_older` or `:or_newer` to specify a range of macOS versions.\n", @cop_name="Cask/NoOverrides", @status=:unsupported, @corrector=nil>].empty?` to be truthy, got false
Shared Example Group: "does not report any offenses" called from ./test/rubocops/cask/no_overrides_spec.rb:77
# ./test/rubocops/cask/shared_examples/cask_cop.rb:24:in `expect_no_offenses'
# ./test/rubocops/cask/shared_examples/cask_cop.rb:7:in `block (2 levels) in <module:CaskCop>'
Took 2 seconds
Tests Failed
```
This turns the ability to replace common paths with placeholders
into a mixin that can be used with both Casks and Formulae.
The idea here is to make formula hash generation more consistent.