Add and enable rubocop-rails.

This will help us catch and cleanup usage of e.g. `.blank?` and other
helpers we use from ActiveSupport.
This commit is contained in:
Mike McQuaid 2020-11-30 14:42:49 +00:00
parent cf70a511bb
commit 8528eff604
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
5 changed files with 151 additions and 107 deletions

1
.gitignore vendored
View File

@ -35,6 +35,7 @@
# Unignore vendored gems # Unignore vendored gems
!**/vendor/bundle/ruby/*/gems/*/lib !**/vendor/bundle/ruby/*/gems/*/lib
!**/vendor/bundle/ruby/*/gems/rubocop-performance-*/config !**/vendor/bundle/ruby/*/gems/rubocop-performance-*/config
!**/vendor/bundle/ruby/*/gems/rubocop-rails-*/config
!**/vendor/bundle/ruby/*/gems/rubocop-rspec-*/config !**/vendor/bundle/ruby/*/gems/rubocop-rspec-*/config
!**/vendor/bundle/ruby/*/gems/rubocop-sorbet-*/config !**/vendor/bundle/ruby/*/gems/rubocop-sorbet-*/config

View File

@ -13,33 +13,34 @@ AllCops:
# enable all pending rubocops # enable all pending rubocops
NewCops: enable NewCops: enable
Include: Include:
- '**/*.rbi' - "**/*.rbi"
Exclude: Exclude:
- 'Homebrew/sorbet/rbi/gems/**/*.rbi' - "Homebrew/sorbet/rbi/gems/**/*.rbi"
- 'Homebrew/sorbet/rbi/hidden-definitions/**/*.rbi' - "Homebrew/sorbet/rbi/hidden-definitions/**/*.rbi"
- 'Homebrew/sorbet/rbi/todo.rbi' - "Homebrew/sorbet/rbi/todo.rbi"
- 'Homebrew/sorbet/rbi/upstream.rbi' - "Homebrew/sorbet/rbi/upstream.rbi"
- 'Homebrew/bin/*' - "Homebrew/bin/*"
- 'Homebrew/vendor/**/*' - "Homebrew/vendor/**/*"
- "Taps/*/*/vendor/**/*"
Cask/Desc: Cask/Desc:
Description: 'Ensure that the desc stanza conforms to various content and style checks.' Description: "Ensure that the desc stanza conforms to various content and style checks."
Enabled: true Enabled: true
Cask/HomepageUrlTrailingSlash: Cask/HomepageUrlTrailingSlash:
Description: 'Ensure that the homepage url has a slash after the domain name.' Description: "Ensure that the homepage url has a slash after the domain name."
Enabled: true Enabled: true
Cask/NoDslVersion: Cask/NoDslVersion:
Description: 'Do not use the deprecated DSL version syntax in your cask header.' Description: "Do not use the deprecated DSL version syntax in your cask header."
Enabled: true Enabled: true
Cask/StanzaGrouping: Cask/StanzaGrouping:
Description: 'Ensure that cask stanzas are grouped correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/readme.md#stanza-order' Description: "Ensure that cask stanzas are grouped correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/readme.md#stanza-order"
Enabled: true Enabled: true
Cask/StanzaOrder: Cask/StanzaOrder:
Description: 'Ensure that cask stanzas are sorted correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/readme.md#stanza-order' Description: "Ensure that cask stanzas are sorted correctly. More info at https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/readme.md#stanza-order"
Enabled: true Enabled: true
# enable all formulae audits # enable all formulae audits
@ -105,9 +106,9 @@ Style/HashTransformValues:
# Allow for license expressions # Allow for license expressions
Style/HashAsLastArrayItem: Style/HashAsLastArrayItem:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/Formula/*.rb' - "/**/Formula/*.rb"
- '**/Formula/*.rb' - "**/Formula/*.rb"
# Enabled now LineLength is lowish. # Enabled now LineLength is lowish.
Style/IfUnlessModifier: Style/IfUnlessModifier:
@ -118,7 +119,7 @@ Style/NumericLiterals:
MinDigits: 7 MinDigits: 7
Strict: true Strict: true
Exclude: Exclude:
- '**/Brewfile' - "**/Brewfile"
# Zero-prefixed octal literals are widely used and understood. # Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix: Style/NumericLiteralPrefix:
@ -166,13 +167,30 @@ Performance/Caller:
Performance/MethodObjectAsBlock: Performance/MethodObjectAsBlock:
Enabled: false Enabled: false
# Cannot use ActiveSupport in RuboCops.
Rails:
Exclude:
- "Homebrew/rubocops/**/*"
# Skip these as they only apply to actual Rails and not our ActiveSupport usage.
Rails/Date:
Enabled: false
Rails/Delegate:
Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Rails/Pluck:
Enabled: false
Rails/TimeZone:
Enabled: false
# Don't allow cops to be disabled in casks and formulae. # Don't allow cops to be disabled in casks and formulae.
Style/DisableCopsWithinSourceCodeDirective: Style/DisableCopsWithinSourceCodeDirective:
Enabled: true Enabled: true
Include: Include:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
# make our hashes consistent # make our hashes consistent
Layout/HashAlignment: Layout/HashAlignment:
@ -182,9 +200,9 @@ Layout/HashAlignment:
# `system` is a special case and aligns on second argument, so allow this for formulae. # `system` is a special case and aligns on second argument, so allow this for formulae.
Layout/ArgumentAlignment: Layout/ArgumentAlignment:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/Formula/*.rb' - "/**/Formula/*.rb"
- '**/Formula/*.rb' - "**/Formula/*.rb"
# this is a bit less "floaty" # this is a bit less "floaty"
Layout/CaseIndentation: Layout/CaseIndentation:
@ -208,120 +226,137 @@ Lint/AmbiguousBlockAssociation:
Lint/DuplicateBranch: Lint/DuplicateBranch:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
# needed for lazy_object magic # needed for lazy_object magic
Naming/MemoizedInstanceVariableName: Naming/MemoizedInstanceVariableName:
Exclude: Exclude:
- 'Homebrew/lazy_object.rb' - "Homebrew/lazy_object.rb"
# so many of these in formulae and can't be autocorrected # so many of these in formulae and can't be autocorrected
# TODO: fix these as `ruby -w` complains about them. # TODO: fix these as `ruby -w` complains about them.
Lint/AmbiguousRegexpLiteral: Lint/AmbiguousRegexpLiteral:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/Formula/*.rb' - "/**/Formula/*.rb"
- '**/Formula/*.rb' - "**/Formula/*.rb"
# useful for metaprogramming in RSpec # useful for metaprogramming in RSpec
Lint/ConstantDefinitionInBlock: Lint/ConstantDefinitionInBlock:
Exclude: Exclude:
- '**/*_spec.rb' - "**/*_spec.rb"
# so many of these in formulae and can't be autocorrected # so many of these in formulae and can't be autocorrected
Lint/ParenthesesAsGroupedExpression: Lint/ParenthesesAsGroupedExpression:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/Formula/*.rb' - "/**/Formula/*.rb"
- '**/Formula/*.rb' - "**/Formula/*.rb"
# Most metrics don't make sense to apply for casks/formulae/taps. # Most metrics don't make sense to apply for casks/formulae/taps.
Metrics/AbcSize: Metrics/AbcSize:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/BlockLength: Metrics/BlockLength:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/ClassLength: Metrics/ClassLength:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/MethodLength: Metrics/MethodLength:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/ModuleLength: Metrics/ModuleLength:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
# allow those that are standard # allow those that are standard
# TODO: try to remove some of these # TODO: try to remove some of these
Naming/MethodParameterName: Naming/MethodParameterName:
AllowedNames: AllowedNames:
- '_' - "_"
- 'a' - "a"
- 'b' - "b"
- 'cc' - "cc"
- 'c1' - "c1"
- 'c2' - "c2"
- 'd' - "d"
- 'e' - "e"
- 'f' - "f"
- 'ff' - "ff"
- 'fn' - "fn"
- 'id' - "id"
- 'io' - "io"
- 'o' - "o"
- 'p' - "p"
- 'pr' - "pr"
- 'r' - "r"
- 'rb' - "rb"
- 's' - "s"
- 'to' - "to"
- 'v' - "v"
# GitHub diff UI wraps beyond 118 characters # GitHub diff UI wraps beyond 118 characters
Layout/LineLength: Layout/LineLength:
Max: 118 Max: 118
# ignore manpage comments and long single-line strings # ignore manpage comments and long single-line strings
IgnoredPatterns: ['#: ', ' url "', ' mirror "', ' plist_options ', IgnoredPatterns:
' appcast "', ' executable: "', ' font "', ' homepage "', ' name "', [
' pkg "', ' pkgutil: "', '#{language}', '#{version.', "#: ",
' "/Library/Application Support/', '"/Library/Caches/', '"/Library/PreferencePanes/', ' url "',
' "~/Library/Application Support/', '"~/Library/Caches/', '"~/Application Support', ' mirror "',
' was verified as official when first introduced to the cask'] " plist_options ",
' appcast "',
' executable: "',
' font "',
' homepage "',
' name "',
' pkg "',
' pkgutil: "',
"#{language}",
"#{version.",
' "/Library/Application Support/',
'"/Library/Caches/',
'"/Library/PreferencePanes/',
' "~/Library/Application Support/',
'"~/Library/Caches/',
'"~/Application Support',
" was verified as official when first introduced to the cask",
]
Sorbet/FalseSigil: Sorbet/FalseSigil:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
- 'Homebrew/test/**/Casks/**/*.rb' - "Homebrew/test/**/Casks/**/*.rb"
Sorbet/StrictSigil: Sorbet/StrictSigil:
Enabled: true Enabled: true
Include: Include:
- '**/*.rbi' - "**/*.rbi"
# Try getting rid of these. # Try getting rid of these.
Sorbet/ConstantsFromStrings: Sorbet/ConstantsFromStrings:
@ -339,48 +374,48 @@ Style/AccessorGrouping:
# make rspec formatting more flexible # make rspec formatting more flexible
Style/BlockDelimiters: Style/BlockDelimiters:
Exclude: Exclude:
- 'Homebrew/**/*_spec.rb' - "Homebrew/**/*_spec.rb"
- 'Homebrew/**/shared_examples/**/*.rb' - "Homebrew/**/shared_examples/**/*.rb"
# TODO: remove this when possible. # TODO: remove this when possible.
Style/ClassVars: Style/ClassVars:
Exclude: Exclude:
- '**/developer/bin/*' - "**/developer/bin/*"
# Don't enforce documentation in casks or formulae. # Don't enforce documentation in casks or formulae.
Style/Documentation: Style/Documentation:
Exclude: Exclude:
- 'Taps/**/*' - "Taps/**/*"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
- '**/*.rbi' - "**/*.rbi"
Style/DocumentationMethod: Style/DocumentationMethod:
Include: Include:
- 'Homebrew/formula.rb' - "Homebrew/formula.rb"
# Not used for casks and formulae. # Not used for casks and formulae.
Style/FrozenStringLiteralComment: Style/FrozenStringLiteralComment:
EnforcedStyle: always EnforcedStyle: always
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
- 'Homebrew/test/**/Casks/**/*.rb' - "Homebrew/test/**/Casks/**/*.rb"
- '**/*.rbi' - "**/*.rbi"
- '**/Brewfile' - "**/Brewfile"
# TODO: remove this when possible. # TODO: remove this when possible.
Style/GlobalVars: Style/GlobalVars:
Exclude: Exclude:
- '**/developer/bin/*' - "**/developer/bin/*"
# potential for errors in formulae too high with this # potential for errors in formulae too high with this
Style/GuardClause: Style/GuardClause:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
# avoid hash rockets where possible # avoid hash rockets where possible
Style/HashSyntax: Style/HashSyntax:
@ -389,9 +424,9 @@ Style/HashSyntax:
# so many of these in formulae and can't be autocorrected # so many of these in formulae and can't be autocorrected
Style/StringConcatenation: Style/StringConcatenation:
Exclude: Exclude:
- 'Taps/*/*/*.rb' - "Taps/*/*/*.rb"
- '/**/{Formula,Casks}/*.rb' - "/**/{Formula,Casks}/*.rb"
- '**/{Formula,Casks}/*.rb' - "**/{Formula,Casks}/*.rb"
# ruby style guide favorite # ruby style guide favorite
Style/StringLiterals: Style/StringLiterals:

View File

@ -25,6 +25,7 @@ gem "mechanize"
gem "patchelf" gem "patchelf"
gem "plist" gem "plist"
gem "rubocop-performance" gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rspec" gem "rubocop-rspec"
gem "rubocop-sorbet" gem "rubocop-sorbet"
gem "ruby-macho" gem "ruby-macho"

View File

@ -70,6 +70,7 @@ GEM
pry (0.13.1) pry (0.13.1)
coderay (~> 1.1) coderay (~> 1.1)
method_source (~> 1.0) method_source (~> 1.0)
rack (2.2.3)
rainbow (3.0.0) rainbow (3.0.0)
rdiscount (2.2.0.2) rdiscount (2.2.0.2)
regexp_parser (2.0.0) regexp_parser (2.0.0)
@ -115,6 +116,10 @@ GEM
rubocop-performance (1.9.1) rubocop-performance (1.9.1)
rubocop (>= 0.90.0, < 2.0) rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0) rubocop-ast (>= 0.4.0)
rubocop-rails (2.8.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.87.0)
rubocop-rspec (2.0.0) rubocop-rspec (2.0.0)
rubocop (~> 1.0) rubocop (~> 1.0)
rubocop-ast (>= 1.1.0) rubocop-ast (>= 1.1.0)
@ -176,6 +181,7 @@ DEPENDENCIES
rspec-wait rspec-wait
rubocop rubocop
rubocop-performance rubocop-performance
rubocop-rails
rubocop-rspec rubocop-rspec
rubocop-sorbet rubocop-sorbet
ruby-macho ruby-macho

View File

@ -6,6 +6,7 @@ require_relative "load_path"
require "utils/sorbet" require "utils/sorbet"
require "rubocop-performance" require "rubocop-performance"
require "rubocop-rails"
require "rubocop-rspec" require "rubocop-rspec"
require "rubocop-sorbet" require "rubocop-sorbet"