Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to rubocop 0.76 #163

Merged
merged 18 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ cache:
bundler: true
sudo: false
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
install:
- cd rubocop-airbnb
- bundle install
Expand Down
3 changes: 3 additions & 0 deletions rubocop-airbnb/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require:
- rubocop-performance
- rubocop-rails
inherit_from:
- .rubocop_airbnb.yml
- ./config/default.yml
Expand Down
8 changes: 8 additions & 0 deletions rubocop-airbnb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 3.0.0
* Update to rubocop 0.76
* Enable Rails/IgnoredSkipActionFilterOption
* Enable Rails/ReflectionClassName
* Disable and delete Airbnb/ClassName
* Enable Layout/IndentFirstParameter
* Drop support for Ruby 2.2

# 2.0.0
* Upgrade to rubocop-rspec 1.30.0, use ~> to allow for PATCH version flexibility
* Upgrade to rubocop 0.58.0, use ~> to allow for PATCH version flexibility
Expand Down
5 changes: 5 additions & 0 deletions rubocop-airbnb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Just put this in your `Gemfile` it depends on the appropriate version of rubocop
gem 'rubocop-airbnb'
```

Note: If you want to run with Ruby 2.2 you will need to set your version to 2
```
gem 'rubocop-airbnb', '~> 2'
```

## Usage

You need to tell RuboCop to load the Airbnb extension. There are three
Expand Down
5 changes: 0 additions & 5 deletions rubocop-airbnb/config/rubocop-airbnb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# They are custom built for use inside Airbnb and address issues that we have experienced in
# testing and production.

Airbnb/ClassName:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably delete class_name.rb and class_name_spec.rb now that we're using Rubocop's ReflectionClassName cop instead.

Description: Use :class_name => "Model" instead of :class_name => Model.name
to avoid a long cascade of autoloading.
Enabled: true

Airbnb/ClassOrModuleDeclaredInWrongFile:
Description: Declare a class or module in the file that matches its namespace and name.
Enabled: true
Expand Down
3 changes: 3 additions & 0 deletions rubocop-airbnb/config/rubocop-gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Gemspec/RequiredRubyVersion:
Enabled: false
Include:
- '**/*.gemspec'

Gemspec/RubyVersionGlobalsUsage:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is enabled by default -- is it worth explicitly enabling here or should we just use the rubocop default settings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's explicitly enable it here for clarity. I don't know where the Rubocop defaults are set but I see tons of enabled cops in our configs that are probably also enabled by default.

Enabled: true
16 changes: 6 additions & 10 deletions rubocop-airbnb/config/rubocop-layout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Layout/FirstMethodParameterLineBreak:
Enabled: false

# Supports --auto-correct
Layout/FirstParameterIndentation:
Layout/IndentFirstArgument:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new name is Layout/FirstArgumentIndentation.

Description: Checks the indentation of the first parameter in a method call.
Enabled: true
EnforcedStyle: consistent
Expand All @@ -238,7 +238,7 @@ Layout/FirstParameterIndentation:
- special_for_inner_method_call_in_parentheses

# Supports --auto-correct
Layout/IndentArray:
Layout/IndentFirstArrayElement:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new name is Layout/FirstArrayElementIndentation.

Description: Checks the indentation of the first element in an array literal.
Enabled: true
EnforcedStyle: consistent
Expand All @@ -248,10 +248,9 @@ Layout/IndentAssignment:
Description: Checks the indentation of the first line of the right-hand-side of a
multi-line assignment.
Enabled: true
IndentationWidth:

# Supports --auto-correct
Layout/IndentHash:
Layout/IndentFirstHashElement:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new name is Layout/FirstHashElementIndentation

Copy link
Collaborator Author

@zachsabin zachsabin Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these Indent -> Indentation name changes are in rubocop 0.77, which isn't released yet.

rubocop/rubocop#7468

Description: Checks the indentation of the first key in a hash literal.
Enabled: true
EnforcedStyle: consistent
Expand Down Expand Up @@ -344,7 +343,6 @@ Layout/MultilineMethodCallIndentation:
SupportedStyles:
- aligned
- indented
IndentationWidth:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IndentationWidth isn't supported anymore, although I can't find in the rubocop changelog where exactly that happened.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the cop is Layout/IndentationWidth. This line with bare IndentationWidth should probably never have been here, so you were right to remove it.


Layout/MultilineMethodDefinitionBraceLayout:
Description: >-
Expand Down Expand Up @@ -474,11 +472,6 @@ Layout/SpaceInsideBlockBraces:
EnforcedStyleForEmptyBraces: no_space
SpaceBeforeBlockParameters: true

Layout/SpaceInsideParens:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just duplicated elsewhere in the file! It still exists, but the newer rubocop doesn't allow duplicated styles it seems.

Description: 'No spaces after ( or before ).'
StyleGuide: '#spaces-braces'
Enabled: true

Layout/SpaceInsideArrayLiteralBrackets:
EnforcedStyle: no_space
SupportedStyles:
Expand Down Expand Up @@ -558,3 +551,6 @@ Layout/TrailingWhitespace:
Description: Avoid trailing whitespace.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-trailing-whitespace
Enabled: true

Layout/IndentFirstParameter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the documented name is Layout/FirstParameterIndentation. Let's use that name instead of the alias to make it easier to find documentation.

https://github.com/rubocop-hq/rubocop/blob/a29694f7821ef51ca58528ca703bce9ec713716b/lib/rubocop/config_obsoletion.rb#L17

Enabled: true
13 changes: 9 additions & 4 deletions rubocop-airbnb/config/rubocop-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ Lint/EnsureReturn:
Lint/ErbNewArguments:
Enabled: false

Lint/FlipFlop:
Description: Checks for flip flops
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops
Enabled: false

Lint/FloatOutOfRange:
Description: Catches floating-point literals too large or small for Ruby to represent.
Enabled: false
Expand Down Expand Up @@ -237,20 +242,20 @@ Lint/UnderscorePrefixedVariableName:
Lint/UnifiedInteger:
Enabled: false

Lint/UnneededCopDisableDirective:
Lint/RedundantCopDisableDirective:
Description: >-
Checks for rubocop:disable comments that can be removed.
Note: this cop is not disabled when disabling all cops. It must be explicitly disabled.
Enabled: true

Lint/UnneededCopEnableDirective:
Lint/RedundantCopEnableDirective:
Description: Checks for rubocop:enable comments that can be removed.
Enabled: true

Lint/UnneededRequireStatement:
Lint/RedundantRequireStatement:
Enabled: false

Lint/UnneededSplatExpansion:
Lint/RedundantSplatExpansion:
Enabled: false

Lint/UnreachableCode:
Expand Down
3 changes: 3 additions & 0 deletions rubocop-airbnb/config/rubocop-naming.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ Naming/VariableName:

Naming/VariableNumber:
Enabled: false

Naming/RescuedExceptionsVariableName:
Enabled: false
19 changes: 0 additions & 19 deletions rubocop-airbnb/config/rubocop-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ Performance/FlatMap:
Performance/InefficientHashSearch:
Enabled: false

# Supports --auto-correct
Performance/LstripRstrip:
Description: Use `strip` instead of `lstrip.rstrip`.
Enabled: false

# Supports --auto-correct
Performance/RangeInclude:
Description: Use `Range#cover?` instead of `Range#include?`.
Expand All @@ -85,11 +80,6 @@ Performance/RedundantMerge:
Reference: https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code
Enabled: false

# Supports --auto-correct
Performance/RedundantSortBy:
Description: Use `sort` instead of `sort_by { |x| x }`.
Enabled: false

Performance/RegexpMatch:
Enabled: false

Expand All @@ -99,12 +89,6 @@ Performance/ReverseEach:
Reference: https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code
Enabled: false

# Supports --auto-correct
Performance/Sample:
Description: Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`.
Reference: https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code
Enabled: false

# Supports --auto-correct
Performance/Size:
Description: Use `size` instead of `count` for counting the number of elements in
Expand Down Expand Up @@ -133,9 +117,6 @@ Performance/TimesMap:
Performance/UnfreezeString:
Enabled: false

Performance/UnneededSort:
Enabled: false

Performance/UriDefaultParser:
Enabled: false

6 changes: 6 additions & 0 deletions rubocop-airbnb/config/rubocop-rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,9 @@ Rails/Validation:
Enabled: false
Include:
- app/models/**/*.rb

Rails/IgnoredSkipActionFilterOption:
Enabled: true

Rails/ReflectionClassName:
Enabled: true
36 changes: 25 additions & 11 deletions rubocop-airbnb/config/rubocop-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ Style/ExpandPathArguments:
Description: "Use `expand_path(__dir__)` instead of `expand_path('..', __FILE__)`."
Enabled: false

Style/FlipFlop:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to rubocop-airbnb/config/rubocop-lint.yml

Description: Checks for flip flops
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops
Enabled: false

Style/For:
Description: Checks use of for or each in multiline loops.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-for-loops
Expand Down Expand Up @@ -360,10 +355,10 @@ Style/FrozenStringLiteralComment:
Description: Add the frozen_string_literal comment to the top of files to help transition
from Ruby 2.3.0 to Ruby 3.0.
Enabled: false
EnforcedStyle: when_needed
SupportedStyles:
- when_needed
- always
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this stay here, but with - never and - always as the choices?

- never
EnforcedStyle: always
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when_needed does not appear to be allowed anymore.

Error: invalid EnforcedStyle 'when_needed' for Style/FrozenStringLiteralComment found in config/rubocop-style.yml
Valid choices are: always, never


Style/GlobalVars:
Description: Do not introduce global variables.
Expand Down Expand Up @@ -735,6 +730,11 @@ Style/RedundantSelf:
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-self-unless-required
Enabled: true

# Supports --auto-correct
Style/RedundantSortBy:
Description: Use `sort` instead of `sort_by { |x| x }`.
Enabled: false

# Supports --auto-correct
Style/RegexpLiteral:
Description: Use / or %r around regular expressions.
Expand Down Expand Up @@ -763,6 +763,12 @@ Style/ReturnNil:
Style/SafeNavigation:
Enabled: false

# Supports --auto-correct
Style/Sample:
Description: Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`.
Reference: https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code
Enabled: false

# Supports --auto-correct
Style/SelfAssignment:
Description: Checks for places where self-assignment shorthand should have been used.
Expand Down Expand Up @@ -856,6 +862,11 @@ Style/StringMethods:
PreferredMethods:
intern: to_sym

# Supports --auto-correct
Style/Strip:
Description: Use `strip` instead of `lstrip.rstrip`.
Enabled: false

Style/StructInheritance:
Description: Checks for inheritance from Struct.new.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-extend-struct-new
Expand Down Expand Up @@ -922,24 +933,27 @@ Style/UnlessElse:
Enabled: true

# Supports --auto-correct
Style/UnneededCapitalW:
Style/RedundantCapitalW:
Description: Checks for %W when interpolation is not needed.
Enabled: false

Style/UnneededCondition:
Style/RedundantCondition:
Enabled: false

# Supports --auto-correct
Style/UnneededInterpolation:
Style/RedundantInterpolation:
Description: Checks for strings that are just an interpolated expression.
Enabled: false

# Supports --auto-correct
Style/UnneededPercentQ:
Style/RedundantPercentQ:
Description: Checks for %q/%Q when single quotes or double quotes would do.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-q
Enabled: false

Style/RedundantSort:
Enabled: false

Style/UnpackFirst:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion rubocop-airbnb/lib/rubocop/airbnb/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module RuboCop
module Airbnb
# Version information for the the Airbnb RuboCop plugin.
VERSION = '2.0.0'.freeze
VERSION = '3.0.0'
end
end
47 changes: 0 additions & 47 deletions rubocop-airbnb/lib/rubocop/cop/airbnb/class_name.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def enforce_violation(node)
alias on_send enforce_violation
alias on_if enforce_violation

Util::ASGN_NODES.each do |type|
RuboCop::AST::Node::ASSIGNMENTS.each do |type|
define_method("on_#{type}") do |node|
enforce_violation(node)
end
Expand Down
4 changes: 3 additions & 1 deletion rubocop-airbnb/rubocop-airbnb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Gem::Specification.new do |spec|
'Gemfile',
]

spec.add_dependency('rubocop', '~> 0.58.0')
spec.add_dependency('rubocop', '~> 0.76.0')
spec.add_dependency('rubocop-performance', '~> 1.5.0')
spec.add_dependency('rubocop-rails', '~> 2.3.2')
spec.add_dependency('rubocop-rspec', '~> 1.30.0')
spec.add_development_dependency('rspec', '~> 3.5')
end