rubocop 1.66.1 → 1.68.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +55 -6
  4. data/config/internal_affairs.yml +11 -0
  5. data/lib/rubocop/cached_data.rb +12 -4
  6. data/lib/rubocop/cli/command/auto_generate_config.rb +6 -7
  7. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  8. data/lib/rubocop/cli/command/lsp.rb +2 -2
  9. data/lib/rubocop/cli/command/version.rb +2 -2
  10. data/lib/rubocop/config_loader_resolver.rb +3 -3
  11. data/lib/rubocop/config_validator.rb +2 -1
  12. data/lib/rubocop/cop/autocorrect_logic.rb +22 -2
  13. data/lib/rubocop/cop/base.rb +6 -2
  14. data/lib/rubocop/cop/bundler/gem_version.rb +1 -0
  15. data/lib/rubocop/cop/cop.rb +8 -0
  16. data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -12
  17. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  18. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
  19. data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
  20. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
  21. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +8 -1
  22. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
  23. data/lib/rubocop/cop/internal_affairs.rb +16 -0
  24. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  25. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  26. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  27. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
  28. data/lib/rubocop/cop/layout/indentation_width.rb +4 -5
  29. data/lib/rubocop/cop/layout/leading_comment_space.rb +56 -1
  30. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -5
  31. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +4 -0
  32. data/lib/rubocop/cop/lint/ambiguous_range.rb +4 -1
  33. data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
  34. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  35. data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
  36. data/lib/rubocop/cop/lint/duplicate_set_element.rb +74 -0
  37. data/lib/rubocop/cop/lint/ensure_return.rb +0 -3
  38. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  39. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  40. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +10 -4
  41. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +5 -14
  42. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +25 -2
  43. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +7 -0
  44. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -6
  45. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -1
  46. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +9 -0
  47. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +107 -41
  48. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  49. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +88 -0
  50. data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
  51. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -1
  52. data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -0
  53. data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
  54. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +3 -1
  55. data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
  56. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
  57. data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
  58. data/lib/rubocop/cop/naming/inclusive_language.rb +12 -3
  59. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  60. data/lib/rubocop/cop/offense.rb +4 -5
  61. data/lib/rubocop/cop/style/access_modifier_declarations.rb +12 -2
  62. data/lib/rubocop/cop/style/accessor_grouping.rb +10 -2
  63. data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
  64. data/lib/rubocop/cop/style/arguments_forwarding.rb +46 -6
  65. data/lib/rubocop/cop/style/bitwise_predicate.rb +100 -0
  66. data/lib/rubocop/cop/style/block_delimiters.rb +31 -3
  67. data/lib/rubocop/cop/style/collection_compact.rb +10 -10
  68. data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
  69. data/lib/rubocop/cop/style/combinable_loops.rb +7 -0
  70. data/lib/rubocop/cop/style/commented_keyword.rb +7 -1
  71. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  72. data/lib/rubocop/cop/style/data_inheritance.rb +1 -1
  73. data/lib/rubocop/cop/style/endless_method.rb +1 -14
  74. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  75. data/lib/rubocop/cop/style/guard_clause.rb +15 -2
  76. data/lib/rubocop/cop/style/hash_each_methods.rb +6 -0
  77. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  78. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  79. data/lib/rubocop/cop/style/if_with_semicolon.rb +7 -3
  80. data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
  81. data/lib/rubocop/cop/style/lambda.rb +1 -1
  82. data/lib/rubocop/cop/style/map_into_array.rb +59 -8
  83. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +12 -7
  84. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  85. data/lib/rubocop/cop/style/multiple_comparison.rb +28 -39
  86. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  87. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  88. data/lib/rubocop/cop/style/one_line_conditional.rb +4 -0
  89. data/lib/rubocop/cop/style/operator_method_call.rb +25 -6
  90. data/lib/rubocop/cop/style/redundant_begin.rb +4 -0
  91. data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
  92. data/lib/rubocop/cop/style/redundant_line_continuation.rb +23 -5
  93. data/lib/rubocop/cop/style/redundant_parentheses.rb +9 -11
  94. data/lib/rubocop/cop/style/require_order.rb +1 -1
  95. data/lib/rubocop/cop/style/rescue_modifier.rb +13 -1
  96. data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
  97. data/lib/rubocop/cop/style/safe_navigation.rb +104 -50
  98. data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
  99. data/lib/rubocop/cop/style/select_by_regexp.rb +9 -6
  100. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  101. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  102. data/lib/rubocop/cop/style/ternary_parentheses.rb +26 -5
  103. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  104. data/lib/rubocop/cop/team.rb +8 -1
  105. data/lib/rubocop/cop/util.rb +1 -1
  106. data/lib/rubocop/cop/variable_force/assignment.rb +18 -3
  107. data/lib/rubocop/cop/variable_force/branch.rb +1 -1
  108. data/lib/rubocop/cop/variable_force/variable.rb +5 -1
  109. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  110. data/lib/rubocop/cops_documentation_generator.rb +81 -40
  111. data/lib/rubocop/file_finder.rb +9 -4
  112. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  113. data/lib/rubocop/lsp/runtime.rb +2 -0
  114. data/lib/rubocop/lsp/server.rb +0 -1
  115. data/lib/rubocop/rspec/expect_offense.rb +1 -0
  116. data/lib/rubocop/runner.rb +17 -6
  117. data/lib/rubocop/server/cache.rb +6 -1
  118. data/lib/rubocop/server/core.rb +1 -0
  119. data/lib/rubocop/target_ruby.rb +13 -13
  120. data/lib/rubocop/version.rb +28 -7
  121. data/lib/rubocop/yaml_duplication_checker.rb +20 -27
  122. data/lib/rubocop.rb +10 -0
  123. metadata +13 -4
@@ -5,37 +5,30 @@ module RuboCop
5
5
  # @api private
6
6
  module YAMLDuplicationChecker
7
7
  def self.check(yaml_string, filename, &on_duplicated)
8
- # Ruby 2.6+
9
- tree = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
10
- # Specify filename to display helpful message when it raises
11
- # an error.
12
- YAML.parse(yaml_string, filename: filename)
13
- else
14
- YAML.parse(yaml_string, filename)
15
- end
16
- return unless tree
17
-
18
- traverse(tree, &on_duplicated)
19
- tree
8
+ handler = DuplicationCheckHandler.new(&on_duplicated)
9
+ parser = Psych::Parser.new(handler)
10
+ parser.parse(yaml_string, filename)
11
+ parser.handler.root.children[0]
20
12
  end
21
13
 
22
- def self.traverse(tree, &on_duplicated)
23
- case tree
24
- when Psych::Nodes::Mapping
25
- tree.children.each_slice(2).with_object([]) do |(key, value), keys|
26
- exist = keys.find { |key2| key2.value == key.value }
27
- yield(exist, key) if exist
28
- keys << key
29
- traverse(value, &on_duplicated)
30
- end
31
- else
32
- children = tree.children
33
- return unless children
14
+ class DuplicationCheckHandler < Psych::TreeBuilder # :nodoc:
15
+ def initialize(&block)
16
+ super()
17
+ @block = block
18
+ end
34
19
 
35
- children.each { |c| traverse(c, &on_duplicated) }
20
+ def end_mapping
21
+ mapping_node = super
22
+ # OPTIMIZE: Use a hash for faster lookup since there can
23
+ # be quite a few keys at the top-level.
24
+ keys = {}
25
+ mapping_node.children.each_slice(2) do |key, _value|
26
+ duplicate = keys[key.value]
27
+ @block.call(duplicate, key) if duplicate
28
+ keys[key.value] = key
29
+ end
30
+ mapping_node
36
31
  end
37
32
  end
38
-
39
- private_class_method :traverse
40
33
  end
41
34
  end
data/lib/rubocop.rb CHANGED
@@ -11,6 +11,7 @@ require 'rainbow'
11
11
 
12
12
  require 'regexp_parser'
13
13
  require 'set'
14
+ require 'stringio'
14
15
  require 'unicode/display_width'
15
16
 
16
17
  # we have to require RuboCop's version, before rubocop-ast's
@@ -90,6 +91,7 @@ require_relative 'rubocop/cop/mixin/annotation_comment' # relies on range
90
91
  require_relative 'rubocop/cop/mixin/empty_lines_around_body' # relies on range
91
92
  require_relative 'rubocop/cop/mixin/empty_parameter'
92
93
  require_relative 'rubocop/cop/mixin/end_keyword_alignment'
94
+ require_relative 'rubocop/cop/mixin/endless_method_rewriter'
93
95
  require_relative 'rubocop/cop/mixin/enforce_superclass'
94
96
  require_relative 'rubocop/cop/mixin/first_element_line_break'
95
97
  require_relative 'rubocop/cop/mixin/frozen_string_literal'
@@ -312,6 +314,7 @@ require_relative 'rubocop/cop/lint/duplicate_methods'
312
314
  require_relative 'rubocop/cop/lint/duplicate_regexp_character_class_element'
313
315
  require_relative 'rubocop/cop/lint/duplicate_require'
314
316
  require_relative 'rubocop/cop/lint/duplicate_rescue_exception'
317
+ require_relative 'rubocop/cop/lint/duplicate_set_element'
315
318
  require_relative 'rubocop/cop/lint/each_with_object_argument'
316
319
  require_relative 'rubocop/cop/lint/else_layout'
317
320
  require_relative 'rubocop/cop/lint/empty_block'
@@ -402,6 +405,7 @@ require_relative 'rubocop/cop/lint/top_level_return_with_argument'
402
405
  require_relative 'rubocop/cop/lint/trailing_comma_in_attribute_declaration'
403
406
  require_relative 'rubocop/cop/lint/triple_quotes'
404
407
  require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
408
+ require_relative 'rubocop/cop/lint/unescaped_bracket_in_regexp'
405
409
  require_relative 'rubocop/cop/lint/unexpected_block_arity'
406
410
  require_relative 'rubocop/cop/lint/unified_integer'
407
411
  require_relative 'rubocop/cop/lint/unmodified_reduce_accumulator'
@@ -459,6 +463,7 @@ require_relative 'rubocop/cop/naming/variable_number'
459
463
  require_relative 'rubocop/cop/style/access_modifier_declarations'
460
464
  require_relative 'rubocop/cop/style/accessor_grouping'
461
465
  require_relative 'rubocop/cop/style/alias'
466
+ require_relative 'rubocop/cop/style/ambiguous_endless_method_definition'
462
467
  require_relative 'rubocop/cop/style/and_or'
463
468
  require_relative 'rubocop/cop/style/arguments_forwarding'
464
469
  require_relative 'rubocop/cop/style/array_coercion'
@@ -471,6 +476,7 @@ require_relative 'rubocop/cop/style/auto_resource_cleanup'
471
476
  require_relative 'rubocop/cop/style/bare_percent_literals'
472
477
  require_relative 'rubocop/cop/style/begin_block'
473
478
  require_relative 'rubocop/cop/style/bisected_attr_accessor'
479
+ require_relative 'rubocop/cop/style/bitwise_predicate'
474
480
  require_relative 'rubocop/cop/style/block_comments'
475
481
  require_relative 'rubocop/cop/style/block_delimiters'
476
482
  require_relative 'rubocop/cop/style/case_equality'
@@ -486,6 +492,7 @@ require_relative 'rubocop/cop/style/collection_compact'
486
492
  require_relative 'rubocop/cop/style/collection_methods'
487
493
  require_relative 'rubocop/cop/style/colon_method_call'
488
494
  require_relative 'rubocop/cop/style/colon_method_definition'
495
+ require_relative 'rubocop/cop/style/combinable_defined'
489
496
  require_relative 'rubocop/cop/style/combinable_loops'
490
497
  require_relative 'rubocop/cop/style/command_literal'
491
498
  require_relative 'rubocop/cop/style/comment_annotation'
@@ -558,6 +565,7 @@ require_relative 'rubocop/cop/style/inverse_methods'
558
565
  require_relative 'rubocop/cop/style/inline_comment'
559
566
  require_relative 'rubocop/cop/style/invertible_unless_condition'
560
567
  require_relative 'rubocop/cop/style/ip_addresses'
568
+ require_relative 'rubocop/cop/style/keyword_arguments_merging'
561
569
  require_relative 'rubocop/cop/style/keyword_parameters_order'
562
570
  require_relative 'rubocop/cop/style/lambda'
563
571
  require_relative 'rubocop/cop/style/lambda_call'
@@ -591,6 +599,7 @@ require_relative 'rubocop/cop/style/redundant_regexp_constructor'
591
599
  require_relative 'rubocop/cop/style/redundant_self_assignment'
592
600
  require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
593
601
  require_relative 'rubocop/cop/style/require_order'
602
+ require_relative 'rubocop/cop/style/safe_navigation_chain_length'
594
603
  require_relative 'rubocop/cop/style/single_line_do_end_block'
595
604
  require_relative 'rubocop/cop/style/sole_nested_conditional'
596
605
  require_relative 'rubocop/cop/style/static_class'
@@ -750,6 +759,7 @@ require_relative 'rubocop/config_store'
750
759
  require_relative 'rubocop/config_validator'
751
760
  require_relative 'rubocop/feature_loader'
752
761
  require_relative 'rubocop/lockfile'
762
+ require_relative 'rubocop/lsp'
753
763
  require_relative 'rubocop/target_finder'
754
764
  require_relative 'rubocop/directive_comment'
755
765
  require_relative 'rubocop/comment_config'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.66.1
4
+ version: 1.68.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-09-04 00:00:00.000000000 Z
13
+ date: 2024-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -179,6 +179,7 @@ files:
179
179
  - assets/output.css.erb
180
180
  - assets/output.html.erb
181
181
  - config/default.yml
182
+ - config/internal_affairs.yml
182
183
  - config/obsoletion.yml
183
184
  - exe/rubocop
184
185
  - lib/rubocop.rb
@@ -425,6 +426,7 @@ files:
425
426
  - lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb
426
427
  - lib/rubocop/cop/lint/duplicate_require.rb
427
428
  - lib/rubocop/cop/lint/duplicate_rescue_exception.rb
429
+ - lib/rubocop/cop/lint/duplicate_set_element.rb
428
430
  - lib/rubocop/cop/lint/each_with_object_argument.rb
429
431
  - lib/rubocop/cop/lint/else_layout.rb
430
432
  - lib/rubocop/cop/lint/empty_block.rb
@@ -515,6 +517,7 @@ files:
515
517
  - lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb
516
518
  - lib/rubocop/cop/lint/triple_quotes.rb
517
519
  - lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
520
+ - lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb
518
521
  - lib/rubocop/cop/lint/unexpected_block_arity.rb
519
522
  - lib/rubocop/cop/lint/unified_integer.rb
520
523
  - lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
@@ -575,6 +578,7 @@ files:
575
578
  - lib/rubocop/cop/mixin/empty_lines_around_body.rb
576
579
  - lib/rubocop/cop/mixin/empty_parameter.rb
577
580
  - lib/rubocop/cop/mixin/end_keyword_alignment.rb
581
+ - lib/rubocop/cop/mixin/endless_method_rewriter.rb
578
582
  - lib/rubocop/cop/mixin/enforce_superclass.rb
579
583
  - lib/rubocop/cop/mixin/first_element_line_break.rb
580
584
  - lib/rubocop/cop/mixin/frozen_string_literal.rb
@@ -654,6 +658,7 @@ files:
654
658
  - lib/rubocop/cop/style/access_modifier_declarations.rb
655
659
  - lib/rubocop/cop/style/accessor_grouping.rb
656
660
  - lib/rubocop/cop/style/alias.rb
661
+ - lib/rubocop/cop/style/ambiguous_endless_method_definition.rb
657
662
  - lib/rubocop/cop/style/and_or.rb
658
663
  - lib/rubocop/cop/style/arguments_forwarding.rb
659
664
  - lib/rubocop/cop/style/array_coercion.rb
@@ -667,6 +672,7 @@ files:
667
672
  - lib/rubocop/cop/style/begin_block.rb
668
673
  - lib/rubocop/cop/style/bisected_attr_accessor.rb
669
674
  - lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
675
+ - lib/rubocop/cop/style/bitwise_predicate.rb
670
676
  - lib/rubocop/cop/style/block_comments.rb
671
677
  - lib/rubocop/cop/style/block_delimiters.rb
672
678
  - lib/rubocop/cop/style/case_equality.rb
@@ -682,6 +688,7 @@ files:
682
688
  - lib/rubocop/cop/style/collection_methods.rb
683
689
  - lib/rubocop/cop/style/colon_method_call.rb
684
690
  - lib/rubocop/cop/style/colon_method_definition.rb
691
+ - lib/rubocop/cop/style/combinable_defined.rb
685
692
  - lib/rubocop/cop/style/combinable_loops.rb
686
693
  - lib/rubocop/cop/style/command_literal.rb
687
694
  - lib/rubocop/cop/style/comment_annotation.rb
@@ -754,6 +761,7 @@ files:
754
761
  - lib/rubocop/cop/style/inverse_methods.rb
755
762
  - lib/rubocop/cop/style/invertible_unless_condition.rb
756
763
  - lib/rubocop/cop/style/ip_addresses.rb
764
+ - lib/rubocop/cop/style/keyword_arguments_merging.rb
757
765
  - lib/rubocop/cop/style/keyword_parameters_order.rb
758
766
  - lib/rubocop/cop/style/lambda.rb
759
767
  - lib/rubocop/cop/style/lambda_call.rb
@@ -863,6 +871,7 @@ files:
863
871
  - lib/rubocop/cop/style/return_nil.rb
864
872
  - lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb
865
873
  - lib/rubocop/cop/style/safe_navigation.rb
874
+ - lib/rubocop/cop/style/safe_navigation_chain_length.rb
866
875
  - lib/rubocop/cop/style/sample.rb
867
876
  - lib/rubocop/cop/style/select_by_regexp.rb
868
877
  - lib/rubocop/cop/style/self_assignment.rb
@@ -1017,9 +1026,9 @@ licenses:
1017
1026
  - MIT
1018
1027
  metadata:
1019
1028
  homepage_uri: https://rubocop.org/
1020
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.66.1
1029
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.68.0
1021
1030
  source_code_uri: https://github.com/rubocop/rubocop/
1022
- documentation_uri: https://docs.rubocop.org/rubocop/1.66/
1031
+ documentation_uri: https://docs.rubocop.org/rubocop/1.68/
1023
1032
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1024
1033
  rubygems_mfa_required: 'true'
1025
1034
  post_install_message: