rubocop-airbnb 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e5601cd8ff7b14b19b4bf38c802b4e1d687c322
4
- data.tar.gz: fb2fca2fe9589451f8f7a1f35ba79372b0ee5b9a
3
+ metadata.gz: 9d17d320064046e37b313b570d8f4ab81f6b615b
4
+ data.tar.gz: 6dead3f9f8849866f8a57c4fc15bb5cb0f0d4176
5
5
  SHA512:
6
- metadata.gz: 2862c58fce4d1f1048df2b58e28978fcb01a943d67339dd93e4175f019cc40757deb378b86e1c2a1c241844652e6d3fff8f75876246e4153bea1da77a1f018cd
7
- data.tar.gz: 252c1280c4b61671975ff387b2b3ded22e55747b8125860ff3b37728ac6192716eb0c118db22cb34fc9ae046e5aec3d56ea74174339f1ea521f983b4f13cde0b
6
+ metadata.gz: 1f95f01b2d2bc692b651dbb364fcf5c5a4a17d4007b0ddc120d97ba3025dc314b091b1bb3b088d0f8182cc4cd9088548d794fedbd3a4702fff86632579fea9e7
7
+ data.tar.gz: 4fd9025bfd1273ed564071eadff4bf17ed416b56def7f24fe10598846b5988cbf9fbf23f2af57072c68c84ebaabae3250467860f1f8557db1cbc4e812bf6dfb5
@@ -1,3 +1,11 @@
1
+ # 3.0.0
2
+ * Update to rubocop 0.76
3
+ * Enable Rails/IgnoredSkipActionFilterOption
4
+ * Enable Rails/ReflectionClassName
5
+ * Disable and delete Airbnb/ClassName
6
+ * Enable Layout/IndentFirstParameter
7
+ * Drop support for Ruby 2.2
8
+
1
9
  # 2.0.0
2
10
  * Upgrade to rubocop-rspec 1.30.0, use ~> to allow for PATCH version flexibility
3
11
  * Upgrade to rubocop 0.58.0, use ~> to allow for PATCH version flexibility
data/README.md CHANGED
@@ -15,6 +15,11 @@ Just put this in your `Gemfile` it depends on the appropriate version of rubocop
15
15
  gem 'rubocop-airbnb'
16
16
  ```
17
17
 
18
+ Note: If you want to run with Ruby 2.2 you will need to set your version to 2
19
+ ```
20
+ gem 'rubocop-airbnb', '~> 2'
21
+ ```
22
+
18
23
  ## Usage
19
24
 
20
25
  You need to tell RuboCop to load the Airbnb extension. There are three
@@ -29,7 +34,7 @@ require:
29
34
  ```
30
35
 
31
36
  Next add the following to `.rubocop.yml`
32
- or add before `.rubocop_todo.yml` in your existin `inherit_from`
37
+ or add before `.rubocop_todo.yml` in your existing `inherit_from`
33
38
 
34
39
  ```
35
40
  inherit_from:
@@ -2,11 +2,6 @@
2
2
  # They are custom built for use inside Airbnb and address issues that we have experienced in
3
3
  # testing and production.
4
4
 
5
- Airbnb/ClassName:
6
- Description: Use :class_name => "Model" instead of :class_name => Model.name
7
- to avoid a long cascade of autoloading.
8
- Enabled: true
9
-
10
5
  Airbnb/ClassOrModuleDeclaredInWrongFile:
11
6
  Description: Declare a class or module in the file that matches its namespace and name.
12
7
  Enabled: true
@@ -7,3 +7,6 @@ Gemspec/RequiredRubyVersion:
7
7
  Enabled: false
8
8
  Include:
9
9
  - '**/*.gemspec'
10
+
11
+ Gemspec/RubyVersionGlobalsUsage:
12
+ Enabled: true
@@ -227,7 +227,7 @@ Layout/FirstMethodParameterLineBreak:
227
227
  Enabled: false
228
228
 
229
229
  # Supports --auto-correct
230
- Layout/FirstParameterIndentation:
230
+ Layout/IndentFirstArgument:
231
231
  Description: Checks the indentation of the first parameter in a method call.
232
232
  Enabled: true
233
233
  EnforcedStyle: consistent
@@ -238,7 +238,7 @@ Layout/FirstParameterIndentation:
238
238
  - special_for_inner_method_call_in_parentheses
239
239
 
240
240
  # Supports --auto-correct
241
- Layout/IndentArray:
241
+ Layout/IndentFirstArrayElement:
242
242
  Description: Checks the indentation of the first element in an array literal.
243
243
  Enabled: true
244
244
  EnforcedStyle: consistent
@@ -248,10 +248,9 @@ Layout/IndentAssignment:
248
248
  Description: Checks the indentation of the first line of the right-hand-side of a
249
249
  multi-line assignment.
250
250
  Enabled: true
251
- IndentationWidth:
252
251
 
253
252
  # Supports --auto-correct
254
- Layout/IndentHash:
253
+ Layout/IndentFirstHashElement:
255
254
  Description: Checks the indentation of the first key in a hash literal.
256
255
  Enabled: true
257
256
  EnforcedStyle: consistent
@@ -344,7 +343,6 @@ Layout/MultilineMethodCallIndentation:
344
343
  SupportedStyles:
345
344
  - aligned
346
345
  - indented
347
- IndentationWidth:
348
346
 
349
347
  Layout/MultilineMethodDefinitionBraceLayout:
350
348
  Description: >-
@@ -474,11 +472,6 @@ Layout/SpaceInsideBlockBraces:
474
472
  EnforcedStyleForEmptyBraces: no_space
475
473
  SpaceBeforeBlockParameters: true
476
474
 
477
- Layout/SpaceInsideParens:
478
- Description: 'No spaces after ( or before ).'
479
- StyleGuide: '#spaces-braces'
480
- Enabled: true
481
-
482
475
  Layout/SpaceInsideArrayLiteralBrackets:
483
476
  EnforcedStyle: no_space
484
477
  SupportedStyles:
@@ -558,3 +551,6 @@ Layout/TrailingWhitespace:
558
551
  Description: Avoid trailing whitespace.
559
552
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-trailing-whitespace
560
553
  Enabled: true
554
+
555
+ Layout/IndentFirstParameter:
556
+ Enabled: true
@@ -80,6 +80,11 @@ Lint/EnsureReturn:
80
80
  Lint/ErbNewArguments:
81
81
  Enabled: false
82
82
 
83
+ Lint/FlipFlop:
84
+ Description: Checks for flip flops
85
+ StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops
86
+ Enabled: false
87
+
83
88
  Lint/FloatOutOfRange:
84
89
  Description: Catches floating-point literals too large or small for Ruby to represent.
85
90
  Enabled: false
@@ -237,20 +242,20 @@ Lint/UnderscorePrefixedVariableName:
237
242
  Lint/UnifiedInteger:
238
243
  Enabled: false
239
244
 
240
- Lint/UnneededCopDisableDirective:
245
+ Lint/RedundantCopDisableDirective:
241
246
  Description: >-
242
247
  Checks for rubocop:disable comments that can be removed.
243
248
  Note: this cop is not disabled when disabling all cops. It must be explicitly disabled.
244
249
  Enabled: true
245
250
 
246
- Lint/UnneededCopEnableDirective:
251
+ Lint/RedundantCopEnableDirective:
247
252
  Description: Checks for rubocop:enable comments that can be removed.
248
253
  Enabled: true
249
254
 
250
- Lint/UnneededRequireStatement:
255
+ Lint/RedundantRequireStatement:
251
256
  Enabled: false
252
257
 
253
- Lint/UnneededSplatExpansion:
258
+ Lint/RedundantSplatExpansion:
254
259
  Enabled: false
255
260
 
256
261
  Lint/UnreachableCode:
@@ -83,3 +83,6 @@ Naming/VariableName:
83
83
 
84
84
  Naming/VariableNumber:
85
85
  Enabled: false
86
+
87
+ Naming/RescuedExceptionsVariableName:
88
+ Enabled: false
@@ -56,11 +56,6 @@ Performance/FlatMap:
56
56
  Performance/InefficientHashSearch:
57
57
  Enabled: false
58
58
 
59
- # Supports --auto-correct
60
- Performance/LstripRstrip:
61
- Description: Use `strip` instead of `lstrip.rstrip`.
62
- Enabled: false
63
-
64
59
  # Supports --auto-correct
65
60
  Performance/RangeInclude:
66
61
  Description: Use `Range#cover?` instead of `Range#include?`.
@@ -85,11 +80,6 @@ Performance/RedundantMerge:
85
80
  Reference: https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code
86
81
  Enabled: false
87
82
 
88
- # Supports --auto-correct
89
- Performance/RedundantSortBy:
90
- Description: Use `sort` instead of `sort_by { |x| x }`.
91
- Enabled: false
92
-
93
83
  Performance/RegexpMatch:
94
84
  Enabled: false
95
85
 
@@ -99,12 +89,6 @@ Performance/ReverseEach:
99
89
  Reference: https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code
100
90
  Enabled: false
101
91
 
102
- # Supports --auto-correct
103
- Performance/Sample:
104
- Description: Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`.
105
- Reference: https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code
106
- Enabled: false
107
-
108
92
  # Supports --auto-correct
109
93
  Performance/Size:
110
94
  Description: Use `size` instead of `count` for counting the number of elements in
@@ -133,9 +117,6 @@ Performance/TimesMap:
133
117
  Performance/UnfreezeString:
134
118
  Enabled: false
135
119
 
136
- Performance/UnneededSort:
137
- Enabled: false
138
-
139
120
  Performance/UriDefaultParser:
140
121
  Enabled: false
141
122
 
@@ -206,3 +206,9 @@ Rails/Validation:
206
206
  Enabled: false
207
207
  Include:
208
208
  - app/models/**/*.rb
209
+
210
+ Rails/IgnoredSkipActionFilterOption:
211
+ Enabled: true
212
+
213
+ Rails/ReflectionClassName:
214
+ Enabled: true
@@ -328,11 +328,6 @@ Style/ExpandPathArguments:
328
328
  Description: "Use `expand_path(__dir__)` instead of `expand_path('..', __FILE__)`."
329
329
  Enabled: false
330
330
 
331
- Style/FlipFlop:
332
- Description: Checks for flip flops
333
- StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops
334
- Enabled: false
335
-
336
331
  Style/For:
337
332
  Description: Checks use of for or each in multiline loops.
338
333
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-for-loops
@@ -360,10 +355,10 @@ Style/FrozenStringLiteralComment:
360
355
  Description: Add the frozen_string_literal comment to the top of files to help transition
361
356
  from Ruby 2.3.0 to Ruby 3.0.
362
357
  Enabled: false
363
- EnforcedStyle: when_needed
364
358
  SupportedStyles:
365
- - when_needed
366
359
  - always
360
+ - never
361
+ EnforcedStyle: always
367
362
 
368
363
  Style/GlobalVars:
369
364
  Description: Do not introduce global variables.
@@ -735,6 +730,11 @@ Style/RedundantSelf:
735
730
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-self-unless-required
736
731
  Enabled: true
737
732
 
733
+ # Supports --auto-correct
734
+ Style/RedundantSortBy:
735
+ Description: Use `sort` instead of `sort_by { |x| x }`.
736
+ Enabled: false
737
+
738
738
  # Supports --auto-correct
739
739
  Style/RegexpLiteral:
740
740
  Description: Use / or %r around regular expressions.
@@ -763,6 +763,12 @@ Style/ReturnNil:
763
763
  Style/SafeNavigation:
764
764
  Enabled: false
765
765
 
766
+ # Supports --auto-correct
767
+ Style/Sample:
768
+ Description: Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`.
769
+ Reference: https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code
770
+ Enabled: false
771
+
766
772
  # Supports --auto-correct
767
773
  Style/SelfAssignment:
768
774
  Description: Checks for places where self-assignment shorthand should have been used.
@@ -856,6 +862,11 @@ Style/StringMethods:
856
862
  PreferredMethods:
857
863
  intern: to_sym
858
864
 
865
+ # Supports --auto-correct
866
+ Style/Strip:
867
+ Description: Use `strip` instead of `lstrip.rstrip`.
868
+ Enabled: false
869
+
859
870
  Style/StructInheritance:
860
871
  Description: Checks for inheritance from Struct.new.
861
872
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-extend-struct-new
@@ -922,24 +933,27 @@ Style/UnlessElse:
922
933
  Enabled: true
923
934
 
924
935
  # Supports --auto-correct
925
- Style/UnneededCapitalW:
936
+ Style/RedundantCapitalW:
926
937
  Description: Checks for %W when interpolation is not needed.
927
938
  Enabled: false
928
939
 
929
- Style/UnneededCondition:
940
+ Style/RedundantCondition:
930
941
  Enabled: false
931
942
 
932
943
  # Supports --auto-correct
933
- Style/UnneededInterpolation:
944
+ Style/RedundantInterpolation:
934
945
  Description: Checks for strings that are just an interpolated expression.
935
946
  Enabled: false
936
947
 
937
948
  # Supports --auto-correct
938
- Style/UnneededPercentQ:
949
+ Style/RedundantPercentQ:
939
950
  Description: Checks for %q/%Q when single quotes or double quotes would do.
940
951
  StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-q
941
952
  Enabled: false
942
953
 
954
+ Style/RedundantSort:
955
+ Enabled: false
956
+
943
957
  Style/UnpackFirst:
944
958
  Enabled: false
945
959
 
@@ -3,6 +3,6 @@
3
3
  module RuboCop
4
4
  module Airbnb
5
5
  # Version information for the the Airbnb RuboCop plugin.
6
- VERSION = '2.0.0'.freeze
6
+ VERSION = '3.0.0'
7
7
  end
8
8
  end
@@ -14,7 +14,7 @@ module RuboCop
14
14
  alias on_send enforce_violation
15
15
  alias on_if enforce_violation
16
16
 
17
- Util::ASGN_NODES.each do |type|
17
+ RuboCop::AST::Node::ASSIGNMENTS.each do |type|
18
18
  define_method("on_#{type}") do |node|
19
19
  enforce_violation(node)
20
20
  end
@@ -25,7 +25,9 @@ Gem::Specification.new do |spec|
25
25
  'Gemfile',
26
26
  ]
27
27
 
28
- spec.add_dependency('rubocop', '~> 0.58.0')
28
+ spec.add_dependency('rubocop', '~> 0.76.0')
29
+ spec.add_dependency('rubocop-performance', '~> 1.5.0')
30
+ spec.add_dependency('rubocop-rails', '~> 2.3.2')
29
31
  spec.add_dependency('rubocop-rspec', '~> 1.30.0')
30
32
  spec.add_development_dependency('rspec', '~> 3.5')
31
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-airbnb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbnb Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.58.0
19
+ version: 0.76.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.58.0
26
+ version: 0.76.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-performance
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.2
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rubocop-rspec
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +113,6 @@ files:
85
113
  - lib/rubocop/airbnb/inject.rb
86
114
  - lib/rubocop/airbnb/rails_autoloading.rb
87
115
  - lib/rubocop/airbnb/version.rb
88
- - lib/rubocop/cop/airbnb/class_name.rb
89
116
  - lib/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file.rb
90
117
  - lib/rubocop/cop/airbnb/const_assigned_in_wrong_file.rb
91
118
  - lib/rubocop/cop/airbnb/continuation_slash.rb
@@ -105,7 +132,6 @@ files:
105
132
  - lib/rubocop/cop/airbnb/spec_constant_assignment.rb
106
133
  - lib/rubocop/cop/airbnb/unsafe_yaml_marshal.rb
107
134
  - rubocop-airbnb.gemspec
108
- - spec/rubocop/cop/airbnb/class_name_spec.rb
109
135
  - spec/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file_spec.rb
110
136
  - spec/rubocop/cop/airbnb/const_assigned_in_wrong_file_spec.rb
111
137
  - spec/rubocop/cop/airbnb/continuation_slash_spec.rb
@@ -145,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
171
  version: '0'
146
172
  requirements: []
147
173
  rubyforge_project:
148
- rubygems_version: 2.2.5
174
+ rubygems_version: 2.5.1
149
175
  signing_key:
150
176
  specification_version: 4
151
177
  summary: Custom code style checking for Airbnb.
@@ -1,47 +0,0 @@
1
- module RuboCop
2
- module Cop
3
- module Airbnb
4
- # Cop to prevent cross-model references, which result in a cascade of autoloads. E.g.,
5
- # belongs_to :user, :class_name => User.name
6
- class ClassName < Cop
7
- MSG = 'Use "Model" instead of Model.name at class scope to avoid cross-model references. ' \
8
- 'They cause a long cascade of autoloading, slowing down app startup and slowing down ' \
9
- 'reloading of zeus after changing a model.'.freeze
10
-
11
- # Is this a has_many, has_one, or belongs_to with a :class_name arg? Make sure the
12
- # class name is a hardcoded string. If not, add an offense and return true.
13
- def on_send(node)
14
- association_statement =
15
- node.command?(:has_many) ||
16
- node.command?(:has_one) ||
17
- node.command?(:belongs_to)
18
-
19
- return unless association_statement
20
-
21
- class_pair = class_name_node(node)
22
-
23
- if class_pair && !string_class_name?(class_pair)
24
- add_offense(class_pair)
25
- end
26
- end
27
-
28
- private
29
-
30
- # Return the descendant node that is a hash pair (:key => value) whose key
31
- # is :class_name.
32
- def class_name_node(node)
33
- node.descendants.detect do |e|
34
- e.is_a?(Parser::AST::Node) &&
35
- e.pair_type? &&
36
- e.children[0].children[0] == :class_name
37
- end
38
- end
39
-
40
- # Given a hash pair :class_name => value, is the value a hardcoded string?
41
- def string_class_name?(class_pair)
42
- class_pair.children[1].str_type?
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,78 +0,0 @@
1
- describe RuboCop::Cop::Airbnb::ClassName do
2
- subject(:cop) { described_class.new }
3
-
4
- describe "belongs_to" do
5
- it 'rejects with Model.name' do
6
- source = [
7
- 'class Coupon',
8
- ' belongs_to :user, :class_name => User.name',
9
- 'end',
10
- ].join("\n")
11
- inspect_source(source)
12
-
13
- expect(cop.offenses.size).to eq(1)
14
- expect(cop.offenses.map(&:line).sort).to eq([2])
15
- end
16
-
17
- it 'passes with "Model"' do
18
- source = [
19
- 'class Coupon',
20
- ' belongs_to :user, :class_name => "User"',
21
- 'end',
22
- ].join("\n")
23
- inspect_source(source)
24
-
25
- expect(cop.offenses).to be_empty
26
- end
27
- end
28
-
29
- describe "has_many" do
30
- it 'rejects with Model.name' do
31
- source = [
32
- 'class Coupon',
33
- ' has_many :reservations, :class_name => Reservation2.name',
34
- 'end',
35
- ].join("\n")
36
- inspect_source(source)
37
-
38
- expect(cop.offenses.size).to eq(1)
39
- expect(cop.offenses.map(&:line)).to eq([2])
40
- end
41
-
42
- it 'passes with "Model"' do
43
- source = [
44
- 'class Coupon',
45
- ' has_many :reservations, :class_name => "Reservation2"',
46
- 'end',
47
- ].join("\n")
48
- inspect_source(source)
49
-
50
- expect(cop.offenses).to be_empty
51
- end
52
- end
53
-
54
- describe "has_one" do
55
- it 'rejects with Model.name' do
56
- source = [
57
- 'class Coupon',
58
- ' has_one :loss, :class_name => Payments::Loss.name',
59
- 'end',
60
- ].join("\n")
61
- inspect_source(source)
62
-
63
- expect(cop.offenses.size).to eq(1)
64
- expect(cop.offenses.map(&:line)).to eq([2])
65
- end
66
-
67
- it 'passes with "Model"' do
68
- source = [
69
- 'class Coupon',
70
- ' has_one :loss, :class_name => "Payments::Loss"',
71
- 'end',
72
- ].join("\n")
73
- inspect_source(source)
74
-
75
- expect(cop.offenses).to be_empty
76
- end
77
- end
78
- end