rubocop 0.83.0 → 0.84.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +20 -3
  4. data/lib/rubocop.rb +6 -59
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  7. data/lib/rubocop/config.rb +1 -3
  8. data/lib/rubocop/config_loader.rb +3 -9
  9. data/lib/rubocop/config_loader_resolver.rb +2 -6
  10. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  11. data/lib/rubocop/cop/corrector.rb +1 -3
  12. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
  13. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -3
  14. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  15. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  16. data/lib/rubocop/cop/generator.rb +1 -1
  17. data/lib/rubocop/cop/ignored_node.rb +1 -3
  18. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  19. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +62 -4
  20. data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
  21. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
  22. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  23. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -6
  24. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  25. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -3
  26. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  27. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -6
  28. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  29. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
  30. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
  31. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -2
  32. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
  33. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -6
  34. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +11 -3
  35. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -3
  36. data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -1
  37. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  38. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -3
  39. data/lib/rubocop/cop/migration/department_name.rb +5 -9
  40. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  41. data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
  42. data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
  43. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  44. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
  45. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -3
  46. data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -3
  47. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -3
  48. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  49. data/lib/rubocop/cop/registry.rb +2 -6
  50. data/lib/rubocop/cop/severity.rb +1 -3
  51. data/lib/rubocop/cop/style/and_or.rb +2 -2
  52. data/lib/rubocop/cop/style/attr.rb +1 -3
  53. data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -3
  55. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  56. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  57. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -4
  58. data/lib/rubocop/cop/style/hash_syntax.rb +12 -5
  59. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  60. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  61. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
  62. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
  63. data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
  64. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  65. data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
  66. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -3
  67. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -6
  68. data/lib/rubocop/cop/variable_force.rb +3 -9
  69. data/lib/rubocop/cop/variable_force/branch.rb +2 -6
  70. data/lib/rubocop/cop/variable_force/variable.rb +2 -6
  71. data/lib/rubocop/ext/processed_source.rb +18 -0
  72. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  73. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
  74. data/lib/rubocop/formatter/formatter_set.rb +1 -3
  75. data/lib/rubocop/options.rb +2 -8
  76. data/lib/rubocop/remote_config.rb +1 -3
  77. data/lib/rubocop/result_cache.rb +1 -3
  78. data/lib/rubocop/rspec/cop_helper.rb +1 -3
  79. data/lib/rubocop/rspec/expect_offense.rb +3 -9
  80. data/lib/rubocop/rspec/shared_contexts.rb +54 -16
  81. data/lib/rubocop/runner.rb +8 -10
  82. data/lib/rubocop/target_finder.rb +2 -6
  83. data/lib/rubocop/version.rb +5 -3
  84. metadata +19 -56
  85. data/lib/rubocop/ast/builder.rb +0 -85
  86. data/lib/rubocop/ast/node.rb +0 -637
  87. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  88. data/lib/rubocop/ast/node/and_node.rb +0 -29
  89. data/lib/rubocop/ast/node/args_node.rb +0 -29
  90. data/lib/rubocop/ast/node/array_node.rb +0 -70
  91. data/lib/rubocop/ast/node/block_node.rb +0 -121
  92. data/lib/rubocop/ast/node/break_node.rb +0 -17
  93. data/lib/rubocop/ast/node/case_match_node.rb +0 -56
  94. data/lib/rubocop/ast/node/case_node.rb +0 -56
  95. data/lib/rubocop/ast/node/class_node.rb +0 -31
  96. data/lib/rubocop/ast/node/def_node.rb +0 -82
  97. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  98. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  99. data/lib/rubocop/ast/node/float_node.rb +0 -12
  100. data/lib/rubocop/ast/node/for_node.rb +0 -53
  101. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  102. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  103. data/lib/rubocop/ast/node/if_node.rb +0 -175
  104. data/lib/rubocop/ast/node/int_node.rb +0 -12
  105. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  106. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  107. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  108. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  109. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  110. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  111. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
  112. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  113. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  114. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  115. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  116. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  117. data/lib/rubocop/ast/node/module_node.rb +0 -24
  118. data/lib/rubocop/ast/node/or_node.rb +0 -29
  119. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  120. data/lib/rubocop/ast/node/range_node.rb +0 -18
  121. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  122. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  123. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  124. data/lib/rubocop/ast/node/return_node.rb +0 -24
  125. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  126. data/lib/rubocop/ast/node/send_node.rb +0 -17
  127. data/lib/rubocop/ast/node/str_node.rb +0 -16
  128. data/lib/rubocop/ast/node/super_node.rb +0 -21
  129. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  130. data/lib/rubocop/ast/node/until_node.rb +0 -35
  131. data/lib/rubocop/ast/node/when_node.rb +0 -53
  132. data/lib/rubocop/ast/node/while_node.rb +0 -35
  133. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  134. data/lib/rubocop/ast/sexp.rb +0 -16
  135. data/lib/rubocop/ast/traversal.rb +0 -202
  136. data/lib/rubocop/node_pattern.rb +0 -887
  137. data/lib/rubocop/processed_source.rb +0 -213
  138. data/lib/rubocop/token.rb +0 -114
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02ede8c9af1fb47b66ac79a0d93d577a5384f82f5076e1e64631ca761c4d3f6b
4
- data.tar.gz: 2f22e7716a7068013b131636217a77189f2ca506e53c8613c407c18f8028600e
3
+ metadata.gz: 92b169f3f7a5c04a2ce3b9b674328a49e078a8f19b5560e5135eee1ddb4f0428
4
+ data.tar.gz: 6057deda8dd47bbf92038a03ce0bd4d35139c220f5fede6049f5e3da9fcc7ad0
5
5
  SHA512:
6
- metadata.gz: 936fdee12ea43542b66ab1cccc0514f1a7076dbd671386cccf376e61633b12e51c88feba3e652e77c925a2f5df4e0646bf568af453032bd2cb6eafdd9ea66d48
7
- data.tar.gz: 23ec3628be52fd219206cd866c7e46757cdae9c8bd5c29334a7471c856f19becb03af7da2dd6f12a12c1f876f4eb900d10f9c8fdd7ad669c1bf2dea4cb333145
6
+ metadata.gz: 073154f4f62eed603c4b4d947b5dcdc308d1f0aebcffe11daad2b0d21820272f9d13d89e40403292a5497d6d9722e405f9f6cb16071c69214fc10a074eef5254
7
+ data.tar.gz: 69c0e58d557d71c898cf6c43bed3fb6a5df83650e239e470bf0bb56cf4a2722895f2c8b9fb36775e752a2dafc80893f719166e204a4d5f136c82c0f6a03bc321
data/README.md CHANGED
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
53
53
  might want to use a conservative version lock in your `Gemfile`:
54
54
 
55
55
  ```rb
56
- gem 'rubocop', '~> 0.83.0', require: false
56
+ gem 'rubocop', '~> 0.84.0', require: false
57
57
  ```
58
58
 
59
59
  ## Quickstart
@@ -132,7 +132,7 @@ If you're working in a company that's making significant use of RuboCop we'd app
132
132
  to become a RuboCop sponsor.
133
133
 
134
134
  You can support the development of RuboCop via
135
- [Salt](https://salt.bountysource.com/teams/rubocop),
135
+ [GitHub Sponsors](https://github.com/sponsors/bbatsov),
136
136
  [Patreon](https://www.patreon.com/bbatsov),
137
137
  [PayPal](https://paypal.me/bbatsov)
138
138
  and [Open Collective](https://opencollective.com/rubocop).
@@ -468,6 +468,13 @@ Layout/EmptyLinesAroundAttributeAccessor:
468
468
  StyleGuide: '#empty-lines-around-attribute-accessor'
469
469
  Enabled: pending
470
470
  VersionAdded: '0.83'
471
+ VersionChanged: '0.84'
472
+ AllowAliasSyntax: true
473
+ AllowedMethods:
474
+ - alias_method
475
+ - public
476
+ - protected
477
+ - private
471
478
 
472
479
  Layout/EmptyLinesAroundBeginBody:
473
480
  Description: "Keeps track of empty lines around begin-end bodies."
@@ -861,9 +868,9 @@ Layout/LineLength:
861
868
  StyleGuide: '#80-character-limits'
862
869
  Enabled: true
863
870
  VersionAdded: '0.25'
864
- VersionChanged: '0.78'
871
+ VersionChanged: '0.84'
865
872
  AutoCorrect: false
866
- Max: 80
873
+ Max: 120
867
874
  # To make it possible to copy or click on URIs in the code, we allow lines
868
875
  # containing a URI to be longer than Max.
869
876
  AllowHeredoc: true
@@ -1370,6 +1377,11 @@ Lint/DeprecatedClassMethods:
1370
1377
  Enabled: true
1371
1378
  VersionAdded: '0.19'
1372
1379
 
1380
+ Lint/DeprecatedOpenSSLConstant:
1381
+ Description: "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`."
1382
+ Enabled: pending
1383
+ VersionAdded: '0.84'
1384
+
1373
1385
  Lint/DisjunctiveAssignmentInConstructor:
1374
1386
  Description: 'In constructor, plain assignment is preferred over disjunctive.'
1375
1387
  Enabled: true
@@ -2274,7 +2286,7 @@ Style/AndOr:
2274
2286
  VersionChanged: '0.25'
2275
2287
  # Whether `and` and `or` are banned only in conditionals (conditionals)
2276
2288
  # or completely (always).
2277
- EnforcedStyle: always
2289
+ EnforcedStyle: conditionals
2278
2290
  SupportedStyles:
2279
2291
  - always
2280
2292
  - conditionals
@@ -2694,6 +2706,11 @@ Style/DoubleNegation:
2694
2706
  StyleGuide: '#no-bang-bang'
2695
2707
  Enabled: true
2696
2708
  VersionAdded: '0.19'
2709
+ VersionChanged: '0.84'
2710
+ EnforcedStyle: allowed_in_returns
2711
+ SupportedStyles:
2712
+ - allowed_in_returns
2713
+ - forbidden
2697
2714
 
2698
2715
  Style/EachForSimpleLoop:
2699
2716
  Description: >-
@@ -1,73 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser'
4
3
  require 'rainbow'
5
4
 
6
5
  require 'English'
7
6
  require 'set'
8
- require 'forwardable'
9
7
  require 'unicode/display_width/no_string_ext'
8
+ require 'rubocop-ast'
9
+ require_relative 'rubocop/ast_aliases'
10
10
 
11
11
  require_relative 'rubocop/version'
12
12
 
13
13
  require_relative 'rubocop/core_ext/string'
14
+ require_relative 'rubocop/ext/processed_source'
15
+
14
16
  require_relative 'rubocop/path_util'
15
17
  require_relative 'rubocop/file_finder'
16
18
  require_relative 'rubocop/platform'
17
19
  require_relative 'rubocop/name_similarity'
18
- require_relative 'rubocop/node_pattern'
19
20
  require_relative 'rubocop/string_interpreter'
20
- require_relative 'rubocop/ast/sexp'
21
- require_relative 'rubocop/ast/node'
22
- require_relative 'rubocop/ast/node/mixin/method_identifier_predicates'
23
- require_relative 'rubocop/ast/node/mixin/binary_operator_node'
24
- require_relative 'rubocop/ast/node/mixin/collection_node'
25
- require_relative 'rubocop/ast/node/mixin/conditional_node'
26
- require_relative 'rubocop/ast/node/mixin/hash_element_node'
27
- require_relative 'rubocop/ast/node/mixin/method_dispatch_node'
28
- require_relative 'rubocop/ast/node/mixin/modifier_node'
29
- require_relative 'rubocop/ast/node/mixin/numeric_node'
30
- require_relative 'rubocop/ast/node/mixin/parameterized_node'
31
- require_relative 'rubocop/ast/node/mixin/predicate_operator_node'
32
- require_relative 'rubocop/ast/node/mixin/basic_literal_node'
33
- require_relative 'rubocop/ast/node/alias_node'
34
- require_relative 'rubocop/ast/node/and_node'
35
- require_relative 'rubocop/ast/node/args_node'
36
- require_relative 'rubocop/ast/node/array_node'
37
- require_relative 'rubocop/ast/node/block_node'
38
- require_relative 'rubocop/ast/node/break_node'
39
- require_relative 'rubocop/ast/node/case_match_node'
40
- require_relative 'rubocop/ast/node/case_node'
41
- require_relative 'rubocop/ast/node/class_node'
42
- require_relative 'rubocop/ast/node/def_node'
43
- require_relative 'rubocop/ast/node/defined_node'
44
- require_relative 'rubocop/ast/node/ensure_node'
45
- require_relative 'rubocop/ast/node/for_node'
46
- require_relative 'rubocop/ast/node/forward_args_node'
47
- require_relative 'rubocop/ast/node/float_node'
48
- require_relative 'rubocop/ast/node/hash_node'
49
- require_relative 'rubocop/ast/node/if_node'
50
- require_relative 'rubocop/ast/node/int_node'
51
- require_relative 'rubocop/ast/node/keyword_splat_node'
52
- require_relative 'rubocop/ast/node/module_node'
53
- require_relative 'rubocop/ast/node/or_node'
54
- require_relative 'rubocop/ast/node/pair_node'
55
- require_relative 'rubocop/ast/node/range_node'
56
- require_relative 'rubocop/ast/node/regexp_node'
57
- require_relative 'rubocop/ast/node/resbody_node'
58
- require_relative 'rubocop/ast/node/retry_node'
59
- require_relative 'rubocop/ast/node/return_node'
60
- require_relative 'rubocop/ast/node/self_class_node'
61
- require_relative 'rubocop/ast/node/send_node'
62
- require_relative 'rubocop/ast/node/str_node'
63
- require_relative 'rubocop/ast/node/super_node'
64
- require_relative 'rubocop/ast/node/symbol_node'
65
- require_relative 'rubocop/ast/node/until_node'
66
- require_relative 'rubocop/ast/node/when_node'
67
- require_relative 'rubocop/ast/node/while_node'
68
- require_relative 'rubocop/ast/node/yield_node'
69
- require_relative 'rubocop/ast/builder'
70
- require_relative 'rubocop/ast/traversal'
71
21
  require_relative 'rubocop/error'
72
22
  require_relative 'rubocop/warning'
73
23
 
@@ -216,7 +166,7 @@ require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
216
166
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
217
167
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
218
168
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
219
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
169
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
220
170
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
221
171
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
222
172
  require_relative 'rubocop/cop/layout/empty_lines'
@@ -291,6 +241,7 @@ require_relative 'rubocop/cop/lint/boolean_symbol'
291
241
  require_relative 'rubocop/cop/lint/circular_argument_reference'
292
242
  require_relative 'rubocop/cop/lint/debugger'
293
243
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
244
+ require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
294
245
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
295
246
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
296
247
  require_relative 'rubocop/cop/lint/duplicate_hash_key'
@@ -468,11 +419,9 @@ require_relative 'rubocop/cop/style/lambda'
468
419
  require_relative 'rubocop/cop/style/lambda_call'
469
420
  require_relative 'rubocop/cop/style/line_end_concatenation'
470
421
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
471
- # rubocop:disable Layout/LineLength
472
422
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
473
423
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
474
424
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
475
- # rubocop:enable Layout/LineLength
476
425
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
477
426
  require_relative 'rubocop/cop/style/method_def_parentheses'
478
427
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -614,10 +563,8 @@ require_relative 'rubocop/config_obsoletion'
614
563
  require_relative 'rubocop/config_store'
615
564
  require_relative 'rubocop/config_validator'
616
565
  require_relative 'rubocop/target_finder'
617
- require_relative 'rubocop/token'
618
566
  require_relative 'rubocop/comment_config'
619
567
  require_relative 'rubocop/magic_comment'
620
- require_relative 'rubocop/processed_source'
621
568
  require_relative 'rubocop/result_cache'
622
569
  require_relative 'rubocop/runner'
623
570
  require_relative 'rubocop/cli'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These aliases are for compatibility.
4
+ module RuboCop
5
+ NodePattern = AST::NodePattern
6
+ ProcessedSource = AST::ProcessedSource
7
+ Token = AST::Token
8
+ end
@@ -42,18 +42,14 @@ module RuboCop
42
42
  selected_cops_of_department(registry, department)
43
43
  end
44
44
 
45
- if show_all
46
- puts "# Department '#{department}' (#{selected_cops.length}):"
47
- end
45
+ puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
48
46
 
49
47
  print_cop_details(selected_cops)
50
48
  end
51
49
 
52
50
  def print_cop_details(cops)
53
51
  cops.each do |cop|
54
- if cop.new(@config).support_autocorrect?
55
- puts '# Supports --auto-correct'
56
- end
52
+ puts '# Supports --auto-correct' if cop.new(@config).support_autocorrect?
57
53
  puts "#{cop.cop_name}:"
58
54
  puts config_lines(cop)
59
55
  puts
@@ -86,9 +86,7 @@ module RuboCop
86
86
 
87
87
  excludes = for_all_cops['Exclude'] ||= []
88
88
  highest_config.for_all_cops['Exclude'].each do |path|
89
- unless path.is_a?(Regexp) || absolute?(path)
90
- path = File.join(File.dirname(highest_config.loaded_path), path)
91
- end
89
+ path = File.join(File.dirname(highest_config.loaded_path), path) unless path.is_a?(Regexp) || absolute?(path)
92
90
  excludes << path unless excludes.include?(path)
93
91
  end
94
92
  end
@@ -95,9 +95,7 @@ module RuboCop
95
95
  end
96
96
 
97
97
  merge_with_default(config, config_file).tap do |merged_config|
98
- unless possible_new_cops?(config)
99
- warn_on_pending_cops(merged_config.pending_cops)
100
- end
98
+ warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
101
99
  end
102
100
  end
103
101
 
@@ -207,9 +205,7 @@ module RuboCop
207
205
  def write_config_file(file_name, file_string, rubocop_yml_contents)
208
206
  File.open(file_name, 'w') do |f|
209
207
  f.write "inherit_from:#{file_string}\n"
210
- if /\S/.match?(rubocop_yml_contents)
211
- f.write "\n#{rubocop_yml_contents}"
212
- end
208
+ f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
213
209
  end
214
210
  end
215
211
 
@@ -227,9 +223,7 @@ module RuboCop
227
223
 
228
224
  puts "configuration from #{absolute_path}" if debug?
229
225
 
230
- unless hash.is_a?(Hash)
231
- raise(TypeError, "Malformed configuration in #{absolute_path}")
232
- end
226
+ raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
233
227
 
234
228
  hash
235
229
  end
@@ -71,9 +71,7 @@ module RuboCop
71
71
  end
72
72
  end
73
73
 
74
- if disabled_by_default
75
- config = handle_disabled_by_default(config, default_configuration)
76
- end
74
+ config = handle_disabled_by_default(config, default_configuration) if disabled_by_default
77
75
 
78
76
  opts = { inherit_mode: config['inherit_mode'] || {},
79
77
  unset_nil: unset_nil }
@@ -117,9 +115,7 @@ module RuboCop
117
115
  # internal setting that's not documented in the manual. It will cause a
118
116
  # cop to be enabled later, when logic surrounding enabled/disabled it
119
117
  # run, even though its department is disabled.
120
- if derived_hash[key]['Enabled']
121
- derived_hash[key]['Enabled'] = 'override_department'
122
- end
118
+ derived_hash[key]['Enabled'] = 'override_department' if derived_hash[key]['Enabled']
123
119
  end
124
120
  end
125
121
 
@@ -43,8 +43,7 @@ module RuboCop
43
43
  def disable_offense(node)
44
44
  range = node.location.expression
45
45
  eol_comment = " # rubocop:todo #{cop_name}"
46
- needed_line_length = range.column +
47
- (range.source_line + eol_comment).length
46
+ needed_line_length = (range.source_line + eol_comment).length
48
47
  if needed_line_length <= max_line_length
49
48
  disable_offense_at_end_of_line(range_of_first_line(range),
50
49
  eol_comment)
@@ -85,9 +85,7 @@ module RuboCop
85
85
  def insert_before(node_or_range, content)
86
86
  range = to_range(node_or_range)
87
87
  # TODO: Fix Cops using bad ranges instead
88
- if range.end_pos > @source_buffer.source.size
89
- range = range.with(end_pos: @source_buffer.source.size)
90
- end
88
+ range = range.with(end_pos: @source_buffer.source.size) if range.end_pos > @source_buffer.source.size
91
89
 
92
90
  @source_rewriter.insert_before(range, content)
93
91
  end
@@ -48,9 +48,7 @@ module RuboCop
48
48
  return if taboo_ranges.any? { |t| within?(range, t) }
49
49
 
50
50
  if column_delta.positive?
51
- unless range.resize(1).source == "\n"
52
- corrector.insert_before(range, ' ' * column_delta)
53
- end
51
+ corrector.insert_before(range, ' ' * column_delta) unless range.resize(1).source == "\n"
54
52
  elsif /\A[ \t]+\z/.match?(range.source)
55
53
  remove(range, corrector)
56
54
  end
@@ -92,9 +90,7 @@ module RuboCop
92
90
  end
93
91
 
94
92
  def calculate_range(expr, line_begin_pos, column_delta)
95
- if column_delta.positive?
96
- return range_between(line_begin_pos, line_begin_pos)
97
- end
93
+ return range_between(line_begin_pos, line_begin_pos) if column_delta.positive?
98
94
 
99
95
  starts_with_space =
100
96
  expr.source_buffer.source[line_begin_pos].start_with?(' ')
@@ -10,9 +10,7 @@ module RuboCop
10
10
  corrector.remove(node.loc.begin)
11
11
  corrector.remove(node.loc.end)
12
12
 
13
- if ternary_condition?(node) && next_char_is_question_mark?(node)
14
- corrector.insert_after(node.loc.end, ' ')
15
- end
13
+ corrector.insert_after(node.loc.end, ' ') if ternary_condition?(node) && next_char_is_question_mark?(node)
16
14
  end
17
15
  end
18
16
 
@@ -35,9 +35,7 @@ module RuboCop
35
35
 
36
36
  def add_space(processed_source, corrector, left_token, right_token)
37
37
  @processed_source = processed_source
38
- unless left_token.space_after?
39
- corrector.insert_after(left_token.pos, ' ')
40
- end
38
+ corrector.insert_after(left_token.pos, ' ') unless left_token.space_after?
41
39
  return if right_token.space_before?
42
40
 
43
41
  corrector.insert_before(right_token.pos, ' ')
@@ -68,9 +68,7 @@ module RuboCop
68
68
  gem_name(current),
69
69
  gem_name(previous)
70
70
  )
71
- unless get_dependency_name(previous) == get_dependency_name(current)
72
- next
73
- end
71
+ next unless get_dependency_name(previous) == get_dependency_name(current)
74
72
 
75
73
  register_offense(previous, current)
76
74
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  # TODO: Implement the cop in here.
59
59
  #
60
60
  # In many cases, you can use a node matcher for matching node pattern.
61
- # See https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb
61
+ # See https://github.com/rubocop-hq/rubocop-ast/blob/master/lib/rubocop/node_pattern.rb
62
62
  #
63
63
  # For example
64
64
  MSG = 'Use `#good_method` instead of `#bad_method`.'
@@ -10,9 +10,7 @@ module RuboCop
10
10
 
11
11
  def part_of_ignored_node?(node)
12
12
  ignored_nodes.map(&:loc).any? do |ignored_loc|
13
- if ignored_loc.expression.begin_pos > node.source_range.begin_pos
14
- next false
15
- end
13
+ next false if ignored_loc.expression.begin_pos > node.source_range.begin_pos
16
14
 
17
15
  ignored_end_pos = if ignored_loc.respond_to?(:heredoc_body)
18
16
  ignored_loc.heredoc_end.end_pos
@@ -99,9 +99,7 @@ module RuboCop
99
99
  lambda do |corrector|
100
100
  line = range_by_whole_lines(node.source_range)
101
101
 
102
- unless previous_line_empty?(node.first_line)
103
- corrector.insert_before(line, "\n")
104
- end
102
+ corrector.insert_before(line, "\n") unless previous_line_empty?(node.first_line)
105
103
 
106
104
  correct_next_line_if_denied_style(corrector, node, line)
107
105
  end
@@ -120,9 +118,7 @@ module RuboCop
120
118
  def correct_next_line_if_denied_style(corrector, node, line)
121
119
  case style
122
120
  when :around
123
- unless next_line_empty?(node.last_line)
124
- corrector.insert_after(line, "\n")
125
- end
121
+ corrector.insert_after(line, "\n") unless next_line_empty?(node.last_line)
126
122
  when :only_before
127
123
  if next_line_empty?(node.last_line)
128
124
  range = next_empty_line_range(node)
@@ -3,7 +3,9 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Layout
6
- # Checks for a newline after attribute accessor.
6
+ # Checks for a newline after an attribute accessor or a group of them.
7
+ # `alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are allowed by default.
8
+ # These are customizable with `AllowAliasSyntax` and `AllowedMethods` options.
7
9
  #
8
10
  # @example
9
11
  # # bad
@@ -26,6 +28,38 @@ module RuboCop
26
28
  # def do_something
27
29
  # end
28
30
  #
31
+ # @example AllowAliasSyntax: true (default)
32
+ # # good
33
+ # attr_accessor :foo
34
+ # alias :foo? :foo
35
+ #
36
+ # def do_something
37
+ # end
38
+ #
39
+ # @example AllowAliasSyntax: false
40
+ # # bad
41
+ # attr_accessor :foo
42
+ # alias :foo? :foo
43
+ #
44
+ # def do_something
45
+ # end
46
+ #
47
+ # # good
48
+ # attr_accessor :foo
49
+ #
50
+ # alias :foo? :foo
51
+ #
52
+ # def do_something
53
+ # end
54
+ #
55
+ # @example AllowedMethods: ['private']
56
+ # # good
57
+ # attr_accessor :foo
58
+ # private :foo
59
+ #
60
+ # def do_something
61
+ # end
62
+ #
29
63
  class EmptyLinesAroundAttributeAccessor < Cop
30
64
  include RangeHelp
31
65
 
@@ -36,7 +70,7 @@ module RuboCop
36
70
  return if next_line_empty?(node.last_line)
37
71
 
38
72
  next_line_node = next_line_node(node)
39
- return if next_line_node.nil? || attribute_accessor?(next_line_node)
73
+ return unless require_empty_line?(next_line_node)
40
74
 
41
75
  add_offense(node)
42
76
  end
@@ -55,12 +89,36 @@ module RuboCop
55
89
  processed_source[line].blank?
56
90
  end
57
91
 
92
+ def require_empty_line?(node)
93
+ return false unless node&.respond_to?(:type)
94
+
95
+ !allow_alias?(node) && !attribute_or_allowed_method?(node)
96
+ end
97
+
58
98
  def next_line_node(node)
59
99
  node.parent.children[node.sibling_index + 1]
60
100
  end
61
101
 
62
- def attribute_accessor?(node)
63
- node.send_type? && node.attribute_accessor?
102
+ def allow_alias?(node)
103
+ allow_alias_syntax? && node.alias_type?
104
+ end
105
+
106
+ def attribute_or_allowed_method?(node)
107
+ return false unless node.send_type?
108
+
109
+ node.attribute_accessor? || allowed_method?(node.method_name)
110
+ end
111
+
112
+ def allow_alias_syntax?
113
+ cop_config.fetch('AllowAliasSyntax', true)
114
+ end
115
+
116
+ def allowed_method?(name)
117
+ allowed_methods.include?(name.to_s)
118
+ end
119
+
120
+ def allowed_methods
121
+ cop_config.fetch('AllowedMethods', [])
64
122
  end
65
123
  end
66
124
  end