rubocop 1.71.1 → 1.72.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +28 -0
  4. data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
  5. data/lib/rubocop/comment_config.rb +1 -1
  6. data/lib/rubocop/config.rb +4 -0
  7. data/lib/rubocop/config_loader.rb +40 -8
  8. data/lib/rubocop/config_loader_resolver.rb +21 -7
  9. data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
  10. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -1
  11. data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
  12. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +7 -1
  13. data/lib/rubocop/cop/internal_affairs.rb +1 -16
  14. data/lib/rubocop/cop/layout/block_alignment.rb +2 -0
  15. data/lib/rubocop/cop/layout/else_alignment.rb +2 -2
  16. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  17. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +0 -6
  18. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
  19. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  20. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  21. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
  22. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
  23. data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
  24. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  25. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +221 -0
  26. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
  27. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
  28. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +74 -0
  29. data/lib/rubocop/cop/lint/void.rb +1 -6
  30. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
  31. data/lib/rubocop/cop/mixin/alignment.rb +2 -2
  32. data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
  33. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +18 -18
  34. data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
  35. data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
  36. data/lib/rubocop/cop/mixin/range_help.rb +3 -3
  37. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  38. data/lib/rubocop/cop/naming/predicate_name.rb +44 -0
  39. data/lib/rubocop/cop/style/each_with_object.rb +2 -3
  40. data/lib/rubocop/cop/style/explicit_block_argument.rb +14 -1
  41. data/lib/rubocop/cop/style/redundant_format.rb +222 -0
  42. data/lib/rubocop/cop/style/redundant_parentheses.rb +17 -3
  43. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  44. data/lib/rubocop/cop/util.rb +1 -1
  45. data/lib/rubocop/cop/utils/format_string.rb +7 -5
  46. data/lib/rubocop/cop/variable_force/variable.rb +13 -1
  47. data/lib/rubocop/directive_comment.rb +35 -2
  48. data/lib/rubocop/lsp/runtime.rb +2 -0
  49. data/lib/rubocop/lsp/server.rb +0 -2
  50. data/lib/rubocop/options.rb +26 -11
  51. data/lib/rubocop/path_util.rb +4 -0
  52. data/lib/rubocop/plugin/configuration_integrator.rb +141 -0
  53. data/lib/rubocop/plugin/load_error.rb +35 -0
  54. data/lib/rubocop/plugin/loader.rb +100 -0
  55. data/lib/rubocop/plugin/not_supported_error.rb +29 -0
  56. data/lib/rubocop/plugin.rb +39 -0
  57. data/lib/rubocop/rake_task.rb +4 -1
  58. data/lib/rubocop/server/cache.rb +35 -2
  59. data/lib/rubocop/server/cli.rb +2 -2
  60. data/lib/rubocop/version.rb +17 -2
  61. data/lib/rubocop.rb +5 -0
  62. data/lib/ruby_lsp/rubocop/addon.rb +7 -10
  63. data/lib/ruby_lsp/rubocop/{wraps_built_in_lsp_runtime.rb → runtime_adapter.rb} +5 -8
  64. metadata +35 -9
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.71.1'
6
+ STRING = '1.72.0'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
@@ -63,9 +63,21 @@ module RuboCop
63
63
  end
64
64
 
65
65
  # @api private
66
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
66
67
  def self.extension_versions(env)
68
+ plugins = config_for_pwd(env).loaded_plugins
69
+ plugin_versions = plugins.filter_map do |plugin|
70
+ next if Plugin::BUILTIN_INTERNAL_PLUGINS.key?(plugin.about.name)
71
+ next unless (plugin_name = plugin.about.name)
72
+
73
+ " - #{plugin_name} #{plugin.about.version}"
74
+ end
75
+
76
+ # TODO: It needs to be maintained for a while to ensure compatibility with extensions that
77
+ # don't support plugins. It should be removed in future once the old style becomes obsolete.
67
78
  features = config_for_pwd(env).loaded_features.sort
68
- features.filter_map do |loaded_feature|
79
+ features -= plugins.map { |plugin| plugin.about.name }
80
+ feature_versions = features.filter_map do |loaded_feature|
69
81
  next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
70
82
 
71
83
  # Get the expected name of the folder containing the extension code.
@@ -84,7 +96,10 @@ module RuboCop
84
96
 
85
97
  " - #{loaded_feature} #{feature_version}"
86
98
  end
99
+
100
+ plugin_versions + feature_versions
87
101
  end
102
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
88
103
 
89
104
  # @api private
90
105
  def self.target_ruby_version(env)
data/lib/rubocop.rb CHANGED
@@ -304,6 +304,7 @@ require_relative 'rubocop/cop/lint/constant_definition_in_block'
304
304
  require_relative 'rubocop/cop/lint/constant_overwritten_in_rescue'
305
305
  require_relative 'rubocop/cop/lint/constant_reassignment'
306
306
  require_relative 'rubocop/cop/lint/constant_resolution'
307
+ require_relative 'rubocop/cop/lint/cop_directive_syntax'
307
308
  require_relative 'rubocop/cop/lint/debugger'
308
309
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
309
310
  require_relative 'rubocop/cop/lint/deprecated_constants'
@@ -384,6 +385,7 @@ require_relative 'rubocop/cop/lint/redundant_require_statement'
384
385
  require_relative 'rubocop/cop/lint/redundant_safe_navigation'
385
386
  require_relative 'rubocop/cop/lint/redundant_splat_expansion'
386
387
  require_relative 'rubocop/cop/lint/redundant_string_coercion'
388
+ require_relative 'rubocop/cop/lint/redundant_type_conversion'
387
389
  require_relative 'rubocop/cop/lint/redundant_with_index'
388
390
  require_relative 'rubocop/cop/lint/redundant_with_object'
389
391
  require_relative 'rubocop/cop/lint/refinement_import_methods'
@@ -405,6 +407,7 @@ require_relative 'rubocop/cop/lint/shadowed_exception'
405
407
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
406
408
  require_relative 'rubocop/cop/lint/struct_new_override'
407
409
  require_relative 'rubocop/cop/lint/suppressed_exception'
410
+ require_relative 'rubocop/cop/lint/suppressed_exception_in_number_conversion'
408
411
  require_relative 'rubocop/cop/lint/symbol_conversion'
409
412
  require_relative 'rubocop/cop/lint/syntax'
410
413
  require_relative 'rubocop/cop/lint/to_enum_arguments'
@@ -425,6 +428,7 @@ require_relative 'rubocop/cop/lint/uri_escape_unescape'
425
428
  require_relative 'rubocop/cop/lint/uri_regexp'
426
429
  require_relative 'rubocop/cop/lint/useless_access_modifier'
427
430
  require_relative 'rubocop/cop/lint/useless_assignment'
431
+ require_relative 'rubocop/cop/lint/useless_constant_scoping'
428
432
  require_relative 'rubocop/cop/lint/useless_defined'
429
433
  require_relative 'rubocop/cop/lint/useless_else_without_rescue'
430
434
  require_relative 'rubocop/cop/lint/useless_method_definition'
@@ -604,6 +608,7 @@ require_relative 'rubocop/cop/style/redundant_each'
604
608
  require_relative 'rubocop/cop/style/redundant_fetch_block'
605
609
  require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
606
610
  require_relative 'rubocop/cop/style/redundant_filter_chain'
611
+ require_relative 'rubocop/cop/style/redundant_format'
607
612
  require_relative 'rubocop/cop/style/redundant_heredoc_delimiter_quotes'
608
613
  require_relative 'rubocop/cop/style/redundant_initialize'
609
614
  require_relative 'rubocop/cop/style/redundant_interpolation_unfreeze'
@@ -2,14 +2,14 @@
2
2
 
3
3
  require_relative '../../rubocop'
4
4
  require_relative '../../rubocop/lsp/logger'
5
- require_relative 'wraps_built_in_lsp_runtime'
5
+ require_relative 'runtime_adapter'
6
6
 
7
7
  module RubyLsp
8
8
  module RuboCop
9
9
  # A Ruby LSP add-on for RuboCop.
10
10
  class Addon < RubyLsp::Addon
11
11
  def initializer
12
- @wraps_built_in_lsp_runtime = nil
12
+ @runtime_adapter = nil
13
13
  end
14
14
 
15
15
  def name
@@ -21,11 +21,8 @@ module RubyLsp
21
21
  "Activating RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
22
22
  )
23
23
 
24
- ::RuboCop::LSP.enable
25
- @wraps_built_in_lsp_runtime = WrapsBuiltinLspRuntime.new
26
-
27
- global_state.register_formatter('rubocop', @wraps_built_in_lsp_runtime)
28
-
24
+ @runtime_adapter = RuntimeAdapter.new
25
+ global_state.register_formatter('rubocop', @runtime_adapter)
29
26
  register_additional_file_watchers(global_state, message_queue)
30
27
 
31
28
  ::RuboCop::LSP::Logger.log(
@@ -34,7 +31,7 @@ module RubyLsp
34
31
  end
35
32
 
36
33
  def deactivate
37
- @wraps_built_in_lsp_runtime = nil
34
+ @runtime_adapter = nil
38
35
  end
39
36
 
40
37
  # rubocop:disable Layout/LineLength, Metrics/MethodLength
@@ -67,9 +64,9 @@ module RubyLsp
67
64
  def workspace_did_change_watched_files(changes)
68
65
  return unless changes.any? { |change| change[:uri].end_with?('.rubocop.yml') }
69
66
 
70
- @wraps_built_in_lsp_runtime.init!
67
+ @runtime_adapter = RuntimeAdapter.new
71
68
 
72
- ::RuboCop::LSP::Logger(<<~MESSAGE, prefix: '[RuboCop]')
69
+ ::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
73
70
  Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to .rubocop.yml file change.
74
71
  MESSAGE
75
72
  end
@@ -4,18 +4,15 @@ require_relative '../../rubocop/lsp/runtime'
4
4
 
5
5
  module RubyLsp
6
6
  module RuboCop
7
- # Wrap RuboCop's built-in runtime for Ruby LSP's add-on.
8
- class WrapsBuiltinLspRuntime
7
+ # Provides an adapter to bridge RuboCop's built-in LSP runtime with Ruby LSP's add-on.
8
+ # @api private
9
+ class RuntimeAdapter
9
10
  include RubyLsp::Requests::Support::Formatter
10
11
 
11
12
  def initialize
12
- init!
13
- end
14
-
15
- def init!
16
- config = ::RuboCop::ConfigStore.new
13
+ config_store = ::RuboCop::ConfigStore.new
17
14
 
18
- @runtime = ::RuboCop::LSP::Runtime.new(config)
15
+ @runtime = ::RuboCop::LSP::Runtime.new(config_store)
19
16
  end
20
17
 
21
18
  def run_diagnostic(uri, document)
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.71.1
4
+ version: 1.72.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-01-31 00:00:00.000000000 Z
12
+ date: 2025-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -29,16 +29,30 @@ dependencies:
29
29
  name: language_server-protocol
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 3.17.0
34
+ version: 3.17.0.2
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 3.17.0.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: lint_roller
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: 3.17.0
55
+ version: 1.1.0
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: parallel
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -272,6 +286,7 @@ files:
272
286
  - lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb
273
287
  - lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb
274
288
  - lib/rubocop/cop/internal_affairs/lambda_or_proc.rb
289
+ - lib/rubocop/cop/internal_affairs/location_exists.rb
275
290
  - lib/rubocop/cop/internal_affairs/location_expression.rb
276
291
  - lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb
277
292
  - lib/rubocop/cop/internal_affairs/method_name_end_with.rb
@@ -288,6 +303,7 @@ files:
288
303
  - lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
289
304
  - lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb
290
305
  - lib/rubocop/cop/internal_affairs/operator_keyword.rb
306
+ - lib/rubocop/cop/internal_affairs/plugin.rb
291
307
  - lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb
292
308
  - lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb
293
309
  - lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
@@ -419,6 +435,7 @@ files:
419
435
  - lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb
420
436
  - lib/rubocop/cop/lint/constant_reassignment.rb
421
437
  - lib/rubocop/cop/lint/constant_resolution.rb
438
+ - lib/rubocop/cop/lint/cop_directive_syntax.rb
422
439
  - lib/rubocop/cop/lint/debugger.rb
423
440
  - lib/rubocop/cop/lint/deprecated_class_methods.rb
424
441
  - lib/rubocop/cop/lint/deprecated_constants.rb
@@ -498,6 +515,7 @@ files:
498
515
  - lib/rubocop/cop/lint/redundant_safe_navigation.rb
499
516
  - lib/rubocop/cop/lint/redundant_splat_expansion.rb
500
517
  - lib/rubocop/cop/lint/redundant_string_coercion.rb
518
+ - lib/rubocop/cop/lint/redundant_type_conversion.rb
501
519
  - lib/rubocop/cop/lint/redundant_with_index.rb
502
520
  - lib/rubocop/cop/lint/redundant_with_object.rb
503
521
  - lib/rubocop/cop/lint/refinement_import_methods.rb
@@ -520,6 +538,7 @@ files:
520
538
  - lib/rubocop/cop/lint/shared_mutable_default.rb
521
539
  - lib/rubocop/cop/lint/struct_new_override.rb
522
540
  - lib/rubocop/cop/lint/suppressed_exception.rb
541
+ - lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb
523
542
  - lib/rubocop/cop/lint/symbol_conversion.rb
524
543
  - lib/rubocop/cop/lint/syntax.rb
525
544
  - lib/rubocop/cop/lint/to_enum_arguments.rb
@@ -540,6 +559,7 @@ files:
540
559
  - lib/rubocop/cop/lint/uri_regexp.rb
541
560
  - lib/rubocop/cop/lint/useless_access_modifier.rb
542
561
  - lib/rubocop/cop/lint/useless_assignment.rb
562
+ - lib/rubocop/cop/lint/useless_constant_scoping.rb
543
563
  - lib/rubocop/cop/lint/useless_defined.rb
544
564
  - lib/rubocop/cop/lint/useless_else_without_rescue.rb
545
565
  - lib/rubocop/cop/lint/useless_method_definition.rb
@@ -865,6 +885,7 @@ files:
865
885
  - lib/rubocop/cop/style/redundant_fetch_block.rb
866
886
  - lib/rubocop/cop/style/redundant_file_extension_in_require.rb
867
887
  - lib/rubocop/cop/style/redundant_filter_chain.rb
888
+ - lib/rubocop/cop/style/redundant_format.rb
868
889
  - lib/rubocop/cop/style/redundant_freeze.rb
869
890
  - lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb
870
891
  - lib/rubocop/cop/style/redundant_initialize.rb
@@ -1008,6 +1029,11 @@ files:
1008
1029
  - lib/rubocop/options.rb
1009
1030
  - lib/rubocop/path_util.rb
1010
1031
  - lib/rubocop/platform.rb
1032
+ - lib/rubocop/plugin.rb
1033
+ - lib/rubocop/plugin/configuration_integrator.rb
1034
+ - lib/rubocop/plugin/load_error.rb
1035
+ - lib/rubocop/plugin/loader.rb
1036
+ - lib/rubocop/plugin/not_supported_error.rb
1011
1037
  - lib/rubocop/rake_task.rb
1012
1038
  - lib/rubocop/remote_config.rb
1013
1039
  - lib/rubocop/result_cache.rb
@@ -1043,15 +1069,15 @@ files:
1043
1069
  - lib/rubocop/warning.rb
1044
1070
  - lib/rubocop/yaml_duplication_checker.rb
1045
1071
  - lib/ruby_lsp/rubocop/addon.rb
1046
- - lib/ruby_lsp/rubocop/wraps_built_in_lsp_runtime.rb
1072
+ - lib/ruby_lsp/rubocop/runtime_adapter.rb
1047
1073
  homepage: https://github.com/rubocop/rubocop
1048
1074
  licenses:
1049
1075
  - MIT
1050
1076
  metadata:
1051
1077
  homepage_uri: https://rubocop.org/
1052
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.1
1078
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.72.0
1053
1079
  source_code_uri: https://github.com/rubocop/rubocop/
1054
- documentation_uri: https://docs.rubocop.org/rubocop/1.71/
1080
+ documentation_uri: https://docs.rubocop.org/rubocop/1.72/
1055
1081
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1056
1082
  rubygems_mfa_required: 'true'
1057
1083
  rdoc_options: []