75 Commits

Author SHA1 Message Date
Patrick Linnane
cb15b67b8e
various: correct Style/CollectionQuerying
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2025-07-11 10:43:00 -07:00
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
Patrick Linnane
5466d6a57a
Replace deprecated Cop.registry with Registry.global
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-07-10 13:07:02 -07: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
Mike McQuaid
97ad3567d1
Optimise more command handling/speed
- in `brew.sh` split the `case` into those cases that take a single or
  no arguments and those that take multiple arguments or handle
  multiple commands. This considerably speeds up the
  `brew shellenv bash` case that wasn't being handled here before.
- add `setup-ruby` to the list of commands that can be called quickly
  by `brew.sh` without additional setup. This speeds up the
  `brew setup-ruby` no-op case by ~10x.
- add a parameter to `setup-ruby` to avoid running Bundler if the
  command doesn't need it. This makes many more cases for
  `brew setup-ruby` to be no-op cases.
- Remove the (now) unused `HOMEBREW_RUBY3` check in `setup-ruby`.
- Improve argument handling in `command_path.sh` to allow it to be
  used as a function in `setup-ruby.sh`.
- Add a new RuboCop to check usage of `install_bundler_gems!` is only
  inside `dev-cmd` (or a few other acceptable places).
- Use new `processed_source.file_path` API in `formula_cop.rb`
2024-04-30 12:48:29 +01:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Douglas Eichelberger
caf8259ae6 Code review changes 2023-12-27 15:29:33 -08:00
Douglas Eichelberger
3abbf4447e Some minor regexp match perf improvements 2023-12-27 13:16:36 -08:00
Bo Anderson
5692c8ecbf
Fix style violations under newer RuboCop 2023-12-14 05:47:12 +00:00
Mike McQuaid
d30fee25e4
formula_cop: fix style_exceptions_dir handling.
This needed to be adjusted to handle a sharded homebrew/core and
repositories with formulae in the root.
2023-08-09 15:20:57 +01:00
Markus Reiter
8274920217
Rename OS::Mac::Version to MacOSVersion. 2023-05-09 05:08:38 +02:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Douglas Eichelberger
cc5b013cb9 Remove compatibility layer 2023-03-14 14:49:34 -07:00
Douglas Eichelberger
bd5a7f6a14
Update formula_cop.rb 2023-02-21 09:52:20 -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
Mike McQuaid
376eac2b8d
rubocops: rename files for consistency.
Make the filenames consistent with the class names.
2018-11-08 14:42:55 +00:00
EricFromCanada
20167e5f1b Adjust comments to tidy API docs output. 2018-10-18 21:42:43 -04:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Markus Reiter
eca488a966 Add $LOAD_PATH for RuboCop cops. 2018-09-06 01:10:47 +02:00
Mike McQuaid
0aa9dce03c
Revert "Add $LOAD_PATH for RuboCop cops." 2018-09-02 20:49:25 +01:00
Markus Reiter
444e3d2a78 Add $LOAD_PATH for RuboCop cops. 2018-08-29 01:44:47 +02:00
Markus Reiter
44f56a0773 Refactor join("") to join. 2018-06-15 13:56:08 +02:00
Markus Reiter
a0ca601a1a Silence Parser compatibility warning. 2018-05-26 16:24:48 +02:00
Gautham Goli
efec2fa0c5 lines_cop: Add deprected options audit for depends_on 2018-05-06 15:42:51 +05:30
Gautham Goli
a8294a81c0 urls_cop: Search for func calls to match url and mirror calls 2018-04-10 03:22:32 +05:30
Mike McQuaid
d2c23bde6d Audit use of :run dependencies.
These are a no-op so let's remove them.
2018-03-19 10:11:08 +00:00
Mike McQuaid
83cca40fc9 RuboCop 0.53.0 manual fixes. 2018-03-08 14:10:02 +00:00
Mike McQuaid
8cd0d85afb rubocop 0.52.1 2018-01-15 16:17:32 +00:00
Mike McQuaid
7f2fda104a formula_cop: match any values in hash match.
e.g. match an array or symbol or string.
2018-01-09 20:08:22 +00:00
Mike McQuaid
4e29152603 formula_cop: use undeprecated add_offense form. 2018-01-07 14:25:07 +00:00
Mike McQuaid
c8b859faad lines_cop: flag depends_on :perl => "1.0".
This requires ignoring the version argument with a new `:any` mode
for this check.
2018-01-07 14:08:58 +00:00
Gautham Goli
fb85ed01bc lines_cop: Convert ARGV audit to negative look ahead 2017-12-02 17:03:11 +05:30
Gautham Goli
09326909af lines_cop: Fix detection of negated expression 2017-10-26 15:35:14 +05:30
Markus Reiter
7e970216a3 Refactor and fix RuboCop specs. 2017-10-24 19:39:40 +02:00
Gautham Goli
7b2fab8ec5 Merge branch 'master' into audit_line_rubocop_part_4_rebase_attempt_1 2017-10-21 13:53:44 +05:30
Markus Reiter
9bee9ca575 Use “squiggly” heredocs. 2017-10-18 14:39:09 +02:00
Gautham Goli
7fa51f71f1 Merge branch 'master' into audit_line_rubocop_part_4_rebase_attempt_1 2017-10-13 19:50:46 +05:30
Markus Reiter
9795195726 Fix RuboCop tests. 2017-10-07 23:30:47 +02:00
Mike McQuaid
bf0ab938e7 Merge pull request #3091 from GauthamGoli/audit_line_rubocop_part_3
audit: Port line_problems to rubocop and add tests part 3
2017-09-05 18:10:02 +01:00
Gautham Goli
4ec26aea40 audit: Port audit_class to rubocop, add tests and autocorrect 2017-09-04 23:43:42 +05:30
Gautham Goli
337d5c6470 audit: Fetch formula name from file path rather than class name in cops 2017-09-04 15:05:43 +05:30
Gautham Goli
b582ed513b audit: Add tests for rubocop methods in line_cop.rb 2017-09-04 15:05:43 +05:30
Gautham Goli
267def28fa audit: Port rules from line_problems to rubocop part 3 2017-09-04 15:05:43 +05:30
JCount
6023e408da Merge pull request #2995 from GauthamGoli/audit_line_rubocop_part_2
audit: Port line_problems to rubocop and add tests part 2
2017-08-23 16:16:07 -04:00
Gautham Goli
efabd4b5c2 Add tests for MACOS version consts usage 2017-08-15 00:42:56 +05:30
Gautham Goli
3efba57cd9 Add negated? method to formula cop and add tests for negated build.without? 2017-08-14 02:18:46 +05:30
Gautham Goli
e14fedd1b3 Add test for negated build.with? 2017-08-14 02:14:20 +05:30
Gautham Goli
6dad9d8b44 Add test for top level method def 2017-08-14 01:25:44 +05:30