389 Commits

Author SHA1 Message Date
Douglas Eichelberger
9075cbae62 brew style --fix 2023-04-21 09:58:50 -07:00
Douglas Eichelberger
ac1e6ded9a git grep -l '# typed: false' | xargs gsed -i 's|# typed: false||g' 2023-04-21 09:57:47 -07:00
Issy Long
e51ad41434
Delete a Cask RuboCop test for an edge case that is not fixed
- 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.
2023-04-15 23:09:42 +01:00
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
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
da734a30c2
Say yes to RuboCop's DisplayCopNames; fix test expectations
- 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.
2023-04-07 19:14:07 +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
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
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
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
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
0889593e2a
Another failing test for a real Cask, version.csv.first interpolated 2023-03-23 00:02:17 +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
991e5f2f9c
Failing test for mishandling contents of livecheck blocks in on_*
- 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
```
2023-03-22 21:41:28 +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
bc796a3120
Add a failing test for the arch inside url inside on_* weirdness
- So that I remember what's up with this after some sleep.
2023-03-22 00:23:38 +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
478ba9b604
rubocops/cask: Add another test case to check I've done it right?
- I wrote this because I was concerned that I'd done something wrong
  since `brew style --only=Cask/NoOverrides` in
  `$(brew --repo homebrew/cask)` didn't report any offenses. Turns out
  I'd just missed the `.` off the end of the command to target the
  current directory! But, the cost of writing the test is sunk now,
  and more tests can't hurt?
2023-03-21 22:51:22 +00:00
Issy Long
35cd764261
rubocops/cask: Tweak offense message to read better 2023-03-21 22:51:20 +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
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
Douglas Eichelberger
999594dc07 Remove oxford comma from to_sentence default 2023-03-11 17:27:53 -08:00
Issy Long
3a83b5492c
rubocop: Clean up Style/BlockDelimiters excludes and autofix offenses
- The defaults of using "do ... end" for multi-line blocks everywhere is
  good, better than switching everything to braces everywhere.
2023-03-08 23:54:22 +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
d995afc000
test/rubocops/cask/url: Ensure that autocorrection works 2023-03-05 17:08:43 +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
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
8527b01b2b Oxford commas 2023-03-03 18:07:39 -08:00
Douglas Eichelberger
d9db5e8825 Refactor FormulaCop as a mixin 2023-02-20 18:14:47 -08:00
Mike McQuaid
b9b3bd2571
brew style --fix 2023-02-10 08:59:51 +00:00
Douglas Eichelberger
dc78e91edd missed a few 2023-01-27 22:54:14 -08:00
Douglas Eichelberger
1dbeee826d replace undent with squiggly heredoc 2023-01-27 22:52:44 -08:00
Carlo Cabrera
86161e8c32
Fix test failures 2023-01-24 14:19:28 +08:00
Sam Ford
a1993b9086
rubocops/caveats: Disallow ANSI escape codes
Formula caveats text appears on formulae.brew.sh but escape
characters, as used in ANSI escape codes, should not appear in HTML.
This commit adds a RuboCop to disallow escape characters in the
caveats text.
2023-01-16 01:30:19 -05:00
Rylan Polster
d316819f0c
Add tests 2022-12-28 16:10:26 -05:00
Rylan Polster
a504d2c1aa
Check for loose Hardware::CPU method calls 2022-12-28 16:10:26 -05:00
Mike McQuaid
77c0d38c35
brew style --fix 2022-12-13 11:37:06 +00:00
apainintheneck
c477b9aab3 Cleanup after adding os specific rubocop
- Change name of rubocop warning
- Disable linting on remaining offending lines
- Add todos to move lines with disabled linting
  checks to extend/os in the future
2022-11-29 23:13:50 -08:00
apainintheneck
c7d53a2d9c Add cop to police os checks
The methods `OS.linux?` and `OS.mac?` should only be used
in `extend/os` and this cop makes sure of that.
2022-11-19 22:01:13 -08:00