Skip to content
Snippets Groups Projects
Unverified Commit 25db60eb authored by Mike McQuaid's avatar Mike McQuaid
Browse files

Unify (mostly) Homebrew code style

Make the Homebrew/cask and Homebrew/homebrew-core style more closely
match the rest of Homebrew.

To accomplish this:
- Run `brew cask style` to ensure we don't break style there when
  making changes or upgrading RuboCop in Homebrew/brew.
- Fix the HomepageMatchesUrl cop to better handle weird input.
- Remove the now unneeded `.rubocop_shared.yml`
- Fix the cask fixtures with `brew cask style --fix`.
- Share more style between Homebrew/brew, casks and formulae.
parent 21003354
No related branches found
No related tags found
No related merge requests found
Showing
with 220 additions and 268 deletions
......@@ -103,6 +103,9 @@ jobs:
if [ "$RUNNER_OS" = "macOS" ]; then
brew tap homebrew/cask
brew update-reset Library/Taps/homebrew/homebrew-cask
# don't care about `brew cask style` here.
brew untap adoptopenjdk/openjdk
else
# Fix permissions for 'brew tests'
sudo chmod -R g-w,o-w /home/linuxbrew /home/runner /opt
......@@ -159,6 +162,10 @@ jobs:
- name: Run brew style on official taps
run: brew style --display-cop-names homebrew/bundle homebrew/services homebrew/test-bot
- name: Run brew cask style
if: matrix.os == 'macOS-latest'
run: brew cask style
- name: Run vale for docs linting
run: |
brew install vale
......
inherit_from: ./.rubocop_shared.yml
# TODO: Try getting more rules in sync.
require: ./Homebrew/rubocops.rb
AllCops:
TargetRubyVersion: 2.6
DisplayCopNames: false
# enable all pending rubocops
NewCops: enable
# enable all formulae audits
FormulaAudit:
......@@ -8,9 +16,108 @@ FormulaAudit:
FormulaAuditStrict:
Enabled: true
# enable all pending rubocops
AllCops:
NewCops: enable
# Use `<<~` for heredocs.
Layout/HeredocIndentation:
Enabled: true
# Not useful in casks and formulae.
Metrics/BlockLength:
Enabled: false
# Keyword arguments don't have the same readability
# problems as normal parameters.
Metrics/ParameterLists:
CountKeywordArgs: false
# Implicitly allow EOS as we use it everywhere.
Naming/HeredocDelimiterNaming:
ForbiddenDelimiters:
- END, EOD, EOF
# Allow dashes in filenames.
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# Both styles are used depending on context,
# e.g. `sha256` and `something_countable_1`.
Naming/VariableNumber:
Enabled: false
# Avoid leaking resources.
Style/AutoResourceCleanup:
Enabled: true
# This makes these a little more obvious.
Style/BarePercentLiterals:
EnforcedStyle: percent_q
# Use consistent style for better readability.
Style/CollectionMethods:
Enabled: true
# Prefer tokens with type annotations for consistency
# between formatting numbers and strings.
Style/FormatStringToken:
EnforcedStyle: annotated
# autocorrectable and more readable
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
# Enabled now LineLength is lowish.
Style/IfUnlessModifier:
Enabled: true
# Only use this for numbers >= `1_000_000`.
Style/NumericLiterals:
MinDigits: 7
Strict: true
# Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# 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
# Use consistent method names.
Style/StringMethods:
Enabled: true
# An array of symbols is more readable than a symbol array
# and also allows for easier grepping.
Style/SymbolArray:
EnforcedStyle: brackets
# Trailing commas make diffs nicer.
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
# Does not hinder readability, so might as well enable it.
Performance/CaseWhenSplat:
Enabled: true
# Makes code less readable for minor performance increases.
Performance/Caller:
Enabled: false
# don't allow cops to be disabled in formulae
Style/DisableCopsWithinSourceCodeDirective:
......@@ -54,6 +161,7 @@ Lint/AmbiguousRegexpLiteral:
Lint/ParenthesesAsGroupedExpression:
Enabled: false
# most metrics don't make sense to apply for formulae/taps
Metrics/AbcSize:
Enabled: false
......@@ -72,7 +180,15 @@ Metrics/PerceivedComplexity:
Layout/LineLength:
Max: 118
# ignore manpage comments and long single-line strings
IgnoredPatterns: ['#: ', ' url "', ' mirror "', ' plist_options :']
IgnoredPatterns: ['#: ', ' url "', ' mirror "', ' plist_options ',
' appcast "', ' executable: "', '#{version.',
' "~/Library/Application Support/', '"~/Library/Caches/', '"~/Application Support',
' was verified as official when first introduced to the cask']
# TODO: remove this when possible.
Style/ClassVars:
Exclude:
- '**/developer/bin/*'
# most of our APIs are internal so don't require docs
Style/Documentation:
......@@ -82,26 +198,18 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false
# TODO: remove this when possible.
Style/GlobalVars:
Exclude:
- '**/developer/bin/*'
# potential for errors in formulae too high with this
Style/GuardClause:
Enabled: false
# depends_on a: :b looks weird in formulae.
# avoid hash rockets where possible
Style/HashSyntax:
EnforcedStyle: hash_rockets
Exclude:
- '**/Guardfile'
- '**/cmd/**/*.rb'
- '**/lib/**/*.rb'
- '**/spec/**/*.rb'
# autocorrectable and more readable
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
EnforcedStyle: ruby19
# ruby style guide favorite
Style/StringLiterals:
......@@ -118,3 +226,11 @@ Style/TernaryParentheses:
# a bit confusing to non-Rubyists but useful for longer arrays
Style/WordArray:
MinSize: 4
# would rather freeze too much than too little
Style/MutableConstant:
EnforcedStyle: strict
# unused keyword arguments improve APIs
Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true
inherit_from: ./.rubocop_shared.yml
inherit_from: ./Homebrew/.rubocop.yml
Cask/HomepageMatchesUrl:
Description: 'Ensure that the homepage and url match, otherwise add a comment. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/stanzas/url.md#when-url-and-homepage-hostnames-differ-add-a-comment'
Enabled: true
Exclude:
- '**/test/support/fixtures/cask/Casks/**/*.rb'
Cask/HomepageUrlTrailingSlash:
Description: 'Ensure that the homepage url has a slash after the domain name.'
......@@ -22,44 +20,6 @@ Cask/StanzaOrder:
Description: 'Ensure that cask stanzas are sorted correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/CONTRIBUTING.md#stanza-order'
Enabled: true
Layout/HashAlignment:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
Layout/FirstArrayElementIndentation:
EnforcedStyle: align_brackets
Layout/FirstHashElementIndentation:
EnforcedStyle: align_braces
# Casks often contain long URLs and file paths.
Layout/LineLength:
Enabled: false
# Casks don't need documentation.
Style/Documentation:
Enabled: false
# These would only be distracting in casks.
# don't want this for casks but re-enabled for Library/Homebrew
Style/FrozenStringLiteralComment:
EnforcedStyle: never
# Don't use hash rockets.
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
# This is more readable when the regex contains slashes.
Style/RegexpLiteral:
EnforcedStyle: percent_r
# Use consistent style for all arrays.
Style/WordArray:
EnforcedStyle: brackets
# This makes multi-line arrays more readable and alignable.
Layout/FirstArrayElementLineBreak:
Enabled: true
# This makes multi-line hashes more readable and alignable.
Layout/FirstHashElementLineBreak:
Enabled: true
Enabled: false
# TODO: Try getting more rules in sync.
require: ./Homebrew/rubocops.rb
AllCops:
TargetRubyVersion: 2.6
DisplayCopNames: false
# Use `<<~` for heredocs.
Layout/HeredocIndentation:
Enabled: true
# Not useful in casks and formulae.
Metrics/BlockLength:
Enabled: false
# Keyword arguments don't have the same readability
# problems as normal parameters.
Metrics/ParameterLists:
CountKeywordArgs: false
# Implicitly allow EOS as we use it everywhere.
Naming/HeredocDelimiterNaming:
ForbiddenDelimiters:
- END, EOD, EOF
# Allow dashes in filenames.
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# Both styles are used depending on context,
# e.g. `sha256` and `something_countable_1`.
Naming/VariableNumber:
Enabled: false
# Avoid leaking resources.
Style/AutoResourceCleanup:
Enabled: true
# This makes these a little more obvious.
Style/BarePercentLiterals:
EnforcedStyle: percent_q
# Use consistent style for better readability.
Style/CollectionMethods:
Enabled: true
# Prefer tokens with type annotations for consistency
# between formatting numbers and strings.
Style/FormatStringToken:
EnforcedStyle: annotated
# autocorrectable and more readable
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
# Enabled now LineLength is lowish.
Style/IfUnlessModifier:
Enabled: true
# Only use this for numbers >= `1_000_000`.
Style/NumericLiterals:
MinDigits: 7
Strict: true
# Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# 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
# Use consistent method names.
Style/StringMethods:
Enabled: true
# An array of symbols is more readable than a symbol array
# and also allows for easier grepping.
Style/SymbolArray:
EnforcedStyle: brackets
# Trailing commas make diffs nicer.
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
# Does not hinder readability, so might as well enable it.
Performance/CaseWhenSplat:
Enabled: true
# Makes code less readable for minor performance increases.
Performance/Caller:
Enabled: false
......@@ -6,7 +6,6 @@ AllCops:
- 'Library/Homebrew/.simplecov'
Exclude:
- 'bin/*'
- '**/Casks/**/*'
- '**/vendor/**/*'
# messes up system formatting for formulae but good for Homebrew/brew
......@@ -35,10 +34,6 @@ Lint/NestedMethodDefinition:
Lint/ParenthesesAsGroupedExpression:
Enabled: true
# unused keyword arguments improve APIs
Lint/UnusedMethodArgument:
AllowUnusedKeywordArguments: true
# TODO: try to bring down all metrics maximums
Metrics/AbcSize:
Enabled: true
......@@ -113,10 +108,7 @@ Style/BlockDelimiters:
# don't group nicely documented or private attr_readers
Style/AccessorGrouping:
Enabled: true
Exclude:
- 'cask/cmd/internal_stanza.rb'
- 'cask/download.rb'
- 'formula.rb'
- 'formulary.rb'
- 'migrator.rb'
......@@ -124,11 +116,6 @@ Style/AccessorGrouping:
- 'system_command.rb'
- 'tap.rb'
# https://github.com/rubocop-hq/rubocop/issues/8257
Style/BisectedAttrAccessor:
Exclude:
- 'cask/url.rb'
# document our public APIs
Style/Documentation:
Enabled: true
......@@ -143,19 +130,9 @@ Style/DocumentationMethod:
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
Exclude:
- '**/Casks/**/*.rb'
# so many of these in formulae but none in here
Style/GuardClause:
Enabled: true
# hash-rockets preferred for formulae, a: 1 preferred here
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
# would rather freeze too much than too little
Style/MutableConstant:
EnforcedStyle: strict
# LineLength is low enough here to re-enable it.
Style/IfUnlessModifier:
Enabled: true
......@@ -32,12 +32,8 @@ module Cask
option "--yaml", :yaml, false
option "--inspect", :inspect, false
attr_accessor :format
attr_accessor :format, :stanza
private :format, :format=
attr_accessor :stanza
private :stanza, :stanza=
def initialize(*)
......
......@@ -9,7 +9,7 @@ module RuboCop
# or if it doesn't, checks if a comment in the form
# `# example.com was verified as official when first introduced to the cask`
# is present.
class HomepageMatchesUrl < Cop # rubocop:disable Metrics/ClassLength
class HomepageMatchesUrl < Cop
extend Forwardable
include CaskHelp
......@@ -134,7 +134,13 @@ module RuboCop
def url_match_homepage?(stanza)
host = extract_url(stanza).downcase
host_uri = URI(remove_non_ascii(host))
host_uri = begin
URI(remove_non_ascii(host))
rescue URI::InvalidURIError
# Can't check if we can't parse.
return true
end
host = if host.match?(/:\d/) && host_uri.port != 80
"#{host_uri.host}:#{host_uri.port}"
else
......
......@@ -10,14 +10,14 @@ describe Cask::Cmd::Cat, :cask do
describe "given a basic Cask" do
let(:basic_cask_content) {
<<~RUBY
cask 'basic-cask' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
cask "basic-cask" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url 'https://brew.sh/TestCask.dmg'
homepage 'https://brew.sh/'
url "https://brew.sh/TestCask.dmg"
homepage "https://brew.sh/"
app 'TestCask.app'
app "TestCask.app"
end
RUBY
}
......
......@@ -15,14 +15,16 @@ describe Cask::Cmd::Style, :cask do
around do |example|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_cask.yml", HOMEBREW_LIBRARY/".rubocop_cask.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_rspec.yml", HOMEBREW_LIBRARY/".rubocop_rspec.yml"
example.run
ensure
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_cask.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_rspec.yml"
end
before do
......
......@@ -6,13 +6,11 @@ describe Homebrew::Style do
around do |example|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop.yml"
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml"
example.run
ensure
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop.yml"
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml"
end
before do
......
cask 'adobe-air' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
cask "adobe-air" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url 'https://brew.sh/TestCask.dmg'
name 'Adobe Air'
homepage 'https://brew.sh/'
url "https://brew.sh/TestCask.dmg"
name "Adobe Air"
homepage "https://brew.sh/"
app 'TestCask.app'
app "TestCask.app"
end
cask 'adobe-illustrator' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
cask "adobe-illustrator" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url 'https://brew.sh/TestCask.dmg'
name 'Adobe Illustrator'
homepage 'https://brew.sh/'
url "https://brew.sh/TestCask.dmg"
name "Adobe Illustrator"
homepage "https://brew.sh/"
app 'TestCask.app'
app "TestCask.app"
end
cask 'appdir-interpolation' do
version '2.61'
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
cask "appdir-interpolation" do
version "2.61"
sha256 "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68"
url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://brew.sh/appdir-interpolation'
homepage "https://brew.sh/appdir-interpolation"
binary "#{appdir}/some/path"
end
cask 'auto-updates' do
version '2.61'
sha256 '5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d'
cask "auto-updates" do
version "2.61"
sha256 "5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d"
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
homepage 'https://brew.sh/MyFancyApp'
homepage "https://brew.sh/MyFancyApp"
auto_updates true
app 'MyFancyApp/MyFancyApp.app'
app "MyFancyApp/MyFancyApp.app"
end
cask 'bad-checksum' do
version '1.2.3'
sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb'
cask "bad-checksum" do
version "1.2.3"
sha256 "badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb"
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh/'
homepage "https://brew.sh/"
app 'Caffeine.app'
app "Caffeine.app"
end
cask 'bad-checksum2' do
version '1.2.3'
sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb'
cask "bad-checksum2" do
version "1.2.3"
sha256 "badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb"
url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.gz"
homepage 'https://brew.sh/container-tar-gz'
homepage "https://brew.sh/container-tar-gz"
app 'container'
app "container"
end
cask 'basic-cask' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
cask "basic-cask" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url 'https://brew.sh/TestCask.dmg'
homepage 'https://brew.sh/'
url "https://brew.sh/TestCask.dmg"
homepage "https://brew.sh/"
app 'TestCask.app'
app "TestCask.app"
end
cask 'booby-trap' do
version '0.0.7'
cask "booby-trap" do
version "0.0.7"
url do
# to be lazily evaluated
raise 'Boom'
raise "Boom"
end
end
cask 'with-depends-on-macos-string' do
version '1.2.3'
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
cask "with-depends-on-macos-string" do
version "1.2.3"
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh/with-depends-on-macos-string'
homepage "https://brew.sh/with-depends-on-macos-string"
depends_on macos: MacOS.version.to_s
app 'Caffeine.app'
app "Caffeine.app"
end
cask 'container-7z' do
version '1.2.3'
sha256 '3f9542ace85ed5f88549e2d0ea82210f8ddc87e0defbb78469d3aed719b3c964'
cask "container-7z" do
version "1.2.3"
sha256 "3f9542ace85ed5f88549e2d0ea82210f8ddc87e0defbb78469d3aed719b3c964"
url "file://#{TEST_FIXTURE_DIR}/cask/container.7z"
homepage 'https://brew.sh/container-7z'
homepage "https://brew.sh/container-7z"
depends_on formula: 'unar'
depends_on formula: "unar"
app 'container'
app "container"
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment