53 Commits

Author SHA1 Message Date
Issy Long
45978435e7
rubocop: Use Sorbet/StrictSigil as it's better than comments
- Previously I thought that comments were fine to discourage people from
  wasting their time trying to bump things that used `undef` that Sorbet
  didn't support. But RuboCop is better at this since it'll complain if
  the comments are unnecessary.

- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.

- I've gone for a mixture of `rubocop:disable` for the files that can't
  be `typed: strict` (use of undef, required before everything else, etc)
  and `rubocop:todo` for everything else that should be tried to make
  strictly typed. There's no functional difference between the two as
  `rubocop:todo` is `rubocop:disable` with a different name.

- And I entirely disabled the cop for the docs/ directory since
  `typed: strict` isn't going to gain us anything for some Markdown
  linting config files.

- This means that now it's easier to track what needs to be done rather
  than relying on checklists of files in our big Sorbet issue:

```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
    268
```

- And this is confirmed working for new files:

```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        Library/Homebrew/bad.rb
        Library/Homebrew/good.rb

nothing added to commit but untracked files present (use "git add" to track)

$ brew style
Offenses:

bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^

1340 files inspected, 1 offense detected
```
2024-08-12 15:24:27 +01:00
Sam Ford
17b0493e18
Use struct for #audit_formula args
Adding type signatures to `#audit_formula` methods in formula cops
would lead to verbose, repetitive signatures across the existing ~63
instances. This reworks `#audit_formula` to use a `T::Struct` for its
arguments, which allows us to use a one-line signature for these
methods.
2024-07-08 12:22:25 -04:00
Issy Long
f4218a6316
Fix RuboCop Performance/MapCompact offenses
- Rename an iterator variable since it would make the line too long.
2024-02-25 22:59:59 +00:00
Issy Long
0c2e6e59c5
rubocop: Remove redundant Style/InverseMethods disables 2023-04-07 21:35:38 +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
f1ab720000
rubocop: Drop "c1" and "c2" from Naming/MethodParameterName allowlist 2023-03-09 21:54:37 +00:00
Douglas Eichelberger
ef2baee799 disable false positive 2023-03-02 11:49:09 -08:00
Douglas Eichelberger
387d2f859f Use exclude_from_registry instead 2023-02-20 18:14:47 -08:00
Douglas Eichelberger
d9db5e8825 Refactor FormulaCop as a mixin 2023-02-20 18:14:47 -08:00
Douglas Eichelberger
6c93f6fe91 Enable typing in rubocops 2023-02-16 15:51:20 -08:00
Mike McQuaid
6b4363092d
Revert "Merge pull request #14548 from Homebrew/revert-14382-deprecate-disable-remove"
This reverts commit 932d2cf3b77c9439a57b6a43577fc8d3b6399a62, reversing
changes made to f4e60482791d2ff628efadfdbf0d14d9237d2d29.
2023-02-07 19:25:51 +01:00
Mike McQuaid
6882ac17e7
Revert "Add deprecations and disables" 2023-02-07 15:13:19 +01:00
Carlo Cabrera
f576140ade
Remove Rubocop for ignore_missing_libraries
This is no longer needed.
2023-01-26 13:48:06 +08:00
Bo Anderson
6ede5d2dd5
rubocops: handle empty formula body in various cops 2022-11-05 04:40:16 +00:00
Sam Ford
40199404cf
Allow livecheck method in on_system blocks
It's sometimes necessary to have a `livecheck` block in an `on_macos`
or `on_linux` block. For example, a formula may be disabled on macOS
but not on Linux. In that scenario, we only want a `livecheck` block
to apply to Linux, so livecheck will automatically skip the formula
as disabled on macOS.

While this setup works on a technical level, `brew style` will give
an `on_linux cannot include livecheck` offense. This commit addresses
the issue by adding `livecheck` to `on_system_allowed_methods` in the
`ComponentsOrder` Rubocop.

This also updates `on_system_allowed_methods` to use the order in
`FORMULA_COMPONENT_PRECEDENCE_LIST`, which may make it a bit easier
for formula maintainers to read at a glance.
2022-10-18 16:02:29 -04:00
fn ⌃ ⌥
d5f949e60b Check dependency order in on_system methods 2022-08-03 06:33:30 -07:00
Rylan Polster
2c3926ae1e
Check nesting for blocks with one child 2022-07-24 23:37:36 +02:00
Rylan Polster
a4327521d5
Add on_system to and reorder component order cop 2022-07-24 23:37:35 +02:00
Rylan Polster
9b49561066
Update components_order cop to check other on_{system} methods 2022-07-01 10:52:41 -04:00
Mike McQuaid
2d5eab2e1c
brew style --fix 2022-06-30 08:56:21 +01:00
Nanda H Krishna
5ccfbcd1d2
Autocorrect style issues with brew style --fix 2021-07-08 12:36:39 +05:30
Dawid Dziurla
d50bd605b8
components_order: allow ignore_missing_libraries in on_os 2021-07-04 18:34:03 +02:00
danielnachun
5af7521ab8
components_order: allow keg_only in on_macos/on_linux blocks 2021-05-30 19:03:04 -07:00
Michka Popoff
865fb15ad7
on_os block: allow to contain conflicts_with
Some conflicts are os-specific.
2021-02-08 13:27:04 +01:00
Seeker
33edb9f901 rubocops: point to offending OS-specific block in resource blocks 2021-01-13 23:18:32 -08:00
Jonathan Chang
641afdd2de rubocops: permit mirror in OS-specific resources 2021-01-14 17:04:40 +11:00
Jonathan Chang
c3f797d9ac rubocops/components_order: use rubocop v1 API 2021-01-12 19:11:43 +11:00
Jonathan Chang
f81e89193e rubocops: update helpers for rubocop v1 API 2021-01-12 19:11:42 +11:00
Seeker
332778025a utils/ast: add Sorbet method signatures 2021-01-07 13:54:05 -08:00
Seeker
4924b7633c components_order: allow if-else statements inside on_os blocks
Co-Authored-By: Rylan Polster <rslpolster@gmail.com>
2020-12-23 19:28:11 -05:00
Rylan Polster
27ce5754c9 style: fix on_macos/on_linux resource block checks 2020-12-23 17:04:24 -05:00
Seeker
85373df30e
Merge pull request #9095 from SeekingMeaning/bottle-ast
bottle: add bottle stanza by traversing AST
2020-12-11 09:05:14 -08:00
Seeker
b8aa67be5b bottle: add bottle stanza by traversing AST 2020-12-10 13:38:57 -08:00
Seeker
c4da302303 on_macos/on_linux block: improve rubocop message
Co-authored-by: Markus Reiter <me@reitermark.us>
2020-12-10 11:47:25 -08:00
Seeker
5a643ff0db on_macos/on_linux block: fix rubocop for special cases 2020-12-08 14:33:47 -08:00
Rylan Polster
1dbbcfd1d6 Migrate COMPONENTS_ORDER_EXCEPTIONS 2020-11-30 18:18:50 -05:00
Michka Popoff
a044f99d56 on_macos/on_linux block: allow to use deprecate or disable 2020-11-20 22:14:56 +01:00
Issy Long
7bcf554799
rubocops/components_order: Specify disable! and deprecate! order
- Ordering them this way seems to require less `--fix`ing in
  Homebrew/homebrew-core than the other way around.
- In the Big Sur bottling, we found many repos that were archived. We've
  been going through and deprecating repos that are archived or that
  don't build any more. I felt weird without the ordering of these
  stanzas without an audit to guide me - I spent time looking at
  previous examples to see "should `deprecate!` go before or after
  `depends_on`" question. Computers can tell us this instead.
2020-11-18 21:44:46 +00:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
2e5272d04c Deprecate/disable code for Homebrew 2.5.0.
Do the usual "disable deprecations" and "uncomment pending deprecations"
dance and delete/deprecate/disable relevant/related code.
2020-09-03 10:34:22 +01:00
Dawid Dziurla
2cd72908bc
Merge pull request #7863 from iMichka/single-resource
on_os resources: allow linux-only or mac-only resources
2020-07-20 16:58:30 +02:00
Michka Popoff
edd1685d37 on_os resources: allow linux-only or mac-only resources
This is now allowed since #7833 has been fixed.
2020-07-10 23:16:43 +02:00
lionellloh
7358dd7bba style fixes 2020-06-30 23:25:51 +08:00
lionellloh
1422542a07 components_order and test 2020-06-30 23:18:04 +08:00
Michka Popoff
8d55c87adb
components order: fix audit and add test 2020-06-30 08:36:11 +01:00
Issy Long
0041ea21f5
Change occurrences of "whitelist" to "allowlist" 2020-06-06 22:38:32 +01:00
Michka Popoff
c494528f15 on_os_blocks: add audit 2020-06-04 17:36:28 +02:00
nandahkrishna
a4f9a66406
livecheck: add component order rubocop 2020-05-15 19:00:14 +05:30
Jonathan Chang
abf2b83b35 audit: add uses_from_macos dependency ordering 2020-01-12 11:12:27 -08:00