rubocop 1.66.0 → 1.67.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +15 -6
  4. data/config/internal_affairs.yml +11 -0
  5. data/lib/rubocop/cli/command/auto_generate_config.rb +6 -7
  6. data/lib/rubocop/cli/command/lsp.rb +2 -2
  7. data/lib/rubocop/comment_config.rb +4 -8
  8. data/lib/rubocop/config.rb +4 -16
  9. data/lib/rubocop/config_loader.rb +14 -8
  10. data/lib/rubocop/config_loader_resolver.rb +3 -3
  11. data/lib/rubocop/config_validator.rb +7 -10
  12. data/lib/rubocop/cop/base.rb +6 -2
  13. data/lib/rubocop/cop/bundler/gem_version.rb +1 -0
  14. data/lib/rubocop/cop/cop.rb +8 -0
  15. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  16. data/lib/rubocop/cop/internal_affairs/cop_description.rb +0 -4
  17. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  18. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +6 -21
  19. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +8 -1
  20. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +0 -5
  21. data/lib/rubocop/cop/internal_affairs.rb +16 -0
  22. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  23. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  24. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  25. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +8 -0
  26. data/lib/rubocop/cop/layout/indentation_width.rb +4 -5
  27. data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -1
  28. data/lib/rubocop/cop/lint/ambiguous_range.rb +4 -1
  29. data/lib/rubocop/cop/lint/big_decimal_new.rb +4 -7
  30. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  31. data/lib/rubocop/cop/lint/duplicate_set_element.rb +74 -0
  32. data/lib/rubocop/cop/lint/ensure_return.rb +0 -3
  33. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  34. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  35. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +10 -4
  36. data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +5 -14
  37. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +25 -2
  38. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -6
  39. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -1
  40. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +105 -41
  41. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  42. data/lib/rubocop/cop/lint/uri_regexp.rb +25 -7
  43. data/lib/rubocop/cop/mixin/percent_array.rb +1 -1
  44. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -2
  45. data/lib/rubocop/cop/naming/inclusive_language.rb +12 -3
  46. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  47. data/lib/rubocop/cop/offense.rb +2 -2
  48. data/lib/rubocop/cop/style/access_modifier_declarations.rb +12 -2
  49. data/lib/rubocop/cop/style/accessor_grouping.rb +10 -2
  50. data/lib/rubocop/cop/style/arguments_forwarding.rb +46 -6
  51. data/lib/rubocop/cop/style/block_delimiters.rb +14 -1
  52. data/lib/rubocop/cop/style/collection_compact.rb +10 -10
  53. data/lib/rubocop/cop/style/combinable_loops.rb +7 -0
  54. data/lib/rubocop/cop/style/commented_keyword.rb +7 -1
  55. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  56. data/lib/rubocop/cop/style/data_inheritance.rb +1 -1
  57. data/lib/rubocop/cop/style/empty_else.rb +1 -0
  58. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  59. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  60. data/lib/rubocop/cop/style/guard_clause.rb +1 -1
  61. data/lib/rubocop/cop/style/hash_each_methods.rb +6 -0
  62. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  63. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  64. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -5
  65. data/lib/rubocop/cop/style/lambda.rb +1 -1
  66. data/lib/rubocop/cop/style/magic_comment_format.rb +3 -8
  67. data/lib/rubocop/cop/style/map_into_array.rb +54 -10
  68. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +12 -7
  69. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  70. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  71. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  72. data/lib/rubocop/cop/style/one_line_conditional.rb +4 -0
  73. data/lib/rubocop/cop/style/operator_method_call.rb +25 -6
  74. data/lib/rubocop/cop/style/redundant_begin.rb +4 -0
  75. data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
  76. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +1 -1
  77. data/lib/rubocop/cop/style/redundant_line_continuation.rb +3 -3
  78. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  79. data/lib/rubocop/cop/style/require_order.rb +1 -1
  80. data/lib/rubocop/cop/style/rescue_modifier.rb +13 -1
  81. data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +54 -12
  82. data/lib/rubocop/cop/style/safe_navigation.rb +92 -50
  83. data/lib/rubocop/cop/style/select_by_regexp.rb +9 -6
  84. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  85. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  86. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  87. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  88. data/lib/rubocop/cop/team.rb +8 -1
  89. data/lib/rubocop/cop/util.rb +1 -1
  90. data/lib/rubocop/cops_documentation_generator.rb +73 -34
  91. data/lib/rubocop/file_finder.rb +9 -4
  92. data/lib/rubocop/lsp/runtime.rb +2 -0
  93. data/lib/rubocop/lsp/server.rb +0 -1
  94. data/lib/rubocop/rspec/expect_offense.rb +1 -0
  95. data/lib/rubocop/runner.rb +3 -0
  96. data/lib/rubocop/server/cache.rb +6 -1
  97. data/lib/rubocop/server/core.rb +1 -0
  98. data/lib/rubocop/target_ruby.rb +12 -12
  99. data/lib/rubocop/version.rb +3 -1
  100. data/lib/rubocop/yaml_duplication_checker.rb +20 -26
  101. data/lib/rubocop.rb +2 -0
  102. metadata +12 -10
@@ -53,8 +53,6 @@ module RuboCop
53
53
  class GemspecFile < Source
54
54
  extend NodePattern::Macros
55
55
 
56
- GEMSPEC_EXTENSION = '.gemspec'
57
-
58
56
  # @!method required_ruby_version(node)
59
57
  def_node_search :required_ruby_version, <<~PATTERN
60
58
  (send _ :required_ruby_version= $_)
@@ -68,7 +66,7 @@ module RuboCop
68
66
  PATTERN
69
67
 
70
68
  def name
71
- "`required_ruby_version` parameter (in #{gemspec_filename})"
69
+ "`required_ruby_version` parameter (in #{gemspec_filepath})"
72
70
  end
73
71
 
74
72
  private
@@ -83,16 +81,18 @@ module RuboCop
83
81
  find_minimal_known_ruby(right_hand_side)
84
82
  end
85
83
 
86
- def gemspec_filename
87
- @gemspec_filename ||= begin
88
- basename = Pathname.new(@config.base_dir_for_path_parameters).basename.to_s
89
- "#{basename}#{GEMSPEC_EXTENSION}"
90
- end
91
- end
92
-
93
84
  def gemspec_filepath
94
- @gemspec_filepath ||=
95
- @config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters)
85
+ return @gemspec_filepath if defined?(@gemspec_filepath)
86
+
87
+ @gemspec_filepath =
88
+ @config.traverse_directories_upwards(@config.base_dir_for_path_parameters) do |dir|
89
+ # NOTE: Can't use `dir.glob` because of JRuby 9.4.8.0 incompatibility:
90
+ # https://github.com/jruby/jruby/issues/8358
91
+ candidates = Pathname.glob("#{dir}/*.gemspec")
92
+ # Bundler will use a gemspec whatever the filename is, as long as its the only one in
93
+ # the folder.
94
+ break candidates.first if candidates.one?
95
+ end
96
96
  end
97
97
 
98
98
  def version_from_gemspec_file(file)
@@ -3,10 +3,11 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.66.0'
6
+ STRING = '1.67.0'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
10
+ 'analyzing as Ruby %<target_ruby_version>s, ' \
10
11
  'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
11
12
 
12
13
  CANONICAL_FEATURE_NAMES = {
@@ -22,6 +23,7 @@ module RuboCop
22
23
  if debug
23
24
  verbose_version = format(MSG, version: STRING, parser_version: parser_version,
24
25
  rubocop_ast_version: RuboCop::AST::Version::STRING,
26
+ target_ruby_version: TargetRuby.new(Config.new).version,
25
27
  ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
26
28
  server_mode: server_mode,
27
29
  ruby_platform: RUBY_PLATFORM)
@@ -5,36 +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)
8
+ handler = DuplicationCheckHandler.new(&on_duplicated)
9
+ parser = Psych::Parser.new(handler)
10
+ parser.parse(yaml_string, filename)
11
+ parser.handler.root.children[0]
19
12
  end
20
13
 
21
- def self.traverse(tree, &on_duplicated)
22
- case tree
23
- when Psych::Nodes::Mapping
24
- tree.children.each_slice(2).with_object([]) do |(key, value), keys|
25
- exist = keys.find { |key2| key2.value == key.value }
26
- yield(exist, key) if exist
27
- keys << key
28
- traverse(value, &on_duplicated)
29
- end
30
- else
31
- children = tree.children
32
- return unless children
14
+ class DuplicationCheckHandler < Psych::TreeBuilder # :nodoc:
15
+ def initialize(&block)
16
+ super()
17
+ @block = block
18
+ end
33
19
 
34
- 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
35
31
  end
36
32
  end
37
-
38
- private_class_method :traverse
39
33
  end
40
34
  end
data/lib/rubocop.rb CHANGED
@@ -312,6 +312,7 @@ require_relative 'rubocop/cop/lint/duplicate_methods'
312
312
  require_relative 'rubocop/cop/lint/duplicate_regexp_character_class_element'
313
313
  require_relative 'rubocop/cop/lint/duplicate_require'
314
314
  require_relative 'rubocop/cop/lint/duplicate_rescue_exception'
315
+ require_relative 'rubocop/cop/lint/duplicate_set_element'
315
316
  require_relative 'rubocop/cop/lint/each_with_object_argument'
316
317
  require_relative 'rubocop/cop/lint/else_layout'
317
318
  require_relative 'rubocop/cop/lint/empty_block'
@@ -750,6 +751,7 @@ require_relative 'rubocop/config_store'
750
751
  require_relative 'rubocop/config_validator'
751
752
  require_relative 'rubocop/feature_loader'
752
753
  require_relative 'rubocop/lockfile'
754
+ require_relative 'rubocop/lsp'
753
755
  require_relative 'rubocop/target_finder'
754
756
  require_relative 'rubocop/directive_comment'
755
757
  require_relative 'rubocop/comment_config'
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.66.0
4
+ version: 1.67.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-08-31 00:00:00.000000000 Z
13
+ date: 2024-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 1.32.1
117
+ version: 1.32.2
118
118
  - - "<"
119
119
  - !ruby/object:Gem::Version
120
120
  version: '2.0'
@@ -124,7 +124,7 @@ dependencies:
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: 1.32.1
127
+ version: 1.32.2
128
128
  - - "<"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '2.0'
@@ -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
@@ -1017,12 +1019,12 @@ licenses:
1017
1019
  - MIT
1018
1020
  metadata:
1019
1021
  homepage_uri: https://rubocop.org/
1020
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.66.0
1022
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.67.0
1021
1023
  source_code_uri: https://github.com/rubocop/rubocop/
1022
- documentation_uri: https://docs.rubocop.org/rubocop/1.66/
1024
+ documentation_uri: https://docs.rubocop.org/rubocop/1.67/
1023
1025
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1024
1026
  rubygems_mfa_required: 'true'
1025
- post_install_message:
1027
+ post_install_message:
1026
1028
  rdoc_options: []
1027
1029
  require_paths:
1028
1030
  - lib
@@ -1037,8 +1039,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1037
1039
  - !ruby/object:Gem::Version
1038
1040
  version: '0'
1039
1041
  requirements: []
1040
- rubygems_version: 3.4.22
1041
- signing_key:
1042
+ rubygems_version: 3.3.7
1043
+ signing_key:
1042
1044
  specification_version: 4
1043
1045
  summary: Automatic Ruby code style checking tool.
1044
1046
  test_files: []