rubocop 0.47.1 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -16
  3. data/config/default.yml +203 -115
  4. data/config/disabled.yml +0 -5
  5. data/config/enabled.yml +92 -8
  6. data/lib/rubocop.rb +24 -1
  7. data/lib/rubocop/ast/builder.rb +7 -2
  8. data/lib/rubocop/ast/node.rb +23 -20
  9. data/lib/rubocop/ast/node/and_node.rb +37 -0
  10. data/lib/rubocop/ast/node/array_node.rb +4 -1
  11. data/lib/rubocop/ast/node/case_node.rb +1 -0
  12. data/lib/rubocop/ast/node/ensure_node.rb +25 -0
  13. data/lib/rubocop/ast/node/hash_node.rb +10 -3
  14. data/lib/rubocop/ast/node/if_node.rb +2 -0
  15. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +23 -0
  16. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +35 -0
  17. data/lib/rubocop/ast/node/or_node.rb +37 -0
  18. data/lib/rubocop/ast/node/resbody_node.rb +25 -0
  19. data/lib/rubocop/ast/node/send_node.rb +190 -0
  20. data/lib/rubocop/ast/node/when_node.rb +1 -1
  21. data/lib/rubocop/ast/traversal.rb +15 -15
  22. data/lib/rubocop/comment_config.rb +1 -1
  23. data/lib/rubocop/config.rb +39 -15
  24. data/lib/rubocop/config_loader.rb +34 -13
  25. data/lib/rubocop/cop/bundler/ordered_gems.rb +23 -4
  26. data/lib/rubocop/cop/commissioner.rb +4 -0
  27. data/lib/rubocop/cop/cop.rb +5 -0
  28. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +53 -0
  29. data/lib/rubocop/cop/lint/debugger.rb +8 -1
  30. data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -1
  31. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +2 -4
  32. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
  33. data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -1
  34. data/lib/rubocop/cop/lint/empty_ensure.rb +6 -2
  35. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  36. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +20 -18
  37. data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -3
  38. data/lib/rubocop/cop/lint/literal_in_condition.rb +1 -1
  39. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  40. data/lib/rubocop/cop/lint/multiple_compare.rb +5 -3
  41. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +26 -18
  42. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +7 -8
  43. data/lib/rubocop/cop/lint/require_parentheses.rb +7 -13
  44. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +7 -3
  45. data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -6
  46. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +7 -8
  47. data/lib/rubocop/cop/lint/unneeded_disable.rb +35 -11
  48. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
  49. data/lib/rubocop/cop/lint/unreachable_code.rb +5 -2
  50. data/lib/rubocop/cop/lint/unused_block_argument.rb +6 -6
  51. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -1
  52. data/lib/rubocop/cop/lint/useless_comparison.rb +5 -4
  53. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  54. data/lib/rubocop/cop/message_annotator.rb +7 -3
  55. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  56. data/lib/rubocop/cop/metrics/block_nesting.rb +4 -4
  57. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
  58. data/lib/rubocop/cop/metrics/line_length.rb +2 -9
  59. data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -3
  60. data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
  61. data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
  62. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -2
  63. data/lib/rubocop/cop/mixin/check_assignment.rb +6 -6
  64. data/lib/rubocop/cop/mixin/duplication.rb +1 -1
  65. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  66. data/lib/rubocop/cop/mixin/ignored_pattern.rb +27 -0
  67. data/lib/rubocop/cop/mixin/method_preference.rb +2 -0
  68. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +17 -29
  69. data/lib/rubocop/cop/mixin/on_method_def.rb +3 -3
  70. data/lib/rubocop/cop/mixin/percent_literal.rb +27 -0
  71. data/lib/rubocop/cop/mixin/rescue_node.rb +21 -0
  72. data/lib/rubocop/cop/mixin/safe_mode.rb +1 -1
  73. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  74. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -1
  75. data/lib/rubocop/cop/mixin/target_rails_version.rb +16 -0
  76. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
  77. data/lib/rubocop/cop/offense.rb +3 -3
  78. data/lib/rubocop/cop/performance/casecmp.rb +1 -1
  79. data/lib/rubocop/cop/performance/detect.rb +2 -1
  80. data/lib/rubocop/cop/performance/double_start_end_with.rb +35 -1
  81. data/lib/rubocop/cop/performance/end_with.rb +3 -1
  82. data/lib/rubocop/cop/performance/flat_map.rb +6 -6
  83. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -2
  84. data/lib/rubocop/cop/performance/range_include.rb +3 -1
  85. data/lib/rubocop/cop/performance/redundant_match.rb +6 -5
  86. data/lib/rubocop/cop/performance/regexp_match.rb +10 -3
  87. data/lib/rubocop/cop/performance/reverse_each.rb +2 -1
  88. data/lib/rubocop/cop/performance/size.rb +6 -11
  89. data/lib/rubocop/cop/performance/start_with.rb +3 -1
  90. data/lib/rubocop/cop/performance/string_replacement.rb +13 -18
  91. data/lib/rubocop/cop/performance/times_map.rb +4 -4
  92. data/lib/rubocop/cop/rails/action_filter.rb +42 -42
  93. data/lib/rubocop/cop/rails/active_support_aliases.rb +68 -0
  94. data/lib/rubocop/cop/rails/blank.rb +131 -0
  95. data/lib/rubocop/cop/rails/date.rb +25 -28
  96. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +5 -7
  97. data/lib/rubocop/cop/rails/dynamic_find_by.rb +7 -3
  98. data/lib/rubocop/cop/rails/exit.rb +9 -9
  99. data/lib/rubocop/cop/rails/file_path.rb +5 -14
  100. data/lib/rubocop/cop/rails/find_by.rb +8 -10
  101. data/lib/rubocop/cop/rails/find_each.rb +6 -9
  102. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -0
  103. data/lib/rubocop/cop/rails/http_positional_arguments.rb +15 -7
  104. data/lib/rubocop/cop/rails/output.rb +3 -5
  105. data/lib/rubocop/cop/rails/output_safety.rb +4 -8
  106. data/lib/rubocop/cop/rails/pluralization_grammar.rb +25 -24
  107. data/lib/rubocop/cop/rails/present.rb +137 -0
  108. data/lib/rubocop/cop/rails/read_write_attribute.rb +9 -18
  109. data/lib/rubocop/cop/rails/relative_date_constant.rb +53 -0
  110. data/lib/rubocop/cop/rails/request_referer.rb +7 -4
  111. data/lib/rubocop/cop/rails/reversible_migration.rb +1 -2
  112. data/lib/rubocop/cop/rails/safe_navigation.rb +2 -1
  113. data/lib/rubocop/cop/rails/save_bang.rb +10 -10
  114. data/lib/rubocop/cop/rails/skips_model_validations.rb +23 -6
  115. data/lib/rubocop/cop/rails/time_zone.rb +20 -18
  116. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -2
  117. data/lib/rubocop/cop/rails/validation.rb +8 -11
  118. data/lib/rubocop/cop/registry.rb +3 -3
  119. data/lib/rubocop/cop/security/json_load.rb +1 -1
  120. data/lib/rubocop/cop/security/marshal_load.rb +5 -1
  121. data/lib/rubocop/cop/security/yaml_load.rb +3 -3
  122. data/lib/rubocop/cop/severity.rb +1 -1
  123. data/lib/rubocop/cop/style/alias.rb +5 -5
  124. data/lib/rubocop/cop/style/align_hash.rb +1 -1
  125. data/lib/rubocop/cop/style/align_parameters.rb +5 -5
  126. data/lib/rubocop/cop/style/and_or.rb +16 -31
  127. data/lib/rubocop/cop/style/attr.rb +14 -8
  128. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +8 -11
  129. data/lib/rubocop/cop/style/block_delimiters.rb +11 -13
  130. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -23
  131. data/lib/rubocop/cop/style/case_indentation.rb +2 -0
  132. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  133. data/lib/rubocop/cop/style/class_check.rb +5 -7
  134. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +5 -4
  135. data/lib/rubocop/cop/style/collection_methods.rb +8 -8
  136. data/lib/rubocop/cop/style/colon_method_call.rb +2 -9
  137. data/lib/rubocop/cop/style/conditional_assignment.rb +38 -45
  138. data/lib/rubocop/cop/style/constant_name.rb +1 -1
  139. data/lib/rubocop/cop/style/documentation_method.rb +1 -0
  140. data/lib/rubocop/cop/style/dot_position.rb +3 -7
  141. data/lib/rubocop/cop/style/double_negation.rb +2 -1
  142. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  143. data/lib/rubocop/cop/style/empty_else.rb +2 -2
  144. data/lib/rubocop/cop/style/empty_line_after_magic_comment.rb +63 -0
  145. data/lib/rubocop/cop/style/empty_line_between_defs.rb +74 -4
  146. data/lib/rubocop/cop/style/empty_lines_around_begin_body.rb +42 -0
  147. data/lib/rubocop/cop/style/empty_lines_around_exception_handling_keywords.rb +127 -0
  148. data/lib/rubocop/cop/style/empty_literal.rb +17 -9
  149. data/lib/rubocop/cop/style/end_of_line.rb +25 -3
  150. data/lib/rubocop/cop/style/file_name.rb +1 -1
  151. data/lib/rubocop/cop/style/first_method_argument_line_break.rb +1 -1
  152. data/lib/rubocop/cop/style/first_parameter_indentation.rb +17 -19
  153. data/lib/rubocop/cop/style/for.rb +2 -4
  154. data/lib/rubocop/cop/style/format_string.rb +5 -4
  155. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  156. data/lib/rubocop/cop/style/identical_conditional_branches.rb +27 -1
  157. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  158. data/lib/rubocop/cop/style/indent_assignment.rb +2 -2
  159. data/lib/rubocop/cop/style/indent_hash.rb +2 -1
  160. data/lib/rubocop/cop/style/indent_heredoc.rb +173 -0
  161. data/lib/rubocop/cop/style/indentation_width.rb +61 -29
  162. data/lib/rubocop/cop/style/inverse_methods.rb +130 -0
  163. data/lib/rubocop/cop/style/lambda_call.rb +15 -11
  164. data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -4
  165. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +26 -14
  166. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -16
  167. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
  168. data/lib/rubocop/cop/style/missing_else.rb +4 -3
  169. data/lib/rubocop/cop/style/mixin_grouping.rb +97 -0
  170. data/lib/rubocop/cop/style/multiline_memoization.rb +38 -5
  171. data/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb +2 -3
  172. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +38 -19
  173. data/lib/rubocop/cop/style/mutable_constant.rb +5 -1
  174. data/lib/rubocop/cop/style/negated_if.rb +73 -1
  175. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +21 -19
  176. data/lib/rubocop/cop/style/next.rb +5 -5
  177. data/lib/rubocop/cop/style/non_nil_check.rb +7 -10
  178. data/lib/rubocop/cop/style/not.rb +3 -4
  179. data/lib/rubocop/cop/style/numeric_literals.rb +25 -3
  180. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  181. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
  182. data/lib/rubocop/cop/style/op_method.rb +2 -2
  183. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -3
  184. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +52 -6
  185. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  186. data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -9
  187. data/lib/rubocop/cop/style/raise_args.rb +28 -24
  188. data/lib/rubocop/cop/style/redundant_freeze.rb +5 -7
  189. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -3
  190. data/lib/rubocop/cop/style/redundant_self.rb +17 -35
  191. data/lib/rubocop/cop/style/rescue_modifier.rb +2 -14
  192. data/lib/rubocop/cop/style/self_assignment.rb +3 -3
  193. data/lib/rubocop/cop/style/send.rb +4 -5
  194. data/lib/rubocop/cop/style/space_after_not.rb +7 -8
  195. data/lib/rubocop/cop/style/space_around_keyword.rb +8 -9
  196. data/lib/rubocop/cop/style/space_around_operators.rb +19 -15
  197. data/lib/rubocop/cop/style/space_before_first_arg.rb +17 -14
  198. data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -1
  199. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +3 -3
  200. data/lib/rubocop/cop/style/space_inside_parens.rb +1 -1
  201. data/lib/rubocop/cop/style/special_global_vars.rb +14 -14
  202. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -1
  203. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  204. data/lib/rubocop/cop/style/string_methods.rb +10 -5
  205. data/lib/rubocop/cop/style/struct_inheritance.rb +4 -15
  206. data/lib/rubocop/cop/style/symbol_array.rb +31 -35
  207. data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
  208. data/lib/rubocop/cop/style/ternary_parentheses.rb +41 -13
  209. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +6 -9
  210. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -1
  211. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  212. data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -2
  213. data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
  214. data/lib/rubocop/cop/style/word_array.rb +12 -34
  215. data/lib/rubocop/cop/style/zero_length_predicate.rb +11 -4
  216. data/lib/rubocop/cop/team.rb +4 -1
  217. data/lib/rubocop/cop/util.rb +33 -26
  218. data/lib/rubocop/cop/variable_force.rb +13 -13
  219. data/lib/rubocop/cop/variable_force/assignment.rb +1 -8
  220. data/lib/rubocop/cop/variable_force/branch.rb +318 -0
  221. data/lib/rubocop/cop/variable_force/branchable.rb +21 -0
  222. data/lib/rubocop/cop/variable_force/reference.rb +1 -3
  223. data/lib/rubocop/cop/variable_force/scope.rb +36 -20
  224. data/lib/rubocop/cop/variable_force/variable.rb +9 -8
  225. data/lib/rubocop/formatter/colorizable.rb +10 -10
  226. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  227. data/lib/rubocop/formatter/html_formatter.rb +2 -1
  228. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -2
  229. data/lib/rubocop/magic_comment.rb +20 -6
  230. data/lib/rubocop/options.rb +1 -1
  231. data/lib/rubocop/platform.rb +11 -0
  232. data/lib/rubocop/processed_source.rb +1 -1
  233. data/lib/rubocop/remote_config.rb +18 -6
  234. data/lib/rubocop/result_cache.rb +8 -8
  235. data/lib/rubocop/rspec/cop_helper.rb +2 -0
  236. data/lib/rubocop/rspec/shared_contexts.rb +20 -0
  237. data/lib/rubocop/rspec/shared_examples.rb +1 -1
  238. data/lib/rubocop/runner.rb +2 -2
  239. data/lib/rubocop/target_finder.rb +64 -6
  240. data/lib/rubocop/version.rb +2 -4
  241. metadata +27 -4
  242. data/lib/rubocop/cop/variable_force/locatable.rb +0 -200
data/config/disabled.yml CHANGED
@@ -114,11 +114,6 @@ Style/StringMethods:
114
114
  Description: 'Checks if configured preferred methods are used over non-preferred.'
115
115
  Enabled: false
116
116
 
117
- Style/SymbolArray:
118
- Description: 'Use %i or %I for arrays of symbols.'
119
- StyleGuide: '#percent-i'
120
- Enabled: false
121
-
122
117
  Style/SingleLineBlockParams:
123
118
  Description: 'Enforces the names of some block params.'
124
119
  Enabled: false
data/config/enabled.yml CHANGED
@@ -217,26 +217,42 @@ Style/EmptyLineBetweenDefs:
217
217
 
218
218
  Style/EmptyLines:
219
219
  Description: "Don't use several empty lines in a row."
220
+ StyleGuide: '#two-or-more-empty-lines'
220
221
  Enabled: true
221
222
 
222
223
  Style/EmptyLinesAroundAccessModifier:
223
224
  Description: "Keep blank lines around access modifiers."
225
+ StyleGuide: '#empty-lines-around-access-modifier'
226
+ Enabled: true
227
+
228
+ Style/EmptyLinesAroundBeginBody:
229
+ Description: "Keeps track of empty lines around begin-end bodies."
230
+ StyleGuide: '#empty-lines-around-bodies'
224
231
  Enabled: true
225
232
 
226
233
  Style/EmptyLinesAroundBlockBody:
227
234
  Description: "Keeps track of empty lines around block bodies."
235
+ StyleGuide: '#empty-lines-around-bodies'
228
236
  Enabled: true
229
237
 
230
238
  Style/EmptyLinesAroundClassBody:
231
239
  Description: "Keeps track of empty lines around class bodies."
240
+ StyleGuide: '#empty-lines-around-bodies'
241
+ Enabled: true
242
+
243
+ Style/EmptyLinesAroundExceptionHandlingKeywords:
244
+ Description: "Keeps track of empty lines around exception handling keywords."
245
+ StyleGuide: '#empty-lines-around-bodies'
232
246
  Enabled: true
233
247
 
234
248
  Style/EmptyLinesAroundModuleBody:
235
249
  Description: "Keeps track of empty lines around module bodies."
250
+ StyleGuide: '#empty-lines-around-bodies'
236
251
  Enabled: true
237
252
 
238
253
  Style/EmptyLinesAroundMethodBody:
239
254
  Description: "Keeps track of empty lines around method bodies."
255
+ StyleGuide: '#empty-lines-around-bodies'
240
256
  Enabled: true
241
257
 
242
258
  Style/EmptyLiteral:
@@ -374,11 +390,22 @@ Style/IndentHash:
374
390
  Description: 'Checks the indentation of the first key in a hash literal.'
375
391
  Enabled: true
376
392
 
393
+ Style/IndentHeredoc:
394
+ Description: 'This cops checks the indentation of the here document bodies.'
395
+ StyleGuide: '#squiggly-heredocs'
396
+ Enabled: true
397
+
377
398
  Style/InfiniteLoop:
378
399
  Description: 'Use Kernel#loop for infinite loops.'
379
400
  StyleGuide: '#infinite-loop'
380
401
  Enabled: true
381
402
 
403
+ Style/InverseMethods:
404
+ Description: >-
405
+ Use the inverse method instead of `!.method`
406
+ if an inverse method is defined.
407
+ Enabled: true
408
+
382
409
  Style/Lambda:
383
410
  Description: 'Use the new lambda literal syntax for single-line blocks.'
384
411
  StyleGuide: '#lambda-multi-line'
@@ -426,6 +453,11 @@ Style/MethodMissing:
426
453
  StyleGuide: '#no-method-missing'
427
454
  Enabled: true
428
455
 
456
+ Style/MixinGrouping:
457
+ Description: 'Checks for grouping of mixins in `class` and `module` bodies.'
458
+ StyleGuide: '#mixin-grouping'
459
+ Enabled: true
460
+
429
461
  Style/ModuleFunction:
430
462
  Description: 'Checks for usage of `extend self` in modules.'
431
463
  StyleGuide: '#module-function'
@@ -533,6 +565,11 @@ Style/NestedTernaryOperator:
533
565
  StyleGuide: '#no-nested-ternary'
534
566
  Enabled: true
535
567
 
568
+ Style/EmptyLineAfterMagicComment:
569
+ Description: 'Add a newline after magic comments to separate them from code.'
570
+ StyleGuide: '#separate-magic-comments-from-code'
571
+ Enabled: true
572
+
536
573
  Style/Next:
537
574
  Description: 'Use `next` to skip iteration instead of a condition at the end.'
538
575
  StyleGuide: '#no-nested-conditionals'
@@ -855,6 +892,11 @@ Style/StructInheritance:
855
892
  StyleGuide: '#no-extend-struct-new'
856
893
  Enabled: true
857
894
 
895
+ Style/SymbolArray:
896
+ Description: 'Use %i or %I for arrays of symbols.'
897
+ StyleGuide: '#percent-i'
898
+ Enabled: true
899
+
858
900
  Style/SymbolLiteral:
859
901
  Description: 'Use plain symbols instead of string symbols when possible.'
860
902
  Enabled: true
@@ -966,7 +1008,7 @@ Style/ZeroLengthPredicate:
966
1008
  Description: 'Use #empty? when testing for objects of length 0.'
967
1009
  Enabled: true
968
1010
 
969
- #################### Metrics ################################
1011
+ #################### Metrics ###############################
970
1012
 
971
1013
  Metrics/AbcSize:
972
1014
  Description: >-
@@ -1019,9 +1061,16 @@ Metrics/PerceivedComplexity:
1019
1061
  human reader.
1020
1062
  Enabled: true
1021
1063
 
1022
- #################### Lint ################################
1064
+ #################### Lint ##################################
1023
1065
  ### Warnings
1024
1066
 
1067
+ Lint/AmbiguousBlockAssociation:
1068
+ Description: >-
1069
+ Checks for ambiguous block association with method when param passed without
1070
+ parentheses.
1071
+ StyleGuide: '#syntax'
1072
+ Enabled: true
1073
+
1025
1074
  Lint/AmbiguousOperator:
1026
1075
  Description: >-
1027
1076
  Checks for ambiguous operators in the first argument of a
@@ -1090,6 +1139,7 @@ Lint/ElseLayout:
1090
1139
  Lint/EmptyEnsure:
1091
1140
  Description: 'Checks for empty ensure block.'
1092
1141
  Enabled: true
1142
+ AutoCorrect: false
1093
1143
 
1094
1144
  Lint/EmptyExpression:
1095
1145
  Description: 'Checks for empty expressions.'
@@ -1302,7 +1352,7 @@ Lint/Void:
1302
1352
  Description: 'Possible use of operator/literal/variable in void context.'
1303
1353
  Enabled: true
1304
1354
 
1305
- ##################### Performance #############################
1355
+ #################### Performance ###########################
1306
1356
 
1307
1357
  Performance/Casecmp:
1308
1358
  Description: >-
@@ -1410,7 +1460,9 @@ Performance/RedundantSortBy:
1410
1460
  Enabled: true
1411
1461
 
1412
1462
  Performance/RegexpMatch:
1413
- Description: 'Use `match?` instead of `Regexp#match`, `String#match`, `Symbol#match`, `Regexp#===` or `=~` when `MatchData` is not used.'
1463
+ Description: >-
1464
+ Use `match?` instead of `Regexp#match`, `String#match`, `Symbol#match`,
1465
+ `Regexp#===`, or `=~` when `MatchData` is not used.
1414
1466
  Enabled: true
1415
1467
 
1416
1468
  Performance/ReverseEach:
@@ -1457,12 +1509,29 @@ Performance/TimesMap:
1457
1509
  Description: 'Checks for .times.map calls.'
1458
1510
  Enabled: true
1459
1511
 
1460
- ##################### Rails ##################################
1512
+ #################### Rails #################################
1461
1513
 
1462
1514
  Rails/ActionFilter:
1463
1515
  Description: 'Enforces consistent use of action filter methods.'
1464
1516
  Enabled: true
1465
1517
 
1518
+ Rails/ActiveSupportAliases:
1519
+ Description: >-
1520
+ Avoid ActiveSupport aliases of standard ruby methods:
1521
+ `String#starts_with?`, `String#ends_with?`,
1522
+ `Array#append`, `Array#prepend`.
1523
+ Enabled: true
1524
+
1525
+ Rails/Blank:
1526
+ Description: 'Enforce using `blank?` and `present?`.'
1527
+ Enabled: true
1528
+ # Convert checks for `nil` or `empty?` to `blank?`
1529
+ NilOrEmpty: true
1530
+ # Convert usages of not `present?` to `blank?`
1531
+ NotPresent: true
1532
+ # Convert usages of `unless` `present?` to `if` `blank?`
1533
+ UnlessPresent: true
1534
+
1466
1535
  Rails/Date:
1467
1536
  Description: >-
1468
1537
  Checks the correct usage of date aware methods,
@@ -1535,6 +1604,16 @@ Rails/PluralizationGrammar:
1535
1604
  Description: 'Checks for incorrect grammar when using methods like `3.day.ago`.'
1536
1605
  Enabled: true
1537
1606
 
1607
+ Rails/Present:
1608
+ Description: 'Enforce using `blank?` and `present?`.'
1609
+ Enabled: true
1610
+ NotNilAndNotEmpty: true
1611
+ # Convert checks for not `nil` and not `empty?` to `present?`
1612
+ NotBlank: true
1613
+ # Convert usages of not `blank?` to `present?`
1614
+ UnlessBlank: true
1615
+ # Convert usages of `unless` `blank?` to `if` `present?`
1616
+
1538
1617
  Rails/ReadWriteAttribute:
1539
1618
  Description: >-
1540
1619
  Checks for read_attribute(:attr) and
@@ -1542,6 +1621,10 @@ Rails/ReadWriteAttribute:
1542
1621
  StyleGuide: 'https://github.com/bbatsov/rails-style-guide#read-attribute'
1543
1622
  Enabled: true
1544
1623
 
1624
+ Rails/RelativeDateConstant:
1625
+ Description: 'Do not assign relative date to constants.'
1626
+ Enabled: true
1627
+
1545
1628
  Rails/RequestReferer:
1546
1629
  Description: 'Use consistent syntax for request.referer.'
1547
1630
  Enabled: true
@@ -1581,6 +1664,8 @@ Rails/Validation:
1581
1664
  Description: 'Use validates :attribute, hash of validations.'
1582
1665
  Enabled: true
1583
1666
 
1667
+ #################### Security ##############################
1668
+
1584
1669
  Security/Eval:
1585
1670
  Description: 'The use of eval represents a serious security risk.'
1586
1671
  Enabled: true
@@ -1609,7 +1694,7 @@ Security/YAMLLoad:
1609
1694
  Reference: 'https://ruby-doc.org/stdlib-2.3.3/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
1610
1695
  Enabled: true
1611
1696
 
1612
- ##################### Bundler #############################
1697
+ #################### Bundler ###############################
1613
1698
 
1614
1699
  Bundler/DuplicatedGem:
1615
1700
  Description: 'Checks for duplicate gem entries in Gemfile.'
@@ -1620,8 +1705,7 @@ Bundler/DuplicatedGem:
1620
1705
 
1621
1706
  Bundler/OrderedGems:
1622
1707
  Description: >-
1623
- Sort alphabetically gems appearing within a contiguous set
1624
- of lines in the Gemfile
1708
+ Gems within groups in the Gemfile should be alphabetically sorted.
1625
1709
  Enabled: true
1626
1710
  Include:
1627
1711
  - '**/Gemfile'
data/lib/rubocop.rb CHANGED
@@ -15,22 +15,30 @@ require 'unicode/display_width'
15
15
  require 'rubocop/version'
16
16
 
17
17
  require 'rubocop/path_util'
18
+ require 'rubocop/platform'
18
19
  require 'rubocop/string_util'
19
20
  require 'rubocop/name_similarity'
20
21
  require 'rubocop/node_pattern'
21
22
  require 'rubocop/string_interpreter'
22
23
  require 'rubocop/ast/sexp'
23
24
  require 'rubocop/ast/node'
25
+ require 'rubocop/ast/node/mixin/binary_operator_node'
24
26
  require 'rubocop/ast/node/mixin/conditional_node'
25
27
  require 'rubocop/ast/node/mixin/hash_element_node'
26
28
  require 'rubocop/ast/node/mixin/modifier_node'
29
+ require 'rubocop/ast/node/mixin/predicate_operator_node'
30
+ require 'rubocop/ast/node/and_node'
27
31
  require 'rubocop/ast/node/array_node'
28
32
  require 'rubocop/ast/node/case_node'
33
+ require 'rubocop/ast/node/ensure_node'
29
34
  require 'rubocop/ast/node/for_node'
30
35
  require 'rubocop/ast/node/hash_node'
31
36
  require 'rubocop/ast/node/if_node'
32
37
  require 'rubocop/ast/node/keyword_splat_node'
38
+ require 'rubocop/ast/node/or_node'
33
39
  require 'rubocop/ast/node/pair_node'
40
+ require 'rubocop/ast/node/resbody_node'
41
+ require 'rubocop/ast/node/send_node'
34
42
  require 'rubocop/ast/node/until_node'
35
43
  require 'rubocop/ast/node/when_node'
36
44
  require 'rubocop/ast/node/while_node'
@@ -53,7 +61,8 @@ require 'rubocop/cop/force'
53
61
  require 'rubocop/cop/severity'
54
62
 
55
63
  require 'rubocop/cop/variable_force'
56
- require 'rubocop/cop/variable_force/locatable'
64
+ require 'rubocop/cop/variable_force/branch'
65
+ require 'rubocop/cop/variable_force/branchable'
57
66
  require 'rubocop/cop/variable_force/variable'
58
67
  require 'rubocop/cop/variable_force/assignment'
59
68
  require 'rubocop/cop/variable_force/reference'
@@ -81,6 +90,7 @@ require 'rubocop/cop/mixin/end_keyword_alignment'
81
90
  require 'rubocop/cop/mixin/first_element_line_break'
82
91
  require 'rubocop/cop/mixin/frozen_string_literal'
83
92
  require 'rubocop/cop/mixin/hash_alignment'
93
+ require 'rubocop/cop/mixin/ignored_pattern'
84
94
  require 'rubocop/cop/mixin/integer_node'
85
95
  require 'rubocop/cop/mixin/on_method_def'
86
96
  require 'rubocop/cop/mixin/match_range'
@@ -95,6 +105,7 @@ require 'rubocop/cop/mixin/parentheses'
95
105
  require 'rubocop/cop/mixin/parser_diagnostic'
96
106
  require 'rubocop/cop/mixin/percent_literal'
97
107
  require 'rubocop/cop/mixin/preceding_following_alignment'
108
+ require 'rubocop/cop/mixin/rescue_node'
98
109
  require 'rubocop/cop/mixin/safe_assignment'
99
110
  require 'rubocop/cop/mixin/safe_mode'
100
111
  require 'rubocop/cop/mixin/space_after_punctuation'
@@ -105,6 +116,7 @@ require 'rubocop/cop/mixin/statement_modifier'
105
116
  require 'rubocop/cop/mixin/string_help'
106
117
  require 'rubocop/cop/mixin/string_literals_help'
107
118
  require 'rubocop/cop/mixin/target_ruby_version'
119
+ require 'rubocop/cop/mixin/target_rails_version'
108
120
  require 'rubocop/cop/mixin/too_many_lines'
109
121
  require 'rubocop/cop/mixin/trailing_comma'
110
122
  require 'rubocop/cop/mixin/unused_argument'
@@ -112,6 +124,7 @@ require 'rubocop/cop/mixin/unused_argument'
112
124
  require 'rubocop/cop/bundler/duplicated_gem'
113
125
  require 'rubocop/cop/bundler/ordered_gems'
114
126
 
127
+ require 'rubocop/cop/lint/ambiguous_block_association'
115
128
  require 'rubocop/cop/lint/ambiguous_operator'
116
129
  require 'rubocop/cop/lint/ambiguous_regexp_literal'
117
130
  require 'rubocop/cop/lint/assignment_in_condition'
@@ -253,11 +266,14 @@ require 'rubocop/cop/style/each_with_object'
253
266
  require 'rubocop/cop/style/else_alignment'
254
267
  require 'rubocop/cop/style/empty_case_condition'
255
268
  require 'rubocop/cop/style/empty_else'
269
+ require 'rubocop/cop/style/empty_line_after_magic_comment'
256
270
  require 'rubocop/cop/style/empty_line_between_defs'
257
271
  require 'rubocop/cop/style/empty_lines'
258
272
  require 'rubocop/cop/style/empty_lines_around_access_modifier'
273
+ require 'rubocop/cop/style/empty_lines_around_begin_body'
259
274
  require 'rubocop/cop/style/empty_lines_around_block_body'
260
275
  require 'rubocop/cop/style/empty_lines_around_class_body'
276
+ require 'rubocop/cop/style/empty_lines_around_exception_handling_keywords'
261
277
  require 'rubocop/cop/style/empty_lines_around_method_body'
262
278
  require 'rubocop/cop/style/empty_lines_around_module_body'
263
279
  require 'rubocop/cop/style/empty_literal'
@@ -289,9 +305,11 @@ require 'rubocop/cop/style/implicit_runtime_error'
289
305
  require 'rubocop/cop/style/indent_array'
290
306
  require 'rubocop/cop/style/indent_assignment'
291
307
  require 'rubocop/cop/style/indent_hash'
308
+ require 'rubocop/cop/style/indent_heredoc'
292
309
  require 'rubocop/cop/style/indentation_consistency'
293
310
  require 'rubocop/cop/style/indentation_width'
294
311
  require 'rubocop/cop/style/infinite_loop'
312
+ require 'rubocop/cop/style/inverse_methods'
295
313
  require 'rubocop/cop/style/initial_indentation'
296
314
  require 'rubocop/cop/style/inline_comment'
297
315
  require 'rubocop/cop/style/lambda'
@@ -305,6 +323,7 @@ require 'rubocop/cop/style/method_def_parentheses'
305
323
  require 'rubocop/cop/style/method_name'
306
324
  require 'rubocop/cop/style/method_missing'
307
325
  require 'rubocop/cop/style/missing_else'
326
+ require 'rubocop/cop/style/mixin_grouping'
308
327
  require 'rubocop/cop/style/module_function'
309
328
  require 'rubocop/cop/style/multiline_array_brace_layout'
310
329
  require 'rubocop/cop/style/multiline_assignment_layout'
@@ -414,6 +433,8 @@ require 'rubocop/cop/style/word_array'
414
433
  require 'rubocop/cop/style/zero_length_predicate'
415
434
 
416
435
  require 'rubocop/cop/rails/action_filter'
436
+ require 'rubocop/cop/rails/active_support_aliases'
437
+ require 'rubocop/cop/rails/blank'
417
438
  require 'rubocop/cop/rails/date'
418
439
  require 'rubocop/cop/rails/dynamic_find_by'
419
440
  require 'rubocop/cop/rails/delegate'
@@ -429,9 +450,11 @@ require 'rubocop/cop/rails/not_null_column'
429
450
  require 'rubocop/cop/rails/output_safety'
430
451
  require 'rubocop/cop/rails/output'
431
452
  require 'rubocop/cop/rails/pluralization_grammar'
453
+ require 'rubocop/cop/rails/present'
432
454
  require 'rubocop/cop/rails/read_write_attribute'
433
455
  require 'rubocop/cop/rails/request_referer'
434
456
  require 'rubocop/cop/rails/reversible_migration'
457
+ require 'rubocop/cop/rails/relative_date_constant'
435
458
  require 'rubocop/cop/rails/safe_navigation'
436
459
  require 'rubocop/cop/rails/save_bang'
437
460
  require 'rubocop/cop/rails/scope_args'
@@ -14,16 +14,21 @@ module RuboCop
14
14
  # root_node = parser.parse(buffer)
15
15
  class Builder < Parser::Builders::Default
16
16
  NODE_MAP = {
17
+ AndNode => [:and],
17
18
  ArrayNode => [:array],
18
19
  CaseNode => [:case],
20
+ EnsureNode => [:ensure],
19
21
  ForNode => [:for],
20
22
  HashNode => [:hash],
21
23
  IfNode => [:if],
22
24
  KeywordSplatNode => [:kwsplat],
25
+ OrNode => [:or],
23
26
  PairNode => [:pair],
24
- UntilNode => [:until, :until_post],
27
+ ResbodyNode => [:resbody],
28
+ SendNode => [:send],
29
+ UntilNode => %i(until until_post),
25
30
  WhenNode => [:when],
26
- WhileNode => [:while, :while_post]
31
+ WhileNode => %i(while while_post)
27
32
  }.freeze
28
33
 
29
34
  # Generates {Node} from the given information.
@@ -21,27 +21,27 @@ module RuboCop
21
21
  class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
22
22
  include RuboCop::AST::Sexp
23
23
 
24
- COMPARISON_OPERATORS = [:!, :==, :===, :!=, :<=, :>=, :>, :<, :<=>].freeze
24
+ COMPARISON_OPERATORS = %i(! == === != <= >= > < <=>).freeze
25
25
 
26
- TRUTHY_LITERALS = [:str, :dstr, :xstr, :int, :float, :sym, :dsym, :array,
27
- :hash, :regexp, :true, :irange, :erange, :complex,
28
- :rational, :regopt].freeze
29
- FALSEY_LITERALS = [:false, :nil].freeze
26
+ TRUTHY_LITERALS = %i(str dstr xstr int float sym dsym array
27
+ hash regexp true irange erange complex
28
+ rational regopt).freeze
29
+ FALSEY_LITERALS = %i(false nil).freeze
30
30
  LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
31
- COMPOSITE_LITERALS = [:dstr, :xstr, :dsym, :array, :hash, :irange,
32
- :erange, :regexp].freeze
31
+ COMPOSITE_LITERALS = %i(dstr xstr dsym array hash irange
32
+ erange regexp).freeze
33
33
  BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
34
- MUTABLE_LITERALS = [:str, :dstr, :xstr, :array, :hash].freeze
34
+ MUTABLE_LITERALS = %i(str dstr xstr array hash).freeze
35
35
  IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
36
36
 
37
- VARIABLES = [:ivar, :gvar, :cvar, :lvar].freeze
38
- REFERENCES = [:nth_ref, :back_ref].freeze
39
- KEYWORDS = [:alias, :and, :break, :case, :class, :def, :defs, :defined?,
40
- :kwbegin, :do, :else, :ensure, :for, :if, :module, :next,
41
- :not, :or, :postexe, :redo, :rescue, :retry, :return, :self,
42
- :super, :zsuper, :then, :undef, :until, :when, :while,
43
- :yield].freeze
44
- OPERATOR_KEYWORDS = [:and, :or].freeze
37
+ VARIABLES = %i(ivar gvar cvar lvar).freeze
38
+ REFERENCES = %i(nth_ref back_ref).freeze
39
+ KEYWORDS = %i(alias and break case class def defs defined?
40
+ kwbegin do else ensure for if module next
41
+ not or postexe redo rescue retry return self
42
+ super zsuper then undef until when while
43
+ yield).freeze
44
+ OPERATOR_KEYWORDS = %i(and or).freeze
45
45
  SPECIAL_KEYWORDS = %w(__FILE__ __LINE__ __ENCODING__).freeze
46
46
 
47
47
  # def_matcher can be used to define a pattern-matching method on Node
@@ -110,7 +110,7 @@ module RuboCop
110
110
  # part of it is changed.
111
111
  def updated(type = nil, children = nil, properties = {})
112
112
  properties[:location] ||= @location
113
- Node.new(type || @type, children || @children, properties)
113
+ self.class.new(type || @type, children || @children, properties)
114
114
  end
115
115
 
116
116
  # Returns the index of the receiver node in its siblings. (Sibling index
@@ -361,7 +361,7 @@ module RuboCop
361
361
  IMMUTABLE_LITERALS.include?(type)
362
362
  end
363
363
 
364
- [:literal, :basic_literal].each do |kind|
364
+ %i(literal basic_literal).each do |kind|
365
365
  recursive_kind = :"recursive_#{kind}?"
366
366
  kind_filter = :"#{kind}?"
367
367
  define_method(recursive_kind) do
@@ -398,6 +398,10 @@ module RuboCop
398
398
  SPECIAL_KEYWORDS.include?(source)
399
399
  end
400
400
 
401
+ def operator_keyword?
402
+ OPERATOR_KEYWORDS.include?(type)
403
+ end
404
+
401
405
  def keyword_not?
402
406
  _receiver, method_name, *args = *self
403
407
  args.empty? && method_name == :! && loc.selector.is?('not'.freeze)
@@ -439,8 +443,7 @@ module RuboCop
439
443
  [{(send nil {:raise :fail} ...) return break next} single_line?]
440
444
  PATTERN
441
445
 
442
- def_matcher :command?, '(send nil %1 ...)'
443
- def_matcher :lambda?, '(block (send nil :lambda) ...)'
446
+ def_matcher :lambda?, '(block (send nil :lambda) ...)'
444
447
  def_matcher :proc?, <<-PATTERN
445
448
  {(block (send nil :proc) ...)
446
449
  (block (send (const nil :Proc) :new) ...)