rubocop 1.60.2 → 1.63.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 (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/assets/output.css.erb +159 -0
  4. data/assets/output.html.erb +1 -160
  5. data/config/default.yml +64 -15
  6. data/lib/rubocop/cli/command/auto_generate_config.rb +12 -3
  7. data/lib/rubocop/cli/command/lsp.rb +2 -2
  8. data/lib/rubocop/cli.rb +6 -1
  9. data/lib/rubocop/config.rb +37 -10
  10. data/lib/rubocop/config_finder.rb +12 -2
  11. data/lib/rubocop/config_obsoletion.rb +1 -1
  12. data/lib/rubocop/config_validator.rb +14 -5
  13. data/lib/rubocop/cop/autocorrect_logic.rb +6 -1
  14. data/lib/rubocop/cop/base.rb +52 -6
  15. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
  16. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
  17. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
  18. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
  19. data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
  20. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +122 -28
  21. data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
  22. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  23. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
  24. data/lib/rubocop/cop/layout/end_alignment.rb +3 -1
  25. data/lib/rubocop/cop/layout/redundant_line_break.rb +11 -3
  26. data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
  27. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
  28. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -4
  29. data/lib/rubocop/cop/lint/debugger.rb +27 -2
  30. data/lib/rubocop/cop/lint/empty_conditional_body.rb +1 -1
  31. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +14 -9
  32. data/lib/rubocop/cop/lint/redundant_with_index.rb +4 -0
  33. data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
  34. data/lib/rubocop/cop/lint/script_permission.rb +3 -3
  35. data/lib/rubocop/cop/lint/syntax.rb +1 -1
  36. data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -2
  37. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  38. data/lib/rubocop/cop/lint/void.rb +6 -1
  39. data/lib/rubocop/cop/mixin/code_length.rb +12 -1
  40. data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
  41. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  42. data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
  43. data/lib/rubocop/cop/naming/block_forwarding.rb +31 -12
  44. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  45. data/lib/rubocop/cop/naming/inclusive_language.rb +1 -2
  46. data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
  47. data/lib/rubocop/cop/registry.rb +1 -1
  48. data/lib/rubocop/cop/style/alias.rb +1 -0
  49. data/lib/rubocop/cop/style/arguments_forwarding.rb +29 -8
  50. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  51. data/lib/rubocop/cop/style/class_vars.rb +3 -3
  52. data/lib/rubocop/cop/style/collection_compact.rb +3 -3
  53. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +4 -5
  55. data/lib/rubocop/cop/style/copyright.rb +16 -11
  56. data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
  57. data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
  58. data/lib/rubocop/cop/style/for.rb +2 -0
  59. data/lib/rubocop/cop/style/format_string.rb +9 -9
  60. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
  61. data/lib/rubocop/cop/style/hash_syntax.rb +6 -2
  62. data/lib/rubocop/cop/style/inverse_methods.rb +8 -8
  63. data/lib/rubocop/cop/style/invertible_unless_condition.rb +10 -5
  64. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +5 -8
  65. data/lib/rubocop/cop/style/map_into_array.rb +175 -0
  66. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  67. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  68. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -1
  69. data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
  70. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +4 -0
  71. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  72. data/lib/rubocop/cop/style/object_then.rb +5 -3
  73. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -3
  74. data/lib/rubocop/cop/style/raise_args.rb +4 -1
  75. data/lib/rubocop/cop/style/redundant_argument.rb +25 -2
  76. data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
  77. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
  78. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  79. data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
  80. data/lib/rubocop/cop/style/redundant_line_continuation.rb +5 -0
  81. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  82. data/lib/rubocop/cop/style/redundant_return.rb +6 -0
  83. data/lib/rubocop/cop/style/sample.rb +1 -3
  84. data/lib/rubocop/cop/team.rb +3 -0
  85. data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
  86. data/lib/rubocop/cops_documentation_generator.rb +4 -2
  87. data/lib/rubocop/directive_comment.rb +10 -8
  88. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
  89. data/lib/rubocop/formatter/html_formatter.rb +30 -10
  90. data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
  91. data/lib/rubocop/formatter/tap_formatter.rb +3 -7
  92. data/lib/rubocop/lockfile.rb +34 -4
  93. data/lib/rubocop/lsp/logger.rb +1 -1
  94. data/lib/rubocop/lsp/routes.rb +1 -1
  95. data/lib/rubocop/lsp/runtime.rb +1 -1
  96. data/lib/rubocop/lsp/server.rb +5 -2
  97. data/lib/rubocop/lsp/severity.rb +1 -1
  98. data/lib/rubocop/lsp.rb +29 -0
  99. data/lib/rubocop/magic_comment.rb +1 -1
  100. data/lib/rubocop/options.rb +11 -0
  101. data/lib/rubocop/path_util.rb +6 -2
  102. data/lib/rubocop/rspec/cop_helper.rb +8 -2
  103. data/lib/rubocop/rspec/expect_offense.rb +16 -8
  104. data/lib/rubocop/rspec/shared_contexts.rb +49 -18
  105. data/lib/rubocop/rspec/support.rb +2 -1
  106. data/lib/rubocop/runner.rb +12 -2
  107. data/lib/rubocop/target_finder.rb +84 -78
  108. data/lib/rubocop/target_ruby.rb +82 -80
  109. data/lib/rubocop/version.rb +19 -4
  110. data/lib/rubocop.rb +1 -0
  111. metadata +10 -6
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  # @api private
6
6
  class TargetRuby
7
- KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3].freeze
7
+ KNOWN_RUBIES = [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4].freeze
8
8
  DEFAULT_VERSION = 2.7
9
9
 
10
10
  OBSOLETE_RUBIES = {
@@ -48,6 +48,86 @@ module RuboCop
48
48
  end
49
49
  end
50
50
 
51
+ # The target ruby version may be found in a .gemspec file.
52
+ # @api private
53
+ class GemspecFile < Source
54
+ extend NodePattern::Macros
55
+
56
+ GEMSPEC_EXTENSION = '.gemspec'
57
+
58
+ # @!method required_ruby_version(node)
59
+ def_node_search :required_ruby_version, <<~PATTERN
60
+ (send _ :required_ruby_version= $_)
61
+ PATTERN
62
+
63
+ # @!method gem_requirement_versions(node)
64
+ def_node_matcher :gem_requirement_versions, <<~PATTERN
65
+ (send (const(const _ :Gem):Requirement) :new
66
+ {$str+ | (send $str :freeze)+ | (array $str+) | (array (send $str :freeze)+)}
67
+ )
68
+ PATTERN
69
+
70
+ def name
71
+ "`required_ruby_version` parameter (in #{gemspec_filename})"
72
+ end
73
+
74
+ private
75
+
76
+ def find_version
77
+ file = gemspec_filepath
78
+ return unless file && File.file?(file)
79
+
80
+ right_hand_side = version_from_gemspec_file(file)
81
+ return if right_hand_side.nil?
82
+
83
+ find_default_minimal_known_ruby(right_hand_side)
84
+ end
85
+
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
+ def gemspec_filepath
94
+ @gemspec_filepath ||=
95
+ @config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters)
96
+ end
97
+
98
+ def version_from_gemspec_file(file)
99
+ processed_source = ProcessedSource.from_file(
100
+ file, DEFAULT_VERSION, parser_engine: @config.parser_engine
101
+ )
102
+ required_ruby_version(processed_source.ast).first
103
+ end
104
+
105
+ def version_from_right_hand_side(right_hand_side)
106
+ gem_requirement_versions = gem_requirement_versions(right_hand_side)
107
+
108
+ if right_hand_side.array_type? && right_hand_side.children.all?(&:str_type?)
109
+ version_from_array(right_hand_side)
110
+ elsif gem_requirement_versions
111
+ gem_requirement_versions.map(&:value)
112
+ elsif right_hand_side.str_type?
113
+ right_hand_side.value
114
+ end
115
+ end
116
+
117
+ def version_from_array(array)
118
+ array.children.map(&:value)
119
+ end
120
+
121
+ def find_default_minimal_known_ruby(right_hand_side)
122
+ version = version_from_right_hand_side(right_hand_side)
123
+ requirement = Gem::Requirement.new(version)
124
+
125
+ KNOWN_RUBIES.detect do |v|
126
+ v >= DEFAULT_VERSION && requirement.satisfied_by?(Gem::Version.new("#{v}.99"))
127
+ end
128
+ end
129
+ end
130
+
51
131
  # The target ruby version may be found in a .ruby-version file.
52
132
  # @api private
53
133
  class RubyVersionFile < Source
@@ -143,84 +223,6 @@ module RuboCop
143
223
  end
144
224
  end
145
225
 
146
- # The target ruby version may be found in a .gemspec file.
147
- # @api private
148
- class GemspecFile < Source
149
- extend NodePattern::Macros
150
-
151
- GEMSPEC_EXTENSION = '.gemspec'
152
-
153
- # @!method required_ruby_version(node)
154
- def_node_search :required_ruby_version, <<~PATTERN
155
- (send _ :required_ruby_version= $_)
156
- PATTERN
157
-
158
- # @!method gem_requirement_versions(node)
159
- def_node_matcher :gem_requirement_versions, <<~PATTERN
160
- (send (const(const _ :Gem):Requirement) :new
161
- {$str+ | (send $str :freeze)+ | (array $str+) | (array (send $str :freeze)+)}
162
- )
163
- PATTERN
164
-
165
- def name
166
- "`required_ruby_version` parameter (in #{gemspec_filename})"
167
- end
168
-
169
- private
170
-
171
- def find_version
172
- file = gemspec_filepath
173
- return unless file && File.file?(file)
174
-
175
- right_hand_side = version_from_gemspec_file(file)
176
- return if right_hand_side.nil?
177
-
178
- find_default_minimal_known_ruby(right_hand_side)
179
- end
180
-
181
- def gemspec_filename
182
- @gemspec_filename ||= begin
183
- basename = Pathname.new(@config.base_dir_for_path_parameters).basename.to_s
184
- "#{basename}#{GEMSPEC_EXTENSION}"
185
- end
186
- end
187
-
188
- def gemspec_filepath
189
- @gemspec_filepath ||=
190
- @config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters)
191
- end
192
-
193
- def version_from_gemspec_file(file)
194
- processed_source = ProcessedSource.from_file(file, DEFAULT_VERSION)
195
- required_ruby_version(processed_source.ast).first
196
- end
197
-
198
- def version_from_right_hand_side(right_hand_side)
199
- gem_requirement_versions = gem_requirement_versions(right_hand_side)
200
-
201
- if right_hand_side.array_type?
202
- version_from_array(right_hand_side)
203
- elsif gem_requirement_versions
204
- gem_requirement_versions.map(&:value)
205
- else
206
- right_hand_side.value
207
- end
208
- end
209
-
210
- def version_from_array(array)
211
- array.children.map(&:value)
212
- end
213
-
214
- def find_default_minimal_known_ruby(right_hand_side)
215
- version = version_from_right_hand_side(right_hand_side)
216
- requirement = Gem::Requirement.new(version)
217
-
218
- KNOWN_RUBIES.detect do |v|
219
- v >= DEFAULT_VERSION && requirement.satisfied_by?(Gem::Version.new("#{v}.99"))
220
- end
221
- end
222
- end
223
-
224
226
  # If all else fails, a default version will be picked.
225
227
  # @api private
226
228
  class Default < Source
@@ -241,10 +243,10 @@ module RuboCop
241
243
 
242
244
  SOURCES = [
243
245
  RuboCopConfig,
246
+ GemspecFile,
244
247
  RubyVersionFile,
245
248
  ToolVersionsFile,
246
249
  BundlerLockFile,
247
- GemspecFile,
248
250
  Default
249
251
  ].freeze
250
252
 
@@ -3,15 +3,15 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.60.2'
6
+ STRING = '1.63.0'
7
7
 
8
- MSG = '%<version>s (using Parser %<parser_version>s, ' \
8
+ MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
10
10
  'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
11
11
 
12
12
  CANONICAL_FEATURE_NAMES = {
13
13
  'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown', 'Factory_bot' => 'FactoryBot',
14
- 'Thread_safety' => 'ThreadSafety'
14
+ 'Thread_safety' => 'ThreadSafety', 'Rspec_rails' => 'RSpecRails'
15
15
  }.freeze
16
16
  EXTENSION_PATH_NAMES = {
17
17
  'rubocop-md' => 'markdown', 'rubocop-factory_bot' => 'factory_bot'
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # @api private
21
21
  def self.version(debug: false, env: nil)
22
22
  if debug
23
- verbose_version = format(MSG, version: STRING, parser_version: Parser::VERSION,
23
+ verbose_version = format(MSG, version: STRING, parser_version: parser_version,
24
24
  rubocop_ast_version: RuboCop::AST::Version::STRING,
25
25
  ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
26
26
  server_mode: server_mode,
@@ -39,6 +39,21 @@ module RuboCop
39
39
  end
40
40
  end
41
41
 
42
+ # @api private
43
+ def self.parser_version
44
+ config_path = ConfigFinder.find_config_path(Dir.pwd)
45
+ yaml = YAML.safe_load(
46
+ File.read(config_path), permitted_classes: [Regexp, Symbol], aliases: true
47
+ )
48
+
49
+ if yaml.dig('AllCops', 'ParserEngine') == 'parser_prism'
50
+ require 'prism'
51
+ "Prism #{Prism::VERSION}"
52
+ else
53
+ "Parser #{Parser::VERSION}"
54
+ end
55
+ end
56
+
42
57
  # @api private
43
58
  def self.extension_versions(env)
44
59
  features = Util.silence_warnings do
data/lib/rubocop.rb CHANGED
@@ -557,6 +557,7 @@ require_relative 'rubocop/cop/style/lambda'
557
557
  require_relative 'rubocop/cop/style/lambda_call'
558
558
  require_relative 'rubocop/cop/style/line_end_concatenation'
559
559
  require_relative 'rubocop/cop/style/magic_comment_format'
560
+ require_relative 'rubocop/cop/style/map_into_array'
560
561
  require_relative 'rubocop/cop/style/map_to_hash'
561
562
  require_relative 'rubocop/cop/style/map_to_set'
562
563
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
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.60.2
4
+ version: 1.63.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-01-24 00:00:00.000000000 Z
13
+ date: 2024-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -134,7 +134,7 @@ dependencies:
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 1.30.0
137
+ version: 1.31.1
138
138
  - - "<"
139
139
  - !ruby/object:Gem::Version
140
140
  version: '2.0'
@@ -144,7 +144,7 @@ dependencies:
144
144
  requirements:
145
145
  - - ">="
146
146
  - !ruby/object:Gem::Version
147
- version: 1.30.0
147
+ version: 1.31.1
148
148
  - - "<"
149
149
  - !ruby/object:Gem::Version
150
150
  version: '2.0'
@@ -196,6 +196,7 @@ files:
196
196
  - LICENSE.txt
197
197
  - README.md
198
198
  - assets/logo.png
199
+ - assets/output.css.erb
199
200
  - assets/output.html.erb
200
201
  - config/default.yml
201
202
  - config/obsoletion.yml
@@ -302,6 +303,7 @@ files:
302
303
  - lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb
303
304
  - lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb
304
305
  - lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
306
+ - lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb
305
307
  - lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb
306
308
  - lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
307
309
  - lib/rubocop/cop/internal_affairs/redundant_message_argument.rb
@@ -776,6 +778,7 @@ files:
776
778
  - lib/rubocop/cop/style/line_end_concatenation.rb
777
779
  - lib/rubocop/cop/style/magic_comment_format.rb
778
780
  - lib/rubocop/cop/style/map_compact_with_conditional_block.rb
781
+ - lib/rubocop/cop/style/map_into_array.rb
779
782
  - lib/rubocop/cop/style/map_to_hash.rb
780
783
  - lib/rubocop/cop/style/map_to_set.rb
781
784
  - lib/rubocop/cop/style/method_call_with_args_parentheses.rb
@@ -978,6 +981,7 @@ files:
978
981
  - lib/rubocop/formatter/text_util.rb
979
982
  - lib/rubocop/formatter/worst_offenders_formatter.rb
980
983
  - lib/rubocop/lockfile.rb
984
+ - lib/rubocop/lsp.rb
981
985
  - lib/rubocop/lsp/logger.rb
982
986
  - lib/rubocop/lsp/routes.rb
983
987
  - lib/rubocop/lsp/runtime.rb
@@ -1028,9 +1032,9 @@ licenses:
1028
1032
  - MIT
1029
1033
  metadata:
1030
1034
  homepage_uri: https://rubocop.org/
1031
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.60.2
1035
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.63.0
1032
1036
  source_code_uri: https://github.com/rubocop/rubocop/
1033
- documentation_uri: https://docs.rubocop.org/rubocop/1.60/
1037
+ documentation_uri: https://docs.rubocop.org/rubocop/1.63/
1034
1038
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1035
1039
  rubygems_mfa_required: 'true'
1036
1040
  post_install_message: