Merge pull request #5316 from reitermarkus/rubocop

Deduplicate RuboCop config.
This commit is contained in:
Markus Reiter 2018-11-23 00:20:19 +01:00 committed by GitHub
commit 158a34bdad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 202 deletions

View File

@ -32,21 +32,11 @@ Layout/CaseIndentation:
# this is a bit less "floaty"
Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line
Exclude:
- '**/Casks/**/*'
# enforce use of <<~EOS
Layout/IndentHeredoc:
EnforcedStyle: squiggly
# conflicts with DSL-style path concatenation with `/`
Layout/SpaceAroundOperators:
Enabled: false
# use spaces for indentation; detect tabs
Layout/Tab:
Enabled: true
# Auto-correct is broken (https://github.com/rubocop-hq/rubocop/issues/6300).
Layout/EmptyLineAfterGuardClause:
Enabled: false
@ -81,8 +71,6 @@ Lint/ParenthesesAsGroupedExpression:
# most metrics don't make sense to apply for formulae/taps
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
@ -94,52 +82,11 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Enabled: false
# keyword arguments don't have the same readability problems
Metrics/ParameterLists:
CountKeywordArgs: false
# GitHub diff UI wraps beyond 118 characters (so that's the goal)
Metrics/LineLength:
Max: 170
# ignore manpage comments and long single-line strings
IgnoredPatterns: ['#: ', ' url "', ' mirror "', ' plist_options :']
Exclude:
- '**/Casks/**/*'
# dashes in filenames are typical
Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
Exclude:
- '**/Casks/**/*'
# implicitly allow EOS as we use it everywhere
Naming/HeredocDelimiterNaming:
Blacklist:
- END, EOD, EOF
# we have too many variables like sha256 where this harms readability
Naming/VariableNumber:
Enabled: false
# makes code less readable for minor performance increases
Performance/Caller:
Enabled: false
# we're doing this already so why not
Performance/CaseWhenSplat:
Enabled: true
# enable to avoid leaking resources
Style/AutoResourceCleanup:
Enabled: true
# this is a little more obvious what's going on
Style/BarePercentLiterals:
EnforcedStyle: percent_q
# consistency helps readability and helps people who don't know Ruby
Style/CollectionMethods:
Enabled: true
# our current conditional style is established
# TODO: enable this when possible
@ -150,14 +97,6 @@ Style/ConditionalAssignment:
Style/Documentation:
Enabled: false
# we don't need UTF-8 encoding comments
Style/Encoding:
Enabled: true
# falsely flags e.g. curl formatting arguments as format strings
Style/FormatStringToken:
EnforcedStyle: template
# we want to add this slowly and manually
# TODO: add to more files
Style/FrozenStringLiteralComment:
@ -170,106 +109,23 @@ Style/GuardClause:
# depends_on a: :b looks weird in formulae.
Style/HashSyntax:
EnforcedStyle: hash_rockets
Exclude:
- '**/bin/**/*'
- '**/cmd/**/*'
- '**/lib/**/*'
- '**/spec/**/*'
- '**/Casks/**/*'
# this doesn't make sense for wide lines below maximum line length
# https://github.com/rubocop-hq/rubocop/issues/6149
Style/IfUnlessModifier:
Enabled: false
# only for numbers >= 1_000_000
Style/NumericLiterals:
MinDigits: 7
# zero-prefixed octal literals are just too widely used (and understood)
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only
# rescuing StandardError is an understood default
Style/RescueStandardError:
EnforcedStyle: implicit
# return nil is unnecessary and a common mistake believing it's required
Style/ReturnNil:
Enabled: true
# We have no use for using `warn` because we are
# calling Ruby with warnings disabled ourselves (for now).
Style/StderrPuts:
Enabled: false
# ruby style guide favorite
Style/StringLiterals:
EnforcedStyle: double_quotes
Exclude:
- '**/Casks/**/*'
# consistency with above
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Exclude:
- '**/Casks/**/*'
# consistency helps readability and helps people who don't know Ruby
Style/StringMethods:
Enabled: true
# less confusing to non-Rubyists
Style/SymbolArray:
EnforcedStyle: brackets
# make things a bit easier to read
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex
Exclude:
- '**/Casks/**/*'
# messes with existing plist/caveats style
Style/TrailingBodyOnMethodDefinition:
Enabled: false
# all trailing commas make diffs nicer
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
# a bit confusing to non-Rubyists but useful for longer arrays
Style/WordArray:
MinSize: 4
Exclude:
- '**/Casks/**/*'
# exclude some styles for casks (for now)
# TODO: make Homebrew/brew, casks and formulae more consistent
Layout/ElseAlignment:
Exclude:
- '**/Casks/**/*'
Layout/IndentArray:
Exclude:
- '**/Casks/**/*'
Layout/IndentHash:
Exclude:
- '**/Casks/**/*'
Layout/IndentationWidth:
Exclude:
- '**/Casks/**/*'
Performance/StringReplacement:
Exclude:
- '**/Casks/**/*'
Style/EmptyElse:
Exclude:
- '**/Casks/**/*'
Style/PercentLiteralDelimiters:
Exclude:
- '**/Casks/**/*'
Style/RegexpLiteral:
Exclude:
- '**/Casks/**/*'

View File

@ -1,7 +1,5 @@
inherit_from: ./.rubocop_shared.yml
# Cask Cops
Cask/HomepageMatchesUrl:
Description: 'Ensure that the homepage and url match, otherwise add a comment. More info at https://github.com/Homebrew/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#when-url-and-homepage-hostnames-differ-add-a-comment'
Enabled: true
@ -22,8 +20,6 @@ Cask/StanzaOrder:
Description: 'Ensure that cask stanzas are sorted correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/master/CONTRIBUTING.md#stanza-order'
Enabled: true
# Built-In Cops
Layout/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
@ -34,63 +30,34 @@ Layout/IndentArray:
Layout/IndentHash:
EnforcedStyle: align_braces
Metrics/BlockLength:
Enabled: false
# Casks often contain long URLs and file paths.
Metrics/LineLength:
Enabled: false
Naming/FileName:
Enabled: false
Naming/HeredocDelimiterNaming:
Blacklist:
- END, EOD, EOF
Performance/StringReplacement:
Enabled: false
Style/BarePercentLiterals:
EnforcedStyle: percent_q
# Casks don't need documentation.
Style/Documentation:
Enabled: false
Style/EmptyElse:
Enabled: false
# These would only be distracting in casks.
Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: never
# Don't use hash rockets.
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
Style/IfUnlessModifier:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%': '{}'
'%i': '{}'
'%q': '{}'
'%Q': '{}'
'%r': '{}'
'%s': '()'
'%w': '[]'
'%W': '[]'
'%x': '()'
# This is more readable when the regex contains slashes.
Style/RegexpLiteral:
EnforcedStyle: percent_r
Style/SymbolArray:
EnforcedStyle: brackets
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
# 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

View File

@ -1,7 +1,102 @@
AllCops:
TargetRubyVersion: 2.3
Exclude:
- '**/vendor/**/*'
DisplayCopNames: false
# TODO: Try getting more rules in sync.
require: ./Homebrew/rubocops.rb
AllCops:
TargetRubyVersion: 2.3
DisplayCopNames: false
# Use `<<~` for heredocs.
Layout/IndentHeredoc:
EnforcedStyle: squiggly
# 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:
Blacklist:
- 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 simple tokens without type annotations.
Style/FormatStringToken:
EnforcedStyle: template
# This often leads to lines longer than the maximum line length.
# https://github.com/rubocop-hq/rubocop/issues/6149
Style/IfUnlessModifier:
Enabled: false
# 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

View File

@ -427,7 +427,7 @@ class ReporterHub
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
end
delegate :empty? => :@hash
delegate empty?: :@hash
def dump
# Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)

View File

@ -5,10 +5,10 @@ require "test/support/helper/cask/install_helper"
require "test/support/helper/cask/never_sudo_system_command"
HOMEBREW_CASK_DIRS = {
:appdir => Pathname.new(TEST_TMPDIR).join("cask-appdir"),
:prefpanedir => Pathname.new(TEST_TMPDIR).join("cask-prefpanedir"),
:qlplugindir => Pathname.new(TEST_TMPDIR).join("cask-qlplugindir"),
:servicedir => Pathname.new(TEST_TMPDIR).join("cask-servicedir"),
appdir: Pathname.new(TEST_TMPDIR).join("cask-appdir"),
prefpanedir: Pathname.new(TEST_TMPDIR).join("cask-prefpanedir"),
qlplugindir: Pathname.new(TEST_TMPDIR).join("cask-qlplugindir"),
servicedir: Pathname.new(TEST_TMPDIR).join("cask-servicedir"),
}.freeze
RSpec.shared_context "Homebrew Cask", :needs_macos do