rubocop 1.79.2 → 1.81.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +10 -0
  4. data/exe/rubocop +1 -8
  5. data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
  6. data/lib/rubocop/cli.rb +6 -2
  7. data/lib/rubocop/config_loader.rb +3 -1
  8. data/lib/rubocop/config_store.rb +5 -0
  9. data/lib/rubocop/cop/autocorrect_logic.rb +2 -2
  10. data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
  11. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  12. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
  13. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  14. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  15. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  16. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +30 -12
  17. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +1 -1
  18. data/lib/rubocop/cop/layout/line_length.rb +9 -1
  19. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
  20. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +8 -0
  21. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  22. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  23. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -2
  24. data/lib/rubocop/cop/lint/self_assignment.rb +5 -4
  25. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  26. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  27. data/lib/rubocop/cop/lint/void.rb +7 -0
  28. data/lib/rubocop/cop/message_annotator.rb +1 -1
  29. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  30. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  31. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  32. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  33. data/lib/rubocop/cop/naming/predicate_method.rb +15 -2
  34. data/lib/rubocop/cop/style/array_intersect.rb +45 -11
  35. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  36. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  37. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  38. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  39. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  40. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  41. data/lib/rubocop/cop/style/it_block_parameter.rb +1 -1
  42. data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
  43. data/lib/rubocop/cop/style/numbered_parameters.rb +1 -1
  44. data/lib/rubocop/cop/style/redundant_begin.rb +34 -0
  45. data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
  46. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  47. data/lib/rubocop/cop/style/redundant_format.rb +18 -3
  48. data/lib/rubocop/cop/style/redundant_parentheses.rb +14 -11
  49. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
  50. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  51. data/lib/rubocop/cop/style/safe_navigation.rb +18 -1
  52. data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
  53. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  54. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  55. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  56. data/lib/rubocop/cop/utils/format_string.rb +10 -0
  57. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  58. data/lib/rubocop/cop/variable_force.rb +9 -7
  59. data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -5
  60. data/lib/rubocop/lsp/diagnostic.rb +21 -20
  61. data/lib/rubocop/lsp/routes.rb +62 -6
  62. data/lib/rubocop/lsp/runtime.rb +2 -2
  63. data/lib/rubocop/lsp/server.rb +2 -2
  64. data/lib/rubocop/lsp/stdin_runner.rb +0 -16
  65. data/lib/rubocop/result_cache.rb +1 -1
  66. data/lib/rubocop/runner.rb +6 -4
  67. data/lib/rubocop/target_finder.rb +9 -9
  68. data/lib/rubocop/target_ruby.rb +10 -1
  69. data/lib/rubocop/version.rb +1 -1
  70. data/lib/rubocop.rb +1 -0
  71. data/lib/ruby_lsp/rubocop/addon.rb +23 -8
  72. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
  73. metadata +11 -7
@@ -8,7 +8,10 @@ module RubyLsp
8
8
  module RuboCop
9
9
  # A Ruby LSP add-on for RuboCop.
10
10
  class Addon < RubyLsp::Addon
11
- def initializer
11
+ RESTART_WATCHERS = %w[.rubocop.yml .rubocop_todo.yml .rubocop].freeze
12
+
13
+ def initialize
14
+ super
12
15
  @runtime_adapter = nil
13
16
  end
14
17
 
@@ -16,12 +19,16 @@ module RubyLsp
16
19
  'RuboCop'
17
20
  end
18
21
 
22
+ def version
23
+ ::RuboCop::Version::STRING
24
+ end
25
+
19
26
  def activate(global_state, message_queue)
20
27
  ::RuboCop::LSP::Logger.log(
21
28
  "Activating RuboCop LSP addon #{::RuboCop::Version::STRING}.", prefix: '[RuboCop]'
22
29
  )
23
30
 
24
- @runtime_adapter = RuntimeAdapter.new
31
+ @runtime_adapter = RuntimeAdapter.new(message_queue)
25
32
  global_state.register_formatter('rubocop', @runtime_adapter)
26
33
  register_additional_file_watchers(global_state, message_queue)
27
34
 
@@ -49,7 +56,7 @@ module RubyLsp
49
56
  register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
50
57
  watchers: [
51
58
  Interface::FileSystemWatcher.new(
52
- glob_pattern: '**/.rubocop{,_todo}.yml',
59
+ glob_pattern: "**/{#{RESTART_WATCHERS.join(',')}}",
53
60
  kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
54
61
  )
55
62
  ]
@@ -62,13 +69,21 @@ module RubyLsp
62
69
  # rubocop:enable Metrics/MethodLength
63
70
 
64
71
  def workspace_did_change_watched_files(changes)
65
- return unless changes.any? { |change| change[:uri].end_with?('.rubocop.yml') }
72
+ if (changed_config_file = changed_config_file(changes))
73
+ @runtime_adapter.reload_config
74
+
75
+ ::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
76
+ Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to #{changed_config_file} change.
77
+ MESSAGE
78
+ end
79
+ end
66
80
 
67
- @runtime_adapter = RuntimeAdapter.new
81
+ private
68
82
 
69
- ::RuboCop::LSP::Logger.log(<<~MESSAGE, prefix: '[RuboCop]')
70
- Re-initialized RuboCop LSP addon #{::RuboCop::Version::STRING} due to .rubocop.yml file change.
71
- MESSAGE
83
+ def changed_config_file(changes)
84
+ RESTART_WATCHERS.find do |file_name|
85
+ changes.any? { |change| change[:uri].end_with?(file_name) }
86
+ end
72
87
  end
73
88
  end
74
89
  end
@@ -7,30 +7,45 @@ module RubyLsp
7
7
  # Provides an adapter to bridge RuboCop's built-in LSP runtime with Ruby LSP's add-on.
8
8
  # @api private
9
9
  class RuntimeAdapter
10
- include RubyLsp::Requests::Support::Formatter
10
+ def initialize(message_queue)
11
+ @message_queue = message_queue
12
+ reload_config
13
+ end
11
14
 
12
- def initialize
13
- config_store = ::RuboCop::ConfigStore.new
15
+ def reload_config
16
+ @runtime = nil
17
+ options, _paths = ::RuboCop::Options.new.parse([])
14
18
 
19
+ config_store = ::RuboCop::ConfigStore.new
20
+ config_store.apply_options!(options)
15
21
  @runtime = ::RuboCop::LSP::Runtime.new(config_store)
22
+ rescue ::RuboCop::Error => e
23
+ @message_queue << Notification.window_show_message(
24
+ "RuboCop configuration error: #{e.message}. Formatting will not be available.",
25
+ type: Constant::MessageType::ERROR
26
+ )
16
27
  end
17
28
 
18
29
  def run_diagnostic(uri, document)
19
- @runtime.offenses(
20
- uri_to_path(uri),
21
- document.source,
22
- document.encoding,
23
- prism_result: prism_result(document)
24
- )
30
+ with_error_handling do
31
+ @runtime.offenses(
32
+ uri_to_path(uri),
33
+ document.source,
34
+ document.encoding,
35
+ prism_result: prism_result(document)
36
+ )
37
+ end
25
38
  end
26
39
 
27
40
  def run_formatting(uri, document)
28
- @runtime.format(
29
- uri_to_path(uri),
30
- document.source,
31
- command: 'rubocop.formatAutocorrects',
32
- prism_result: prism_result(document)
33
- )
41
+ with_error_handling do
42
+ @runtime.format(
43
+ uri_to_path(uri),
44
+ document.source,
45
+ command: 'rubocop.formatAutocorrects',
46
+ prism_result: prism_result(document)
47
+ )
48
+ end
34
49
  end
35
50
 
36
51
  def run_range_formatting(_uri, _partial_source, _base_indentation)
@@ -43,6 +58,25 @@ module RubyLsp
43
58
 
44
59
  private
45
60
 
61
+ def with_error_handling
62
+ return unless @runtime
63
+
64
+ yield
65
+ rescue StandardError => e
66
+ ::RuboCop::LSP::Logger.log(e.full_message, prefix: '[RuboCop]')
67
+
68
+ message = if e.is_a?(::RuboCop::ErrorWithAnalyzedFileLocation)
69
+ "for the #{e.cop.name} cop"
70
+ else
71
+ "- #{e.message}"
72
+ end
73
+ raise Requests::Formatting::Error, <<~MSG
74
+ An internal error occurred #{message}.
75
+ Updating to a newer version of RuboCop may solve this.
76
+ For more details, run RuboCop on the command line.
77
+ MSG
78
+ end
79
+
46
80
  # duplicated from: lib/standard/lsp/routes.rb
47
81
  # modified to incorporate Ruby LSP's to_standardized_path method
48
82
  def uri_to_path(uri)
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.79.2
4
+ version: 1.81.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
+ autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2025-08-05 00:00:00.000000000 Z
13
+ date: 2025-09-25 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
@@ -127,7 +128,7 @@ dependencies:
127
128
  requirements:
128
129
  - - ">="
129
130
  - !ruby/object:Gem::Version
130
- version: 1.46.0
131
+ version: 1.47.1
131
132
  - - "<"
132
133
  - !ruby/object:Gem::Version
133
134
  version: '2.0'
@@ -137,7 +138,7 @@ dependencies:
137
138
  requirements:
138
139
  - - ">="
139
140
  - !ruby/object:Gem::Version
140
- version: 1.46.0
141
+ version: 1.47.1
141
142
  - - "<"
142
143
  - !ruby/object:Gem::Version
143
144
  version: '2.0'
@@ -708,6 +709,7 @@ files:
708
709
  - lib/rubocop/cop/style/array_coercion.rb
709
710
  - lib/rubocop/cop/style/array_first_last.rb
710
711
  - lib/rubocop/cop/style/array_intersect.rb
712
+ - lib/rubocop/cop/style/array_intersect_with_single_element.rb
711
713
  - lib/rubocop/cop/style/array_join.rb
712
714
  - lib/rubocop/cop/style/ascii_comments.rb
713
715
  - lib/rubocop/cop/style/attr.rb
@@ -1090,11 +1092,12 @@ licenses:
1090
1092
  - MIT
1091
1093
  metadata:
1092
1094
  homepage_uri: https://rubocop.org/
1093
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.79.2
1095
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.81.0
1094
1096
  source_code_uri: https://github.com/rubocop/rubocop/
1095
- documentation_uri: https://docs.rubocop.org/rubocop/1.79/
1097
+ documentation_uri: https://docs.rubocop.org/rubocop/1.81/
1096
1098
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1097
1099
  rubygems_mfa_required: 'true'
1100
+ post_install_message:
1098
1101
  rdoc_options: []
1099
1102
  require_paths:
1100
1103
  - lib
@@ -1109,7 +1112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1109
1112
  - !ruby/object:Gem::Version
1110
1113
  version: '0'
1111
1114
  requirements: []
1112
- rubygems_version: 3.6.2
1115
+ rubygems_version: 3.3.7
1116
+ signing_key:
1113
1117
  specification_version: 4
1114
1118
  summary: Automatic Ruby code style checking tool.
1115
1119
  test_files: []