rubocop-airbnb 3.0.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +19 -1
- data/config/default.yml +18 -8
- data/config/rubocop-layout.yml +18 -13
- data/config/rubocop-lint.yml +8 -9
- data/config/rubocop-metrics.yml +0 -4
- data/config/rubocop-naming.yml +3 -3
- data/config/rubocop-performance.yml +3 -0
- data/config/rubocop-rails.yml +7 -0
- data/config/rubocop-rspec.yml +4 -9
- data/config/rubocop-style.yml +17 -14
- data/lib/rubocop/airbnb/version.rb +1 -1
- data/lib/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file.rb +1 -1
- data/lib/rubocop/cop/airbnb/const_assigned_in_wrong_file.rb +1 -1
- data/lib/rubocop/cop/airbnb/continuation_slash.rb +2 -2
- data/lib/rubocop/cop/airbnb/default_scope.rb +1 -1
- data/lib/rubocop/cop/airbnb/factory_attr_references_class.rb +1 -1
- data/lib/rubocop/cop/airbnb/factory_class_use_string.rb +1 -1
- data/lib/rubocop/cop/airbnb/mass_assignment_accessible_modifier.rb +1 -1
- data/lib/rubocop/cop/airbnb/module_method_in_wrong_file.rb +1 -1
- data/lib/rubocop/cop/airbnb/no_timeout.rb +1 -1
- data/lib/rubocop/cop/airbnb/opt_arg_parameters.rb +1 -1
- data/lib/rubocop/cop/airbnb/phrase_bundle_keys.rb +1 -1
- data/lib/rubocop/cop/airbnb/risky_activerecord_invocation.rb +1 -1
- data/lib/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace.rb +1 -1
- data/lib/rubocop/cop/airbnb/rspec_environment_modification.rb +1 -1
- data/lib/rubocop/cop/airbnb/simple_modifier_conditional.rb +1 -1
- data/lib/rubocop/cop/airbnb/simple_unless.rb +1 -1
- data/lib/rubocop/cop/airbnb/spec_constant_assignment.rb +3 -4
- data/lib/rubocop/cop/airbnb/unsafe_yaml_marshal.rb +1 -1
- data/rubocop-airbnb.gemspec +5 -5
- data/spec/rubocop/cop/airbnb/class_or_module_declared_in_wrong_file_spec.rb +69 -102
- data/spec/rubocop/cop/airbnb/const_assigned_in_wrong_file_spec.rb +58 -101
- data/spec/rubocop/cop/airbnb/continuation_slash_spec.rb +77 -112
- data/spec/rubocop/cop/airbnb/default_scope_spec.rb +24 -31
- data/spec/rubocop/cop/airbnb/factory_attr_references_class_spec.rb +81 -121
- data/spec/rubocop/cop/airbnb/factory_class_use_string_spec.rb +12 -20
- data/spec/rubocop/cop/airbnb/mass_assignment_accessible_modifier_spec.rb +17 -22
- data/spec/rubocop/cop/airbnb/module_method_in_wrong_file_spec.rb +75 -114
- data/spec/rubocop/cop/airbnb/no_timeout_spec.rb +16 -22
- data/spec/rubocop/cop/airbnb/opt_arg_parameter_spec.rb +46 -73
- data/spec/rubocop/cop/airbnb/phrase_bundle_keys_spec.rb +5 -20
- data/spec/rubocop/cop/airbnb/risky_activerecord_invocation_spec.rb +19 -33
- data/spec/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace_spec.rb +109 -187
- data/spec/rubocop/cop/airbnb/rspec_environment_modification_spec.rb +31 -41
- data/spec/rubocop/cop/airbnb/simple_modifier_conditional_spec.rb +64 -88
- data/spec/rubocop/cop/airbnb/simple_unless_spec.rb +17 -27
- data/spec/rubocop/cop/airbnb/spec_constant_assignment_spec.rb +42 -60
- data/spec/rubocop/cop/airbnb/unsafe_yaml_marshal_spec.rb +24 -36
- data/spec/spec_helper.rb +2 -0
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 02cd198bf2e20a941f06c78615775bbbcf525f428a41adbd07d1ef4a7e716509
|
4
|
+
data.tar.gz: 1073b91470656809fb195a4eba990e9303e7389a94af1dba88728bba14ec5c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db877cf8c1eb61e805eb3a700cd489bbc2b3b61cf7b307ed2ae66e3930aa57f85e41bd14740e7117e1ff1d0c7cc0701de542b05e9bfebcb4a180dae976bd2cb1
|
7
|
+
data.tar.gz: 5392e711442b997a3fdccd3cc17eaec5b9d153df6803a4227221c82b20acb24a841e8643e99311c77a2be36b8283bb7afa99e00629b2c4d8a6baa73ae49c697c
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# 5.0.0
|
2
|
+
* Add support for Ruby 3.1
|
3
|
+
* Drop support for Ruby 2.4
|
4
|
+
* Update rubocop to 1.22.0
|
5
|
+
* Update rubocop-rspec to 2.0.0
|
6
|
+
* Remove deprecated cops InvalidPredicateMatcher and CustomIncludeMethods
|
7
|
+
|
8
|
+
# 4.0.0
|
9
|
+
* Add support for Ruby 3.0
|
10
|
+
* Run CI against Ruby 2.7
|
11
|
+
* Drop support for Ruby 2.3
|
12
|
+
* Update rubocop to 0.93.1
|
13
|
+
* Update rubocop-performance to 1.10.2
|
14
|
+
* Update rubocop-rails to 2.9.1
|
15
|
+
* Update rubocop-rspec to 1.44.1
|
16
|
+
* Disable Style/BracesAroundHashParameters
|
17
|
+
* Set `DisabledByDefault: true` to disable any new rubocop cops that have not yet been evaluated for this style guide
|
18
|
+
|
19
|
+
# 3.0.2
|
2
20
|
* Moves `require`s for `rubocop-performance` and `rubocop-rails` to library code for better transitivity.
|
3
21
|
|
4
22
|
# 3.0.1
|
data/config/default.yml
CHANGED
@@ -15,14 +15,24 @@ AllCops:
|
|
15
15
|
- 'vendor/**/*'
|
16
16
|
- Vagrantfile
|
17
17
|
- Guardfile
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
|
19
|
+
# While Rubocop has released a bunch of new cops, not all of these cops have been evaluated as
|
20
|
+
# part of this styleguide. To prevent new, unevaluated cops from imposing on this styleguide, we
|
21
|
+
# are marking these new cops as disabled. Note that as a consumer of this styleguide, you can
|
22
|
+
# always override any choices here by setting `Enabled: true` on any cops that you would like to
|
23
|
+
# have be enabled, even if we have explicitly disabled them (or if they are new and we have yet
|
24
|
+
# to evaluate them). For more on this configuration parameter, see
|
25
|
+
# https://github.com/rubocop/rubocop/blob/1e55b1aa5e4c5eaeccad5d61f08b7930ed6bc341/config/default.yml#L89-L101
|
26
|
+
DisabledByDefault: true
|
27
|
+
|
28
|
+
RSpec:
|
29
|
+
Include:
|
30
|
+
- _spec.rb
|
31
|
+
- "(?:^|/)spec/"
|
32
|
+
RSpec/FactoryBot:
|
33
|
+
Include:
|
34
|
+
- spec/factories/**/*.rb
|
35
|
+
- features/support/factories/**/*.rb
|
26
36
|
|
27
37
|
inherit_from:
|
28
38
|
- './rubocop-airbnb.yml'
|
data/config/rubocop-layout.yml
CHANGED
@@ -11,13 +11,13 @@ Layout/AccessModifierIndentation:
|
|
11
11
|
- indent
|
12
12
|
|
13
13
|
# Supports --auto-correct
|
14
|
-
Layout/
|
14
|
+
Layout/ArrayAlignment:
|
15
15
|
Description: Align the elements of an array literal if they span more than one line.
|
16
16
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#align-multiline-arrays
|
17
17
|
Enabled: true
|
18
18
|
|
19
19
|
# Supports --auto-correct
|
20
|
-
Layout/
|
20
|
+
Layout/HashAlignment:
|
21
21
|
Description: Align the elements of a hash literal if they span more than one line.
|
22
22
|
Enabled: true
|
23
23
|
EnforcedHashRocketStyle: key
|
@@ -30,7 +30,7 @@ Layout/AlignHash:
|
|
30
30
|
- ignore_explicit
|
31
31
|
|
32
32
|
# Supports --auto-correct
|
33
|
-
Layout/
|
33
|
+
Layout/ParameterAlignment:
|
34
34
|
Description: Align the parameters of a method call if they span more than one line.
|
35
35
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-double-indent
|
36
36
|
Enabled: true
|
@@ -227,7 +227,7 @@ Layout/FirstMethodParameterLineBreak:
|
|
227
227
|
Enabled: false
|
228
228
|
|
229
229
|
# Supports --auto-correct
|
230
|
-
Layout/
|
230
|
+
Layout/FirstArgumentIndentation:
|
231
231
|
Description: Checks the indentation of the first parameter in a method call.
|
232
232
|
Enabled: true
|
233
233
|
EnforcedStyle: consistent
|
@@ -238,19 +238,19 @@ Layout/IndentFirstArgument:
|
|
238
238
|
- special_for_inner_method_call_in_parentheses
|
239
239
|
|
240
240
|
# Supports --auto-correct
|
241
|
-
Layout/
|
241
|
+
Layout/FirstArrayElementIndentation:
|
242
242
|
Description: Checks the indentation of the first element in an array literal.
|
243
243
|
Enabled: true
|
244
244
|
EnforcedStyle: consistent
|
245
245
|
|
246
246
|
# Supports --auto-correct
|
247
|
-
Layout/
|
247
|
+
Layout/AssignmentIndentation:
|
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
251
|
|
252
252
|
# Supports --auto-correct
|
253
|
-
Layout/
|
253
|
+
Layout/FirstHashElementIndentation:
|
254
254
|
Description: Checks the indentation of the first key in a hash literal.
|
255
255
|
Enabled: true
|
256
256
|
EnforcedStyle: consistent
|
@@ -258,7 +258,7 @@ Layout/IndentFirstHashElement:
|
|
258
258
|
- special_inside_parentheses
|
259
259
|
- consistent
|
260
260
|
|
261
|
-
Layout/
|
261
|
+
Layout/HeredocIndentation:
|
262
262
|
Enabled: false
|
263
263
|
|
264
264
|
# Supports --auto-correct
|
@@ -268,7 +268,7 @@ Layout/IndentationConsistency:
|
|
268
268
|
EnforcedStyle: normal
|
269
269
|
SupportedStyles:
|
270
270
|
- normal
|
271
|
-
-
|
271
|
+
- indented_internal_methods
|
272
272
|
|
273
273
|
# Supports --auto-correct
|
274
274
|
Layout/IndentationWidth:
|
@@ -282,7 +282,7 @@ Layout/InitialIndentation:
|
|
282
282
|
Description: Checks the indentation of the first non-blank non-comment line in a file.
|
283
283
|
Enabled: true
|
284
284
|
|
285
|
-
Layout/
|
285
|
+
Layout/LeadingEmptyLines:
|
286
286
|
Enabled: true
|
287
287
|
|
288
288
|
# Supports --auto-correct
|
@@ -531,13 +531,13 @@ Layout/SpaceInsideStringInterpolation:
|
|
531
531
|
- no_space
|
532
532
|
|
533
533
|
# Supports --auto-correct
|
534
|
-
Layout/
|
534
|
+
Layout/IndentationStyle:
|
535
535
|
Description: No hard tabs.
|
536
536
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#spaces-indentation
|
537
537
|
Enabled: true
|
538
538
|
|
539
539
|
# Supports --auto-correct
|
540
|
-
Layout/
|
540
|
+
Layout/TrailingEmptyLines:
|
541
541
|
Description: Checks trailing blank lines and final newline.
|
542
542
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#newline-eof
|
543
543
|
Enabled: true
|
@@ -552,5 +552,10 @@ Layout/TrailingWhitespace:
|
|
552
552
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-trailing-whitespace
|
553
553
|
Enabled: true
|
554
554
|
|
555
|
-
Layout/
|
555
|
+
Layout/FirstParameterIndentation:
|
556
556
|
Enabled: true
|
557
|
+
|
558
|
+
# Supports --auto-correct
|
559
|
+
Layout/LineLength:
|
560
|
+
Max: 100
|
561
|
+
AllowURI: true
|
data/config/rubocop-lint.yml
CHANGED
@@ -45,7 +45,7 @@ Lint/DuplicateMethods:
|
|
45
45
|
Description: Check for duplicate methods calls.
|
46
46
|
Enabled: true
|
47
47
|
|
48
|
-
Lint/
|
48
|
+
Lint/DuplicateHashKey:
|
49
49
|
Description: Check for duplicate keys in hash literals.
|
50
50
|
Enabled: true
|
51
51
|
|
@@ -68,10 +68,6 @@ Lint/EmptyInterpolation:
|
|
68
68
|
Lint/EmptyWhen:
|
69
69
|
Enabled: false
|
70
70
|
|
71
|
-
Lint/EndInMethod:
|
72
|
-
Description: END blocks should not be placed inside method definitions.
|
73
|
-
Enabled: false
|
74
|
-
|
75
71
|
Lint/EnsureReturn:
|
76
72
|
Description: Do not use return in an ensure block.
|
77
73
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-return-ensure
|
@@ -93,7 +89,7 @@ Lint/FormatParameterMismatch:
|
|
93
89
|
Description: The number of parameters to format/sprint must match the fields.
|
94
90
|
Enabled: true
|
95
91
|
|
96
|
-
Lint/
|
92
|
+
Lint/SuppressedException:
|
97
93
|
Description: Don't suppress exception.
|
98
94
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#dont-hide-exceptions
|
99
95
|
Enabled: false
|
@@ -144,7 +140,10 @@ Lint/MissingCopEnableDirective:
|
|
144
140
|
Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`'
|
145
141
|
Enabled: true
|
146
142
|
|
147
|
-
Lint/
|
143
|
+
Lint/MissingSuper:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
Lint/MultipleComparison:
|
148
147
|
Enabled: false
|
149
148
|
|
150
149
|
Lint/NestedMethodDefinition:
|
@@ -230,7 +229,7 @@ Lint/ShadowingOuterLocalVariable:
|
|
230
229
|
Enabled: true
|
231
230
|
|
232
231
|
# Supports --auto-correct
|
233
|
-
Lint/
|
232
|
+
Lint/RedundantStringCoercion:
|
234
233
|
Description: Checks for Object#to_s usage in string interpolation.
|
235
234
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-to-s
|
236
235
|
Enabled: true
|
@@ -289,7 +288,7 @@ Lint/UselessAssignment:
|
|
289
288
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#underscore-unused-vars
|
290
289
|
Enabled: true
|
291
290
|
|
292
|
-
Lint/
|
291
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
293
292
|
Description: Checks for comparison of something with itself.
|
294
293
|
Enabled: true
|
295
294
|
|
data/config/rubocop-metrics.yml
CHANGED
data/config/rubocop-naming.yml
CHANGED
@@ -55,18 +55,18 @@ Naming/PredicateName:
|
|
55
55
|
- is_
|
56
56
|
- has_
|
57
57
|
- have_
|
58
|
-
|
58
|
+
ForbiddenPrefixes:
|
59
59
|
- is_
|
60
60
|
- has_
|
61
61
|
- have_
|
62
62
|
|
63
|
-
Naming/
|
63
|
+
Naming/BlockParameterName:
|
64
64
|
Description: >-
|
65
65
|
Checks for block parameter names that contain capital letters,
|
66
66
|
end in numbers, or do not meet a minimal length.
|
67
67
|
Enabled: false
|
68
68
|
|
69
|
-
Naming/
|
69
|
+
Naming/MethodParameterName:
|
70
70
|
Description: >-
|
71
71
|
Checks for method parameter names that contain capital letters,
|
72
72
|
end in numbers, or do not meet a minimal length.
|
data/config/rubocop-rails.yml
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rails
|
3
|
+
|
1
4
|
# before_action doesn't seem to exist, so this doesn't make sense.
|
2
5
|
Rails/ActionFilter:
|
3
6
|
Enabled: false
|
@@ -212,3 +215,7 @@ Rails/IgnoredSkipActionFilterOption:
|
|
212
215
|
|
213
216
|
Rails/ReflectionClassName:
|
214
217
|
Enabled: true
|
218
|
+
|
219
|
+
Rails/RakeEnvironment:
|
220
|
+
Description: Ensures that rake tasks depend on :environment
|
221
|
+
Enabled: false
|
data/config/rubocop-rspec.yml
CHANGED
@@ -56,7 +56,6 @@ RSpec/DescribedClass:
|
|
56
56
|
RSpec/EmptyExampleGroup:
|
57
57
|
Description: Checks if an example group does not include any tests.
|
58
58
|
Enabled: true
|
59
|
-
CustomIncludeMethods: []
|
60
59
|
|
61
60
|
RSpec/EmptyLineAfterExampleGroup:
|
62
61
|
Description: Checks if there is an empty line after example group blocks.
|
@@ -155,10 +154,6 @@ RSpec/InstanceVariable:
|
|
155
154
|
Description: 'Checks for the usage of instance variables.'
|
156
155
|
Enabled: false
|
157
156
|
|
158
|
-
RSpec/InvalidPredicateMatcher:
|
159
|
-
Description: Checks invalid usage for predicate matcher.
|
160
|
-
Enabled: false
|
161
|
-
|
162
157
|
RSpec/ItBehavesLike:
|
163
158
|
Description: Checks that only one `it_behaves_like` style is used.
|
164
159
|
Enabled: false
|
@@ -314,18 +309,18 @@ RSpec/VoidExpect:
|
|
314
309
|
Description: This cop checks void `expect()`.
|
315
310
|
Enabled: false
|
316
311
|
|
317
|
-
Capybara/CurrentPathExpectation:
|
312
|
+
RSpec/Capybara/CurrentPathExpectation:
|
318
313
|
Description: Checks that no expectations are set on Capybara's `current_path`.
|
319
314
|
Enabled: false
|
320
315
|
|
321
|
-
Capybara/FeatureMethods:
|
316
|
+
RSpec/Capybara/FeatureMethods:
|
322
317
|
Description: Checks for consistent method usage in feature specs.
|
323
318
|
Enabled: false
|
324
319
|
|
325
|
-
FactoryBot/AttributeDefinedStatically:
|
320
|
+
RSpec/FactoryBot/AttributeDefinedStatically:
|
326
321
|
Description: Always declare attribute values as blocks.
|
327
322
|
Enabled: false
|
328
323
|
|
329
|
-
FactoryBot/CreateList:
|
324
|
+
RSpec/FactoryBot/CreateList:
|
330
325
|
Description: Checks for create_list usage.
|
331
326
|
Enabled: true
|
data/config/rubocop-style.yml
CHANGED
@@ -134,16 +134,6 @@ Style/BlockDelimiters:
|
|
134
134
|
- proc
|
135
135
|
- it
|
136
136
|
|
137
|
-
# Supports --auto-correct
|
138
|
-
Style/BracesAroundHashParameters:
|
139
|
-
Description: Enforce braces style around hash parameters.
|
140
|
-
Enabled: false
|
141
|
-
EnforcedStyle: no_braces
|
142
|
-
SupportedStyles:
|
143
|
-
- braces
|
144
|
-
- no_braces
|
145
|
-
- context_dependent
|
146
|
-
|
147
137
|
Style/CaseEquality:
|
148
138
|
Description: Avoid explicit use of the case equality operator(===).
|
149
139
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-case-equality
|
@@ -357,8 +347,9 @@ Style/FrozenStringLiteralComment:
|
|
357
347
|
Enabled: false
|
358
348
|
SupportedStyles:
|
359
349
|
- always
|
350
|
+
- always_true
|
360
351
|
- never
|
361
|
-
EnforcedStyle:
|
352
|
+
EnforcedStyle: always_true
|
362
353
|
|
363
354
|
Style/GlobalVars:
|
364
355
|
Description: Do not introduce global variables.
|
@@ -458,9 +449,6 @@ Style/MethodDefParentheses:
|
|
458
449
|
- require_parentheses
|
459
450
|
- require_no_parentheses
|
460
451
|
|
461
|
-
Style/MethodMissingSuper:
|
462
|
-
Enabled: false
|
463
|
-
|
464
452
|
Style/MissingRespondToMissing:
|
465
453
|
Enabled: false
|
466
454
|
|
@@ -824,6 +812,21 @@ Style/SpecialGlobalVars:
|
|
824
812
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-cryptic-perlisms
|
825
813
|
Enabled: true
|
826
814
|
|
815
|
+
Style/HashEachMethods:
|
816
|
+
Description: Enforce use of each_key and each_value Hash methods.
|
817
|
+
StyleGuide: https://docs.rubocop.org/en/latest/cops_style/#stylehasheachmethods
|
818
|
+
Enabled: false
|
819
|
+
|
820
|
+
Style/HashTransformKeys:
|
821
|
+
Description: Enforce use of transform_keys Hash methods. Not suggested for use below ruby 2.5
|
822
|
+
StyleGuide: https://docs.rubocop.org/en/latest/cops_style/#stylehashtransformkeys
|
823
|
+
Enabled: false
|
824
|
+
|
825
|
+
Style/HashTransformValues:
|
826
|
+
Description: Enforce use of transform_values Hash methods. Not suggested for use below ruby 2.5
|
827
|
+
StyleGuide: https://docs.rubocop.org/en/latest/cops_style/#stylehashtransformvalues
|
828
|
+
Enabled: false
|
829
|
+
|
827
830
|
Style/StabbyLambdaParentheses:
|
828
831
|
Description: Check for the usage of parentheses around stabby lambda arguments.
|
829
832
|
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#stabby-lambda-with-args
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Cop
|
3
3
|
module Airbnb
|
4
|
-
class ContinuationSlash <
|
4
|
+
class ContinuationSlash < Base
|
5
5
|
MSG = 'Slash continuation should be reserved for closed string continuation. ' \
|
6
6
|
'Many times it is used to get around other existing rules.'.freeze
|
7
7
|
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
alias on_send enforce_violation
|
15
15
|
alias on_if enforce_violation
|
16
16
|
|
17
|
-
RuboCop::AST::Node::ASSIGNMENTS.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
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Cop to help prevent the scorge of Default Scopes from ActiveRecord.
|
5
5
|
# Once in place they are almost impossible to remove.
|
6
|
-
class DefaultScope <
|
6
|
+
class DefaultScope < Base
|
7
7
|
MSG = 'Avoid `default_scope`. Default scopes make it difficult to '\
|
8
8
|
'refactor data access patterns since the scope becomes part '\
|
9
9
|
'of every query unless explicitly excluded, even when it is '\
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# Cop to enforce "attr { CONST }" instead of "attr CONST" in factories,
|
5
5
|
# because the latter forces autoload, which slows down spec startup time and
|
6
6
|
# Zeus reload time after touching a model.
|
7
|
-
class FactoryAttrReferencesClass <
|
7
|
+
class FactoryAttrReferencesClass < Base
|
8
8
|
MSG = "Instead of attr_name MyClass::MY_CONST, use attr_name { MyClass::MY_CONST }. " \
|
9
9
|
"This enables faster spec startup time and Zeus reload time.".freeze
|
10
10
|
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Cop to tell developers to use :class => "MyClass" instead of :class => MyClass,
|
5
5
|
# because the latter slows down reloading zeus.
|
6
|
-
class FactoryClassUseString <
|
6
|
+
class FactoryClassUseString < Base
|
7
7
|
MSG = 'Instead of :class => MyClass, use :class => "MyClass". ' \
|
8
8
|
"This enables faster spec startup time and faster Zeus reload time.".freeze
|
9
9
|
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Modifying Mass assignment restrictions eliminates the entire point of disabling
|
5
5
|
# mass assignment. It's a lazy, potentially dangerous approach that should be discouraged.
|
6
|
-
class MassAssignmentAccessibleModifier <
|
6
|
+
class MassAssignmentAccessibleModifier < Base
|
7
7
|
MSG = 'Do no override and objects mass assignment restrictions.'.freeze
|
8
8
|
|
9
9
|
def on_send(node)
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Cop to enforce use of options hash over default arguments
|
5
5
|
# https://github.com/airbnb/ruby#no-default-args
|
6
|
-
class OptArgParameters <
|
6
|
+
class OptArgParameters < Base
|
7
7
|
MSG =
|
8
8
|
'Do not use default positional arguments. '\
|
9
9
|
'Use keyword arguments or an options hash instead.'.freeze
|
@@ -2,7 +2,7 @@ module RuboCop
|
|
2
2
|
module Cop
|
3
3
|
module Airbnb
|
4
4
|
# Disallow ActiveRecord calls that pass interpolated or added strings as an argument.
|
5
|
-
class RiskyActiverecordInvocation <
|
5
|
+
class RiskyActiverecordInvocation < Base
|
6
6
|
VULNERABLE_AR_METHODS = [
|
7
7
|
:delete_all,
|
8
8
|
:destroy_all,
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
#
|
21
21
|
# describe Foo::Bar
|
22
22
|
# end
|
23
|
-
class RspecDescribeOrContextUnderNamespace <
|
23
|
+
class RspecDescribeOrContextUnderNamespace < Base
|
24
24
|
DESCRIBE_OR_CONTEXT_UNDER_NAMESPACE_MSG =
|
25
25
|
'Declaring a `module` in a spec can break autoloading because subsequent references ' \
|
26
26
|
'to it will not cause it to be loaded from the app. This could cause flaky tests.'.freeze
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
# before(:each) do
|
29
29
|
# stub_env(:production)
|
30
30
|
# end
|
31
|
-
class RspecEnvironmentModification <
|
31
|
+
class RspecEnvironmentModification < Base
|
32
32
|
def_node_matcher :allow_or_expect_rails_env, <<-PATTERN
|
33
33
|
(send (send nil? {:expect :allow} (send (const nil? :Rails) :env)) :to ...)
|
34
34
|
PATTERN
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Cop to tackle prevent more complicated modifier if/unless statements
|
5
5
|
# https://github.com/airbnb/ruby#only-simple-if-unless
|
6
|
-
class SimpleModifierConditional <
|
6
|
+
class SimpleModifierConditional < Base
|
7
7
|
MSG = 'Modifier if/unless usage is okay when the body is simple, ' \
|
8
8
|
'the condition is simple, and the whole thing fits on one line. ' \
|
9
9
|
'Otherwise, avoid modifier if/unless.'.freeze
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
module Airbnb
|
4
4
|
# Cop to tackle prevent unless statements with multiple conditions
|
5
5
|
# https://github.com/airbnb/ruby#unless-with-multiple-conditions
|
6
|
-
class SimpleUnless <
|
6
|
+
class SimpleUnless < Base
|
7
7
|
MSG = 'Unless usage is okay when there is only one conditional'.freeze
|
8
8
|
|
9
9
|
def_node_matcher :multiple_conditionals?, '(if ({and or :^} ...) ...)'
|
@@ -25,16 +25,15 @@ module RuboCop
|
|
25
25
|
# describe Something do
|
26
26
|
# before { stub_const('MyClass::PAYLOAD', [1, 2, 3])
|
27
27
|
# end
|
28
|
-
class SpecConstantAssignment <
|
29
|
-
include RuboCop::RSpec::TopLevelDescribe
|
28
|
+
class SpecConstantAssignment < Base
|
30
29
|
MESSAGE = "Defining constants inside of specs can cause spurious behavior. " \
|
31
|
-
"It is almost always preferable to use `let` statements, "\
|
30
|
+
"It is almost always preferable to use `let` statements, " \
|
32
31
|
"anonymous class/module definitions, or stub_const".freeze
|
33
32
|
|
34
33
|
def on_casgn(node)
|
35
34
|
return unless in_spec_file?(node)
|
36
35
|
parent_module_name = node.parent_module_name
|
37
|
-
if
|
36
|
+
if parent_module_name && parent_module_name != "Object"
|
38
37
|
return
|
39
38
|
end
|
40
39
|
add_offense(node, message: MESSAGE)
|
@@ -2,7 +2,7 @@ module RuboCop
|
|
2
2
|
module Cop
|
3
3
|
module Airbnb
|
4
4
|
# Disallow use of YAML/Marshal methods that can trigger RCE on untrusted input
|
5
|
-
class UnsafeYamlMarshal <
|
5
|
+
class UnsafeYamlMarshal < Base
|
6
6
|
MSG = 'Using unsafe YAML parsing methods on untrusted input can lead ' \
|
7
7
|
'to remote code execution. Use `safe_load`, `parse`, `parse_file`, or ' \
|
8
8
|
'`parse_stream` instead'.freeze
|
data/rubocop-airbnb.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
spec.version = RuboCop::Airbnb::VERSION
|
17
17
|
spec.platform = Gem::Platform::RUBY
|
18
|
-
spec.required_ruby_version = '>= 2.
|
18
|
+
spec.required_ruby_version = '>= 2.5'
|
19
19
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.files = Dir[
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
'Gemfile',
|
26
26
|
]
|
27
27
|
|
28
|
-
spec.add_dependency('rubocop', '~>
|
29
|
-
spec.add_dependency('rubocop-performance', '~> 1.
|
30
|
-
spec.add_dependency('rubocop-rails', '~> 2.
|
31
|
-
spec.add_dependency('rubocop-rspec', '~>
|
28
|
+
spec.add_dependency('rubocop', '~> 1.22.0')
|
29
|
+
spec.add_dependency('rubocop-performance', '~> 1.10.2')
|
30
|
+
spec.add_dependency('rubocop-rails', '~> 2.9.1')
|
31
|
+
spec.add_dependency('rubocop-rspec', '~> 2.0.0')
|
32
32
|
spec.add_development_dependency('rspec', '~> 3.5')
|
33
33
|
end
|