737 Commits

Author SHA1 Message Date
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
Issy Long
1d65c942c3
rubocops/cask: Clean up unnecessary requires
- I suspect these were copy-pasted from other cops, like I did in
  https://github.com/Homebrew/brew/pull/14886#discussion_r1125569999.
- The "forwardable" require is unnecesary if the cop doesn't
  `extend Forwardable` and use `def_delegator`.
- The "uri" require is unnecessary if the cop doesn't call `URI` methods.
2023-03-05 17:13:46 +00:00
Issy Long
4e067565dd
rubocops/cask/url: Fix test expectations; regexp for starts_with? 2023-03-05 16:55:47 +00:00
Issy Long
4791224acf
rubocops/cask/url: Remove unnecessary require "forwardable" 2023-03-05 16:38:10 +00:00
Issy Long
f4a0bc7af3
rubocops/cask: Appease Sorbet with the correct inheritance
- The `on_url_stanza` method is now used in two cops, `Url` and
  `UrlLegacyCommaSeparators`. Make the latter inherit from the former
  to make Sorbet happy.
- The style and typecheck checks now pass fine.
2023-03-05 16:33:11 +00:00
Issy Long
79db987215
rubocops/cask: Disallow protocol in cask URL verified stanza
- Apparently the "verified" parameter in the URL (present when a Cask's
  download URL is not the same as its homepage) shouldn't have the
  protocol (`https`, `http`) at the front.
- Removing this has happened manually in the past, so here's an
  autocorrecting RuboCop for it.
2023-03-04 23:00:04 +00:00
Douglas Eichelberger
e94d3767e6 Add rails license 2023-03-03 12:44:23 -08:00
Douglas Eichelberger
317874c394 Fix type error 2023-03-03 12:44:23 -08:00
Douglas Eichelberger
e68b02c4a6 Move tests and requires 2023-03-03 12:44:23 -08:00
Douglas Eichelberger
ecfceb3fee Revert Utils implementation 2023-03-03 12:44:23 -08:00
Douglas Eichelberger
b8ddecf322 Fix type error 2023-03-03 12:44:22 -08:00
Douglas Eichelberger
d8d4d2031e Isolate to allow rubocop access 2023-03-03 12:44:22 -08:00
Douglas Eichelberger
91ad24b876 Remove Array#to_sentence monkey-patch 2023-03-03 12:44:22 -08:00
Douglas Eichelberger
ef2baee799 disable false positive 2023-03-02 11:49:09 -08:00
Douglas Eichelberger
71402a9a41 Disable false positive violation 2023-03-02 11:49:09 -08:00
Douglas Eichelberger
ed8363fd72 Consolidate some rubocop configurations 2023-02-21 16:50:29 -08:00