35 Commits

Author SHA1 Message Date
Issy Long
0fc1eb534b
More Sorbet typed: strict RuboCops
- Some of these I bumped to `typed: strict`, some of them I added
  intermediary type signatures to some of the methods to make my life
  easier in the (near, hopefully) future.
- Turns out that RuboCop node matchers that end in `?`
  can return `nil` if they don't match anything, not `false`.
2025-02-08 23:38:12 +00:00
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
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07: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
e98e668a34 remove redundant string extension 2023-01-28 08:26:11 -08:00
Bo Anderson
6ede5d2dd5
rubocops: handle empty formula body in various cops 2022-11-05 04:40:16 +00:00
Rylan Polster
ae89577b26
style: re-enable GitLab patch URL check 2021-04-19 11:19:35 -04:00
Rylan Polster
b5dec5fdbd
style: temporarily disable GitLab patch URL check 2021-04-19 09:13:06 -04:00
Jonathan Chang
ef1e07b88b
rubocops/patches: GitLab patches should use .diff
Only `.diff` URLs return output comparable to the diffs from
`git diff --full-index`. While the extra metadata from `.patch` is
nice, the instability of the patch contents is undesirable.

Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2021-04-19 09:08:14 -04:00
Nanda H Krishna
1c2d76c4e4
rubocops/patches: remove autocorrection of some URLs 2021-04-17 01:44:28 +05:30
Issy Long
a328acc9a1
rubocops/patches: Fix quoting of the patch url when autocorrecting
- The autocorrections here before were leading to changes like:

```
➜ brew style --fix brewsci/science/beetl
Formula/beetl.rb:15:11: C: [Corrected] GitHub patches should use the full_index parameter: https://github.com/BEETL/BEETL/commit/ba47b6f9.patch?full_index=1
      url "https://github.com/BEETL/BEETL/commit/ba47b6f9.patch"
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

➜ git diff
diff --git a/Formula/beetl.rb b/Formula/beetl.rb
index bbd049aa..7ec6d7bc 100644
--- a/Formula/beetl.rb
+++ b/Formula/beetl.rb
@@ -12,7 +12,7 @@ class Beetl < Formula
     # Fixes "error: 'accumulate' is not a member of 'std'"
     # Upstream commit "Little fix for compilation on mac"
     patch do
-      url "https://github.com/BEETL/BEETL/commit/ba47b6f9.patch"
+      url https://github.com/BEETL/BEETL/commit/ba47b6f9.patch?full_index=1
       sha256 "63b67f3282893d1f74c66aa98f3bf2684aaba2fa9ce77858427b519f1f02807d"
     end
   end

```

- This fixes the URLs generated to have quotes:

```
➜ git diff
diff --git a/Formula/beetl.rb b/Formula/beetl.rb
index bbd049aa..7ec6d7bc 100644
--- a/Formula/beetl.rb
+++ b/Formula/beetl.rb
@@ -12,7 +12,7 @@ class Beetl < Formula
     # Fixes "error: 'accumulate' is not a member of 'std'"
     # Upstream commit "Little fix for compilation on mac"
     patch do
-      url "https://github.com/BEETL/BEETL/commit/ba47b6f9.patch"
+      url "https://github.com/BEETL/BEETL/commit/ba47b6f9.patch?full_index=1"
       sha256 "63b67f3282893d1f74c66aa98f3bf2684aaba2fa9ce77858427b519f1f02807d"
     end
   end
```
2021-04-16 19:41:02 +01:00
nandahkrishna
d68452f232
rubocops/patches: autocorrect some offenses 2021-03-04 12:36:18 +05:30
Jonathan Chang
df8e030174 rubocops/patches: use rubocop v1 API 2021-01-12 19:11:43 +11:00
Seeker
b9854bd4cf rubocops: add unless_multiple_conditions 2021-01-08 10:33:54 -08:00
Markus Reiter
da9289eff0 Add more type signatures. 2020-11-13 12:26:36 +01:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Seeker
ea10192f8b rubocops/patches: GitHub/GitLab patches should end with .patch 2020-10-21 00:03:47 +11:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
8b97c27c21 brew style manual fixes 2020-09-01 14:26:45 +01:00
Dustin Rodrigues
de8cc4106a style: don't allow PR/MR urls for patches 2020-08-01 16:20:46 -04:00
Dustin Rodrigues
af3ea7d5aa Revert "style: don't allow PR/MR urls for patches"
This reverts commit 7a2483728c18e9cfb45e4b3f079687ec5a8e1503.
2020-07-28 21:20:46 -04:00
Dustin Rodrigues
7a2483728c style: don't allow PR/MR urls for patches 2020-07-28 10:18:26 -04:00
Frank Lam
ffb1cc8e19
Find patch nodes nested inside blocks 2020-06-27 03:13:50 +08:00
Frank Lam
afb8445380
Add inline patch checks to patches cop 2020-06-27 01:10:52 +08:00
Mike McQuaid
632813d969
rubocops/patches: reduce required revision length. 2020-04-13 16:01:26 +01:00
Alexander Bayandin
b37c3e9cb2 rubocops/patches: suggest url with full_index=1 2020-03-15 11:24:38 +00:00
Issy Long
9f80a7bce2
rubocops/patches: Make more GitHub patch locations enforce revisions
- We recently deleted a load of old Homebrew/formula-patches patches for
  non-existent core formulae
  (https://github.com/Homebrew/formula-patches/pull/283). This is a good
  action to take. Users should always be able to retrieve the patch once
  it's been deleted from the repo, if the formula they continue to use
  specifies a git revision to pull from, not just `master`.
- The code to detect `master` formulae was already here, so this adds
  another GitHub host to the detection: `raw.githubusercontent.com` as
  that's what the current patches that use `master`
  (https://github.com/Homebrew/homebrew-core/pull/51329) link to.
- Fixes https://github.com/Homebrew/homebrew-core/issues/51313.
2020-03-08 20:21:43 +00:00
Issy Long
1f6168fe8a
Change regexp.match?(string) to string.match?(regexp) everywhere
- Only try to call `.match?` on strings that aren't nil.
2019-10-13 23:22:51 +01:00
Issy Long
37fee928b5
Auto-fix Style/NegatedIf offenses 2019-10-13 16:04:35 +01:00
Issy Long
b78028b9c2
Auto-fix Performance/RegexpMatch offenses 2019-10-13 16:04:26 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
EricFromCanada
89f0fcedbe whitespace fixes 2019-04-13 21:32:04 -04:00
Mike McQuaid
376eac2b8d
rubocops: rename files for consistency.
Make the filenames consistent with the class names.
2018-11-08 14:42:55 +00:00