brew/Library/.rubocop.yml

509 lines
12 KiB
YAML
Raw Normal View History

---
plugins:
2025-03-04 12:23:34 -08:00
- rubocop-md:
plugin_class_name: RuboCop::Markdown::Plugin
2025-03-04 13:10:48 -08:00
- rubocop-performance:
plugin_class_name: RuboCop::Performance::Plugin
- rubocop-rspec:
plugin_class_name: RuboCop::RSpec::Plugin
- rubocop-sorbet:
plugin_class_name: RuboCop::Sorbet::Plugin
require:
- ./Homebrew/rubocops.rb
inherit_mode:
merge:
- Include
- Exclude
AllCops:
# TODO: This is the default parser in Ruby >= 3.4
# https://github.com/rubocop/rubocop-ast/blob/6b9136235219e9448ee4f369e17cf69bcd9db621/lib/rubocop/ast/processed_source.rb#L385
ParserEngine: parser_prism
TargetRubyVersion: 3.3
NewCops: enable
2020-10-10 19:29:49 +02:00
Include:
2024-04-03 09:12:47 -07:00
- "**/*.rbi"
Exclude:
2025-05-20 20:59:24 -07:00
- "Homebrew/sorbet/rbi/{annotations,dsl,gems}/**/*.rbi"
- "Homebrew/sorbet/rbi/parser*.rbi"
- "Homebrew/bin/*"
- "Homebrew/vendor/**/*"
- "Taps/*/*/vendor/**/*"
SuggestExtensions:
rubocop-minitest: false
Cask/Desc:
Description: "Ensure that the desc stanza conforms to various content and style checks."
Enabled: true
Cask/HomepageUrlStyling:
Description: "Ensure that the homepage url has the correct format and styling."
Enabled: true
Cask/StanzaGrouping:
Description: "Ensure that cask stanzas are grouped correctly. More info at https://docs.brew.sh/Cask-Cookbook#stanza-order"
Enabled: true
Cask/StanzaOrder:
Description: "Ensure that cask stanzas are sorted correctly. More info at https://docs.brew.sh/Cask-Cookbook#stanza-order"
Enabled: true
FormulaAudit:
Enabled: true
FormulaAuditStrict:
Enabled: true
Homebrew:
Enabled: true
2021-04-14 16:08:37 +01:00
Homebrew/Blank:
Exclude:
# Core extensions are not available here:
2024-01-20 10:09:20 -08:00
- "Homebrew/startup/bootsnap.rb"
2024-01-26 13:47:59 -08:00
2024-01-26 13:24:32 -08:00
Homebrew/CompactBlank:
Exclude:
# `blank?` is not necessarily available here:
- "Homebrew/extend/enumerable.rb"
Homebrew/NoFileutilsRmrf:
Include:
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
# only used internally
Homebrew/MoveToExtendOS:
Enabled: false
2024-01-26 13:52:46 -08:00
Homebrew/NegateInclude:
Exclude:
# `exclude?` is not available here:
- "Homebrew/standalone/init.rb"
- "Homebrew/rubocops/**/*"
2024-02-04 12:58:34 -08:00
- "Homebrew/sorbet/tapioca/**/*"
2024-01-26 13:52:46 -08:00
# `system` is a special case and aligns on second argument, so allow this for formulae.
Layout/ArgumentAlignment:
Exclude:
- "Taps/*/*/*.rb"
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"
# this is a bit less "floaty"
Layout/CaseIndentation:
EnforcedStyle: end
# currently bugged and as relevant/urgent in taps:
# https://github.com/rubocop/rubocop/issues/14443
Layout/EmptyLinesAfterModuleInclusion:
Enabled: false
# significantly less indentation involved; more consistent
Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
# this is a bit less "floaty"
Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line
# make our hashes consistent
Layout/HashAlignment:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
# Need to allow #: for external commands.
Layout/LeadingCommentSpace:
Exclude:
- "Taps/*/*/cmd/*.rb"
# GitHub diff UI wraps beyond 118 characters
Layout/LineLength:
Max: 118
# ignore manpage comments and long single-line strings
AllowedPatterns:
[
"#: ",
' url "',
' mirror "',
" plist_options ",
' executable: "',
' font "',
' homepage "',
' name "',
' pkg "',
' pkgutil: "',
" sha256 cellar: ",
" sha256 ",
"#{language}",
"#{version.",
' "/Library/Application Support/',
'"/Library/Caches/',
'"/Library/PreferencePanes/',
' "~/Library/Application Support/',
'"~/Library/Caches/',
'"~/Library/Containers',
'"~/Application Support',
" was verified as official when first introduced to the cask",
]
# conflicts with DSL-style path concatenation with `/`
Layout/SpaceAroundOperators:
Enabled: false
# makes DSL usage ugly.
Layout/SpaceBeforeBrackets:
Exclude:
- "**/*_spec.rb"
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
# favour parens-less DSL-style arguments
Lint/AmbiguousBlockAssociation:
Enabled: false
Lint/DuplicateBranch:
Exclude:
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
# so many of these in formulae and can't be autocorrected
Lint/ParenthesesAsGroupedExpression:
Exclude:
- "Taps/*/*/*.rb"
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"
# unused keyword arguments improve APIs
Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true
# These metrics didn't end up helping.
Metrics:
Enabled: false
# Disabled because it breaks Sorbet: "The declaration for `with` is missing parameter(s): & (RuntimeError)"
Naming/BlockForwarding:
Enabled: false
2021-01-13 09:22:06 +01:00
# Allow dashes in filenames.
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# Implicitly allow EOS as we use it everywhere.
Naming/HeredocDelimiterNaming:
ForbiddenDelimiters:
- END, EOD, EOF
Naming/InclusiveLanguage:
CheckStrings: true
FlaggedTerms:
slave:
AllowedRegex:
- "gitslave" # Used in formula `gitslave`
- "log_slave" # Used in formula `ssdb`
- "ssdb_slave" # Used in formula `ssdb`
- "var_slave" # Used in formula `ssdb`
- "patches/13_fix_scope_for_show_slave_status_data.patch" # Used in formula `mytop`
2020-10-10 19:29:49 +02:00
Naming/MethodName:
AllowedPatterns:
- '\A(fetch_)?HEAD\?\Z'
2020-10-10 19:29:49 +02:00
Naming/MethodParameterName:
inherit_mode:
merge:
- AllowedNames
# Allows a nicer API for boolean methods with side effects.
Naming/PredicateMethod:
AllowBangMethods: true
# Both styles are used depending on context,
# e.g. `sha256` and `something_countable_1`.
Naming/VariableNumber:
Enabled: false
# Makes code less readable for minor performance increases.
Performance/Caller:
Enabled: false
# Does not hinder readability, so might as well enable it.
Performance/CaseWhenSplat:
Enabled: true
2020-11-16 22:18:56 +01:00
# Makes code less readable for minor performance increases.
Performance/MethodObjectAsBlock:
Enabled: false
2024-02-11 14:25:05 -08:00
RSpec:
Include:
- "Homebrew/test/**/*"
2024-02-11 14:25:05 -08:00
# Intentionally disabled as it doesn't fit with our code style.
RSpec/AnyInstance:
Enabled: false
RSpec/IncludeExamples:
Enabled: false
2023-12-14 15:34:15 +00:00
RSpec/SpecFilePathFormat:
Enabled: false
RSpec/StubbedMock:
Enabled: false
RSpec/SubjectStub:
2016-09-18 14:27:09 +01:00
Enabled: false
# These were ever-growing numbers, not useful.
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
RSpec/NestedGroups:
Enabled: false
RSpec/MultipleMemoizedHelpers:
Enabled: false
RSpec/DescribedClassModuleWrapping:
Enabled: true
# Annoying to have these autoremoved.
RSpec/Focus:
AutoCorrect: false
# We use `allow(:foo).to receive(:bar)` everywhere.
RSpec/MessageSpies:
EnforcedStyle: receive
2016-09-18 14:27:09 +01:00
2025-02-22 21:51:41 -08:00
# These are legacy violations that we should try to fix.
Sorbet/AllowIncompatibleOverride:
Exclude:
- "Homebrew/livecheck/strategy/*.rb"
# Try getting rid of these.
Sorbet/ConstantsFromStrings:
Enabled: false
2023-04-24 19:13:14 -07:00
# This is already the default
2020-09-20 05:57:37 +02:00
Sorbet/FalseSigil:
2023-04-21 09:57:25 -07:00
Enabled: false
2020-10-10 19:29:49 +02:00
2024-02-18 15:47:51 -08:00
# We generally prefer to colo rbi files with the Ruby files they describe.
Sorbet/ForbidRBIOutsideOfAllowedPaths:
Enabled: false
# T::Sig is monkey-patched into Module
Sorbet/RedundantExtendTSig:
Enabled: true
2020-10-10 19:29:49 +02:00
Sorbet/StrictSigil:
Enabled: true
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 10:30:59 +01:00
Exclude:
- "Taps/**/*"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
- "Homebrew/utils/ruby_check_version_script.rb" # A standalone script.
- "Homebrew/{standalone,startup}/*.rb" # These are loaded before sorbet-runtime
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 10:30:59 +01:00
- "Homebrew/test/**/*.rb"
- "Homebrew/bundle/{formula_dumper,checker,commands/exec}.rb" # These aren't typed: true yet.
2020-09-20 05:57:37 +02:00
2023-04-19 09:41:11 -07:00
Sorbet/TrueSigil:
Enabled: true
2023-04-19 09:41:11 -07:00
Exclude:
- "Taps/**/*"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
- "Homebrew/test/**/*.rb"
# Require &&/|| instead of and/or
Style/AndOr:
EnforcedStyle: always
# Disabled because it breaks Sorbet: "The declaration for `with` is missing parameter(s): & (RuntimeError)"
Style/ArgumentsForwarding:
Enabled: false
# Avoid leaking resources.
Style/AutoResourceCleanup:
Enabled: true
# This makes these a little more obvious.
Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/BlockDelimiters:
BracesRequiredMethods:
- "sig"
2016-09-25 02:41:14 +02:00
2024-02-18 15:47:51 -08:00
Style/ClassAndModuleChildren:
Exclude:
- "**/*.rbi"
# Use consistent style for better readability.
Style/CollectionMethods:
Enabled: true
# Don't allow cops to be disabled in casks and formulae.
Style/DisableCopsWithinSourceCodeDirective:
Enabled: true
Include:
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
# The files actually scanned in this cop are in `Library/Homebrew/.rubocop.yml`.
2016-09-25 02:41:14 +02:00
Style/Documentation:
Exclude:
- "Taps/**/*"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
- "**/*.rbi"
2024-06-30 01:21:54 +01:00
# This is impossible to fix if the line exceeds the maximum length.
Style/EmptyMethod:
Exclude:
- "**/*.rbi"
# This is quite a large change, so don't enforce this yet for formulae.
# We should consider doing so in the future, but be aware of the impact on third-party taps.
Style/FetchEnvVar:
Exclude:
- "Taps/*/*/*.rb"
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"
# Not used for casks and formulae.
Style/FrozenStringLiteralComment:
EnforcedStyle: always
Exclude:
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
- "Homebrew/test/**/Casks/**/*.rb"
- "**/*.rbi"
- "**/Brewfile"
2020-03-13 21:14:24 +00:00
# potential for errors in formulae too high with this
Style/GuardClause:
Exclude:
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
# Allow for license expressions
Style/HashAsLastArrayItem:
Exclude:
- "Taps/*/*/*.rb"
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"
Style/InverseMethods:
InverseMethods:
:blank?: :present?
Style/InvertibleUnlessCondition:
Enabled: true
InverseMethods:
# Favor `if a != b` over `unless a == b`
:==: :!=
# Unset this (prefer `unless a.zero?` over `if a.nonzero?`)
:zero?:
:blank?: :present?
Style/MutableConstant:
# would rather freeze too much than too little
EnforcedStyle: strict
# Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# Only require this for numbers >= `10_000_000_000`.
Style/NumericLiterals:
MinDigits: 11
Strict: true
2021-11-16 12:07:50 +00:00
Style/OpenStructUse:
2023-02-27 08:51:21 -08:00
Exclude:
- "Taps/**/*"
2021-11-16 12:07:50 +00:00
2024-08-19 09:56:50 -07:00
Style/OptionalBooleanParameter:
AllowedMethods:
# These are overrides of core library methods
2024-08-19 09:56:50 -07:00
# see https://ruby-doc.org/3.3.4/Object.html#method-i-respond_to-3F
- respond_to?
- respond_to_missing?
2024-08-19 09:56:50 -07:00
# Broken in RuboCop 1.68.0 so tries to fix line continuations in inline patch blocks:
# https://github.com/Homebrew/brew/actions/runs/11653110391/job/32460881827?pr=18682
Style/RedundantLineContinuation:
Enabled: false
# Rescuing `StandardError` is an understood default.
Style/RescueStandardError:
EnforcedStyle: implicit
# Returning `nil` is unnecessary.
Style/ReturnNil:
Enabled: true
# We have no use for using `warn` because we
# are calling Ruby with warnings disabled.
Style/StderrPuts:
Enabled: false
2020-08-19 17:12:32 +01:00
# so many of these in formulae and can't be autocorrected
Style/StringConcatenation:
Exclude:
- "Taps/*/*/*.rb"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
2020-08-19 17:12:32 +01:00
2016-09-25 02:41:14 +02:00
# ruby style guide favorite
Style/StringLiterals:
EnforcedStyle: double_quotes
2016-09-18 14:27:09 +01:00
2016-09-25 02:41:14 +02:00
# consistency with above
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
# Use consistent method names.
Style/StringMethods:
Enabled: true
# Treating this the same as Style/MethodCallWithArgsParentheses
2023-12-14 15:34:15 +00:00
Style/SuperWithArgsParentheses:
Enabled: false
# An array of symbols is more readable than a symbol array
# and also allows for easier grepping.
Style/SymbolArray:
EnforcedStyle: brackets
# make things a bit easier to read
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex
2024-01-26 11:36:08 -08:00
Style/TopLevelMethodDefinition:
Enabled: true
2024-01-26 12:03:03 -08:00
Exclude:
- "Taps/**/*"
2024-01-26 11:36:08 -08:00
# Trailing commas make diffs nicer.
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
# `unless ... ||` and `unless ... &&` are hard to mentally parse
Style/UnlessLogicalOperators:
Enabled: true
EnforcedStyle: forbid_logical_operators
# a bit confusing to non-Rubyists but useful for longer arrays
2016-09-25 02:41:14 +02:00
Style/WordArray:
MinSize: 4