652 Commits

Author SHA1 Message Date
Issy Long
6de61e4994
Ensure that stanza grouping works for nested stanzas with comments
- 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.
2023-04-13 15:59:18 +01:00
Markus Reiter
8b9ee05118
Cache Stanza#comments. 2023-04-12 23:08:49 +02:00
Issy Long
6e6493bd1b
Fix Stanza#source_range_with_comments
- All hail Sorbet for telling me that I forgot to rename this variable!
2023-04-12 20:52:38 +01:00
Issy Long
10bdb9f653
Don't pass cask_node into Stanza, stanza_node.parent is enough 2023-04-12 20:46:23 +01:00
Issy Long
519c1b46d8
In-line converting nodes to stanzas; move comment detection to Stanza
- Since comment detection is only used in `Stanza`, move it there.
- The `stanzaify` method was only in `CaskBlock` since the other use of
  `Stanza.new` was. Since it's only used in one other place, move it to
  where it's used.
2023-04-12 20:46:22 +01:00
Issy Long
233db299cd
rubocop/cask: Check for correct stanza grouping within on_* blocks
- 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.
2023-04-12 20:46:20 +01:00
Issy Long
0c2e6e59c5
rubocop: Remove redundant Style/InverseMethods disables 2023-04-07 21:35:38 +01:00
Mike McQuaid
3404767cd0
Merge pull request #15154 from apainintheneck/cop-to-prevent-bin-in-service-blocks 2023-04-05 11:35:33 +01:00
apainintheneck
70451ea7b1 Add cop to stop bin in service block
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
2023-04-04 20:00:30 -07:00
Issy Long
7bb20a3b83
Skip if the URL stanza has only two path components
https://github.com/Homebrew/homebrew-cask-fonts/pull/7336#discussion_r1156325651
2023-04-04 16:11:44 +01:00
Issy Long
28f8cbe8da
Handle when the URL has interpolation: use source not str_content
- We see this a lot in real Casks.
2023-04-02 23:39:43 +01:00
Issy Long
41c35986f8
Simplify the 'should not start with https?://' message wording
Co-authored-by: Markus Reiter <me@reitermark.us>
2023-04-02 22:43:57 +01:00
Issy Long
21da074346
Only 'verified' stanzas with 0 or >1 path components should end with "/"
Handle good things like:

```ruby
url "https://example.org/download",
    verified: "example.org/download" # This is fine.
```

And bad things like:

```ruby
url "https://example.org/",
    verified: "example.org" # This should end with a slash.
```
2023-04-02 22:26:23 +01:00
Issy Long
17c0eaab25
Fix indentation of verified in url stanza examples 2023-04-02 16:41:29 +01:00
Issy Long
b586d97f84
rubocops/cask: Ensure that "verified" URLs with paths end with "/"
- These were being fixed manually[1], so let's make a RuboCop for any
  further occurrences since this is a good rule to enforce[2].

[1] - https://github.com/Homebrew/homebrew-cask/pull/144179#issuecomment-1489857249
[2] - https://github.com/Homebrew/homebrew-cask/pull/80965#issuecomment-616232313
2023-04-02 15:29:53 +01:00
Issy Long
85dd9bdc44
Merge pull request #15079 from issyl0/revert-allowing-resource-blocks-to-have-conditionals-or-on-blocks 2023-03-29 12:11:17 +01:00
Issy Long
039a434936
Merge pull request #14976 from issyl0/rubocop-cask-on-arch-block-order
rubocops/cask: Enforce the order of `on_#{arch}` blocks
2023-03-29 12:10:37 +01:00
Issy Long
9302090404
Revert "Allow resource blocks to include on_* blocks or conditionals"
This reverts commit b4cd90a3cc47bc2f94e4449fa99b37445b878a5f.

This should never have been merged, given its extraction into PR 15062
had a reasonably long discussion and was decided against in
https://github.com/Homebrew/homebrew-core/pull/126705#discussion_r1149545828,
but I didn't realise I hadn't backed it out of PR 15060 before it was
approved and I merged it.
2023-03-29 00:40:46 +01:00
Issy Long
222ef50063
Merge pull request #15060 from issyl0/formula-block-component-order 2023-03-28 22:09:15 +01:00
Issy Long
b4cd90a3cc
Allow resource blocks to include on_* blocks or conditionals
- d2a58a7853 was deemed "unwiedly", but it passes the RuboCop.
- https://github.com/Homebrew/homebrew-core/pull/126705#discussion_r1148558613 is more wieldy, but needed RuboCop tweaks.
2023-03-26 18:25:33 +01:00
Markus Reiter
3da305fa80
Add keyboard_layout stanza. 2023-03-26 08:14:24 +02:00
Issy Long
2d781d23e0
rubocops: Detect unordered stanzas in non-on_* blocks in formulae
- 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.
2023-03-26 02:31:42 +01:00
Issy Long
0af5825dfb
rubocops/cask: on_#{os_version} is after [version & sha256] group
- 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.
2023-03-25 16:02:30 +00:00
Issy Long
48b1279b00
cask/audits: on_#{os_version} stanza order is oldest => newest
- 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.
2023-03-25 14:52:30 +00:00
Issy Long
d97ed0a7c2
rubocops/cask: Ensure ordering of all the on_#{arch,system} blocks
- 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).
2023-03-25 14:52:29 +00:00
Issy Long
b484a29006
rubocops/cask: arch stanzas come before & are separate to on_#{arch}
- https://github.com/Homebrew/brew/pull/14976#issuecomment-1469002998.
- This drops the number of offenses currently in the Cask repo down from
  111 to 46.
2023-03-25 14:52:28 +00:00
Issy Long
b6062acdbe
rubocops/cask: Enforce the order of on_#{arch} blocks
- 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?
2023-03-25 14:52:24 +00:00
Issy Long
e4156909d4
Only take overrideable stanzas into account
- 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`.
2023-03-23 18:59:29 +00:00
Issy Long
d4d413db62
String interpolations in regexps should also be allowed
- 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
```
2023-03-23 13:55:00 +00:00
Issy Long
c1de3dfb90
Fix string interpolation detection again to be even broader
- My approach wasn't quite good enough. Replace it with what RuboCop
  itself does to detect all forms of string interpolation.
2023-03-23 13:17:09 +00:00
Issy Long
e66226aefc
Fix skipping of livecheck block contents in on_* blocks
- 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.
2023-03-22 23:17:32 +00:00
Issy Long
b82c5f1d36
Fix detection of string interpolation
- This was almost there but not quite and the lack of tests lulled me into a false sense of security.
2023-03-22 19:13:47 +00:00
Issy Long
8091e603df
rubocops/cask: Ignore livecheck blocks within on_* blocks
- The Cask `sip`, to give a random example, was failing this RuboCop
  because it has a `livecheck` block within an `on_*` block and the
  livecheck block and the top-level Cask both have `url` stanzas. This
  is a legitimate use of `livecheck` blocks because the cask software
  download URL and the livecheck version check URL are not the same
  thing, so let's skip over `livecheck` blocks and their contents.
2023-03-21 23:49:54 +00:00
Issy Long
794cd37dbb
Remove unnecessary skip since toplevel_stanzas doesn't look in blocks
Co-authored-by: Markus Reiter <me@reitermark.us>
2023-03-21 22:51:28 +00:00
Issy Long
7a4a579847
rubocops/cask: Run on_system_stanzas(on_block) once in the beginning
Co-authored-by: Markus Reiter <me@reitermark.us>
2023-03-21 22:51:27 +00:00
Issy Long
c337dc4c81
rubocops/cask: Skip string interpolations when determining inner stanzas
- Otherwise syntax like this, where `#{arch}` is an interpolation,
  causes an offense:

```ruby
cask "transcribe" do
  arch arm: "_arm"

  on_catalina :or_older do
    version "8.75.2"
    sha256 "f01781100cd3b9987c8f8892145a2eaa358df07b92e10e26f30b6a877f5b352c"

    url "https://www.seventhstring.com/xscribe/downmo/transcribe#{version.no_dots}.dmg"

    livecheck_version = "10"
  end
  on_big_sur :or_newer do
    livecheck_version = "11"

    version "9.21"
    sha256 :no_check

    url "https://www.seventhstring.com/xscribe/transcribe#{arch}.dmg"
  end
  [...]
end
```

```
Casks/transcribe.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: "_arm"
  ^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
```
2023-03-21 22:51:26 +00:00
Markus Reiter
e04101007f
Fix check for Set. 2023-03-21 22:51:25 +00:00
Issy Long
deb8a13a73
rubocops/cask: Make names, the list of method names in on_*, a Set
Co-authored-by: Markus Reiter <me@reitermark.us>
2023-03-21 22:51:24 +00:00
Issy Long
0b7bd81959
rubocops/cask: No need for the first return if, [].each works OK 2023-03-21 22:51:24 +00:00
Issy Long
35cd764261
rubocops/cask: Tweak offense message to read better 2023-03-21 22:51:20 +00:00
Issy Long
2c5165850a
rubocops/cask: Check ON_SYSTEM_METHODS instead of STANZA_ORDER
- This is already here and used in multiple places. Continuing to use
  `STANZA_ORDER` will break this cop when we add `ON_SYSTEM_METHODS`
  to that list.
2023-03-21 22:51:19 +00:00
Issy Long
ff2fad6bcf
rubocops/cask: Don't force on_* blocks for all stanzas
- In the event that there's only one common stanza within the `on_*`
  blocks (eg, `url`) with a generic `version` that doesn't change per-OS,
  let's not force adding `version` to each `on_*` block as well.
2023-03-21 22:51:18 +00:00
Issy Long
dec1309140
rubocops/cask: Casks with zero on_* blocks are still valid 2023-03-21 22:51:17 +00:00
Issy Long
5ce4966f4a
rubocops/cask: Use ON_SYSTEM_METHODS for skipping
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2023-03-21 22:51:16 +00:00
Issy Long
9cc046bc60
rubocops/cask: Enforce the use of on_{system} blocks
- As discussed in
  https://github.com/Homebrew/brew/pull/14976#issuecomment-1474544569
  and further comments, this is needed because in order to enforce the
  order of `on_{arch,system}` blocks we need to have everything
  consistently within one of those blocks.
- We previously allowed overrides where the top-level `version` stanza
  would be the default, unless on an OS that had an `on_system` block
  with a `version` specified. But this breaks down when we try to order
  the `on_system` blocks because if a `url` at the top-level has a
  `version` interpolated in it, then the `version` stanza needs to be
  above the `url` stanza. But it could be that `version` is OS-specific.
- Let's stop allowing overrides and require that everything be in an
  `on_system` block. This will make it easier to enforce the order of
  `on_system` blocks in a future PR (14976).
2023-03-21 22:51:12 +00:00
Markus Reiter
3c89f99df1
Fix toplevel_stanzas. 2023-03-21 14:43:59 +01:00
Douglas Eichelberger
cc5b013cb9 Remove compatibility layer 2023-03-14 14:49:34 -07:00
Issy Long
f1ab720000
rubocop: Drop "c1" and "c2" from Naming/MethodParameterName allowlist 2023-03-09 21:54:37 +00:00
Mike McQuaid
9e370b0a3d
Merge pull request #14847 from dduugg/no-to_sentence
Move Array#to_sentence monkey-patch from ActiveSupport to extend/
2023-03-06 12:37:02 +00:00
Issy Long
2aeeaf706e
Merge pull request #14891 from issyl0/cask-rubocops-unnecessary-requires 2023-03-06 12:23:49 +00:00