rubocop 1.23.0 → 1.24.1

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/config/default.yml +46 -1
  4. data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
  5. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  6. data/lib/rubocop/cli/command/show_docs_url.rb +48 -0
  7. data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
  8. data/lib/rubocop/cli.rb +1 -0
  9. data/lib/rubocop/config_loader_resolver.rb +1 -1
  10. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  11. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +1 -1
  12. data/lib/rubocop/cop/correctors/if_then_corrector.rb +55 -0
  13. data/lib/rubocop/cop/documentation.rb +19 -2
  14. data/lib/rubocop/cop/gemspec/require_mfa.rb +8 -10
  15. data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +47 -0
  16. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +3 -1
  17. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  18. data/lib/rubocop/cop/layout/comment_indentation.rb +31 -2
  19. data/lib/rubocop/cop/layout/dot_position.rb +4 -0
  20. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  21. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  22. data/lib/rubocop/cop/layout/space_before_first_arg.rb +4 -0
  23. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +1 -1
  24. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +16 -4
  25. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +6 -0
  26. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  27. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +4 -0
  28. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +7 -4
  29. data/lib/rubocop/cop/metrics/block_length.rb +1 -0
  30. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +0 -9
  31. data/lib/rubocop/cop/metrics/method_length.rb +1 -0
  32. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  33. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  34. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +1 -1
  35. data/lib/rubocop/cop/mixin/enforce_superclass.rb +5 -0
  36. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +4 -3
  37. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +56 -0
  38. data/lib/rubocop/cop/naming/block_forwarding.rb +107 -0
  39. data/lib/rubocop/cop/security/open.rb +11 -1
  40. data/lib/rubocop/cop/style/character_literal.rb +8 -1
  41. data/lib/rubocop/cop/style/collection_compact.rb +31 -13
  42. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  43. data/lib/rubocop/cop/style/empty_case_condition.rb +10 -0
  44. data/lib/rubocop/cop/style/file_read.rb +112 -0
  45. data/lib/rubocop/cop/style/file_write.rb +124 -0
  46. data/lib/rubocop/cop/style/hash_conversion.rb +2 -1
  47. data/lib/rubocop/cop/style/hash_syntax.rb +22 -0
  48. data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -6
  49. data/lib/rubocop/cop/style/hash_transform_values.rb +6 -6
  50. data/lib/rubocop/cop/style/if_inside_else.rb +15 -0
  51. data/lib/rubocop/cop/style/map_to_hash.rb +68 -0
  52. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +13 -0
  53. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -1
  54. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -13
  55. data/lib/rubocop/cop/style/numeric_literals.rb +10 -1
  56. data/lib/rubocop/cop/style/one_line_conditional.rb +18 -39
  57. data/lib/rubocop/cop/style/redundant_interpolation.rb +17 -3
  58. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +5 -1
  59. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  60. data/lib/rubocop/cop/style/safe_navigation.rb +1 -5
  61. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
  62. data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
  63. data/lib/rubocop/cop/team.rb +1 -1
  64. data/lib/rubocop/cop/util.rb +9 -1
  65. data/lib/rubocop/options.rb +6 -1
  66. data/lib/rubocop/remote_config.rb +1 -3
  67. data/lib/rubocop/result_cache.rb +1 -1
  68. data/lib/rubocop/version.rb +1 -1
  69. data/lib/rubocop.rb +7 -0
  70. metadata +13 -5
@@ -39,7 +39,7 @@ module RuboCop
39
39
  return unless eligible_method?(node)
40
40
  return unless eligible_arguments?(node)
41
41
 
42
- method_name = node.send_node.method_name
42
+ method_name = node.method_name
43
43
  return if args_match?(method_name, node.arguments)
44
44
 
45
45
  preferred_block_arguments = build_preferred_arguments_map(node, target_args(method_name))
@@ -81,7 +81,7 @@ module RuboCop
81
81
  end
82
82
 
83
83
  def eligible_method?(node)
84
- node.send_node.receiver && method_names.include?(node.send_node.method_name)
84
+ node.receiver && method_names.include?(node.method_name)
85
85
  end
86
86
 
87
87
  def methods
@@ -82,7 +82,9 @@ module RuboCop
82
82
  end
83
83
 
84
84
  def autocorrect(corrector, node, if_branch)
85
- corrector.wrap(node.condition, '(', ')') if node.condition.or_type?
85
+ if node.condition.or_type? || node.condition.assignment?
86
+ corrector.wrap(node.condition, '(', ')')
87
+ end
86
88
 
87
89
  correct_from_unless_to_if(corrector, node) if node.unless?
88
90
 
@@ -131,7 +131,7 @@ module RuboCop
131
131
  @options[:stdin] = new_source
132
132
  else
133
133
  filename = processed_source.buffer.name
134
- File.open(filename, 'w') { |f| f.write(new_source) }
134
+ File.write(filename, new_source)
135
135
  end
136
136
  @updated_source_file = true
137
137
  end
@@ -30,8 +30,15 @@ module RuboCop
30
30
  node.loc.respond_to?(:end) && node.loc.end && node.loc.end.is?(')')
31
31
  end
32
32
 
33
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
33
34
  def add_parentheses(node, corrector)
34
- if !node.respond_to?(:arguments)
35
+ if node.args_type?
36
+ arguments_range = node.source_range
37
+ args_with_space = range_with_surrounding_space(range: arguments_range, side: :left)
38
+ leading_space = range_between(args_with_space.begin_pos, arguments_range.begin_pos)
39
+ corrector.replace(leading_space, '(')
40
+ corrector.insert_after(arguments_range, ')')
41
+ elsif !node.respond_to?(:arguments)
35
42
  corrector.wrap(node, '(', ')')
36
43
  elsif node.arguments.empty?
37
44
  corrector.insert_after(node, '()')
@@ -43,6 +50,7 @@ module RuboCop
43
50
  corrector.insert_after(args_end(node), ')')
44
51
  end
45
52
  end
53
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
46
54
 
47
55
  def args_begin(node)
48
56
  loc = node.loc
@@ -15,7 +15,7 @@ module RuboCop
15
15
  'root of the project. RuboCop will use this path to determine which ' \
16
16
  'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
17
17
  'like Naming/FileName can be checked.'
18
- EXITING_OPTIONS = %i[version verbose_version show_cops].freeze
18
+ EXITING_OPTIONS = %i[version verbose_version show_cops show_docs_url].freeze
19
19
  DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15
20
20
 
21
21
  def initialize
@@ -188,6 +188,9 @@ module RuboCop
188
188
  option(opts, '--show-cops [COP1,COP2,...]') do |list|
189
189
  @options[:show_cops] = list.nil? ? [] : list.split(',')
190
190
  end
191
+ option(opts, '--show-docs-url [COP1,COP2,...]') do |list|
192
+ @options[:show_docs_url] = list.nil? ? [] : list.split(',')
193
+ end
191
194
  end
192
195
  end
193
196
 
@@ -475,6 +478,8 @@ module RuboCop
475
478
  show_cops: ['Shows the given cops, or all cops by',
476
479
  'default, and their configurations for the',
477
480
  'current directory.'],
481
+ show_docs_url: ['Display url to documentation for the given',
482
+ 'cops, or base url by default.'],
478
483
  fail_fast: ['Inspect files in order of modification',
479
484
  'time and stop after the first file',
480
485
  'containing offenses.'],
@@ -23,9 +23,7 @@ module RuboCop
23
23
  next if response.is_a?(Net::HTTPNotModified)
24
24
  next if response.is_a?(SocketError)
25
25
 
26
- File.open cache_path, 'w' do |io|
27
- io.write response.body
28
- end
26
+ File.write(cache_path, response.body)
29
27
  end
30
28
 
31
29
  cache_path
@@ -179,7 +179,7 @@ module RuboCop
179
179
  .select { |path| File.file?(path) }
180
180
  .sort!
181
181
  .each do |path|
182
- content = File.open(path, 'rb', &:read)
182
+ content = File.binread(path)
183
183
  digest << Zlib.crc32(content).to_s # mtime not reliable
184
184
  end
185
185
  digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.23.0'
6
+ STRING = '1.24.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -94,6 +94,7 @@ require_relative 'rubocop/cop/mixin/line_length_help'
94
94
  require_relative 'rubocop/cop/mixin/match_range'
95
95
  require_relative 'rubocop/cop/metrics/utils/repeated_csend_discount'
96
96
  require_relative 'rubocop/cop/metrics/utils/repeated_attribute_discount'
97
+ require_relative 'rubocop/cop/mixin/hash_shorthand_syntax'
97
98
  require_relative 'rubocop/cop/mixin/method_complexity'
98
99
  require_relative 'rubocop/cop/mixin/method_preference'
99
100
  require_relative 'rubocop/cop/mixin/min_body_length'
@@ -139,6 +140,7 @@ require_relative 'rubocop/cop/correctors/condition_corrector'
139
140
  require_relative 'rubocop/cop/correctors/each_to_for_corrector'
140
141
  require_relative 'rubocop/cop/correctors/empty_line_corrector'
141
142
  require_relative 'rubocop/cop/correctors/for_to_each_corrector'
143
+ require_relative 'rubocop/cop/correctors/if_then_corrector'
142
144
  require_relative 'rubocop/cop/correctors/lambda_literal_to_method_corrector'
143
145
  require_relative 'rubocop/cop/correctors/line_break_corrector'
144
146
  require_relative 'rubocop/cop/correctors/multiline_literal_brace_corrector'
@@ -405,6 +407,7 @@ require_relative 'rubocop/cop/metrics/perceived_complexity'
405
407
 
406
408
  require_relative 'rubocop/cop/naming/accessor_method_name'
407
409
  require_relative 'rubocop/cop/naming/ascii_identifiers'
410
+ require_relative 'rubocop/cop/naming/block_forwarding'
408
411
  require_relative 'rubocop/cop/naming/block_parameter_name'
409
412
  require_relative 'rubocop/cop/naming/class_and_module_camel_case'
410
413
  require_relative 'rubocop/cop/naming/constant_name'
@@ -481,6 +484,8 @@ require_relative 'rubocop/cop/style/even_odd'
481
484
  require_relative 'rubocop/cop/style/expand_path_arguments'
482
485
  require_relative 'rubocop/cop/style/explicit_block_argument'
483
486
  require_relative 'rubocop/cop/style/exponential_notation'
487
+ require_relative 'rubocop/cop/style/file_read'
488
+ require_relative 'rubocop/cop/style/file_write'
484
489
  require_relative 'rubocop/cop/style/float_division'
485
490
  require_relative 'rubocop/cop/style/for'
486
491
  require_relative 'rubocop/cop/style/format_string'
@@ -513,6 +518,7 @@ require_relative 'rubocop/cop/style/keyword_parameters_order'
513
518
  require_relative 'rubocop/cop/style/lambda'
514
519
  require_relative 'rubocop/cop/style/lambda_call'
515
520
  require_relative 'rubocop/cop/style/line_end_concatenation'
521
+ require_relative 'rubocop/cop/style/map_to_hash'
516
522
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
517
523
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
518
524
  require_relative 'rubocop/cop/style/multiline_in_pattern_then'
@@ -705,6 +711,7 @@ require_relative 'rubocop/cli/command/auto_genenerate_config'
705
711
  require_relative 'rubocop/cli/command/execute_runner'
706
712
  require_relative 'rubocop/cli/command/init_dotfile'
707
713
  require_relative 'rubocop/cli/command/show_cops'
714
+ require_relative 'rubocop/cli/command/show_docs_url'
708
715
  require_relative 'rubocop/cli/command/suggest_extensions'
709
716
  require_relative 'rubocop/cli/command/version'
710
717
  require_relative 'rubocop/config_regeneration'
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.23.0
4
+ version: 1.24.1
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: 2021-11-15 00:00:00.000000000 Z
13
+ date: 2021-12-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 1.12.0
103
+ version: 1.15.1
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '2.0'
@@ -110,7 +110,7 @@ dependencies:
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 1.12.0
113
+ version: 1.15.1
114
114
  - - "<"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '2.0'
@@ -196,6 +196,7 @@ files:
196
196
  - lib/rubocop/cli/command/execute_runner.rb
197
197
  - lib/rubocop/cli/command/init_dotfile.rb
198
198
  - lib/rubocop/cli/command/show_cops.rb
199
+ - lib/rubocop/cli/command/show_docs_url.rb
199
200
  - lib/rubocop/cli/command/suggest_extensions.rb
200
201
  - lib/rubocop/cli/command/version.rb
201
202
  - lib/rubocop/cli/environment.rb
@@ -233,6 +234,7 @@ files:
233
234
  - lib/rubocop/cop/correctors/each_to_for_corrector.rb
234
235
  - lib/rubocop/cop/correctors/empty_line_corrector.rb
235
236
  - lib/rubocop/cop/correctors/for_to_each_corrector.rb
237
+ - lib/rubocop/cop/correctors/if_then_corrector.rb
236
238
  - lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb
237
239
  - lib/rubocop/cop/correctors/line_break_corrector.rb
238
240
  - lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb
@@ -271,6 +273,7 @@ files:
271
273
  - lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb
272
274
  - lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
273
275
  - lib/rubocop/cop/internal_affairs/redundant_message_argument.rb
276
+ - lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
274
277
  - lib/rubocop/cop/internal_affairs/style_detected_api_use.rb
275
278
  - lib/rubocop/cop/internal_affairs/undefined_config.rb
276
279
  - lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
@@ -542,6 +545,7 @@ files:
542
545
  - lib/rubocop/cop/mixin/gem_declaration.rb
543
546
  - lib/rubocop/cop/mixin/gemspec_help.rb
544
547
  - lib/rubocop/cop/mixin/hash_alignment_styles.rb
548
+ - lib/rubocop/cop/mixin/hash_shorthand_syntax.rb
545
549
  - lib/rubocop/cop/mixin/hash_transform_method.rb
546
550
  - lib/rubocop/cop/mixin/heredoc.rb
547
551
  - lib/rubocop/cop/mixin/ignored_methods.rb
@@ -587,6 +591,7 @@ files:
587
591
  - lib/rubocop/cop/naming/accessor_method_name.rb
588
592
  - lib/rubocop/cop/naming/ascii_identifiers.rb
589
593
  - lib/rubocop/cop/naming/binary_operator_parameter_name.rb
594
+ - lib/rubocop/cop/naming/block_forwarding.rb
590
595
  - lib/rubocop/cop/naming/block_parameter_name.rb
591
596
  - lib/rubocop/cop/naming/class_and_module_camel_case.rb
592
597
  - lib/rubocop/cop/naming/constant_name.rb
@@ -671,6 +676,8 @@ files:
671
676
  - lib/rubocop/cop/style/expand_path_arguments.rb
672
677
  - lib/rubocop/cop/style/explicit_block_argument.rb
673
678
  - lib/rubocop/cop/style/exponential_notation.rb
679
+ - lib/rubocop/cop/style/file_read.rb
680
+ - lib/rubocop/cop/style/file_write.rb
674
681
  - lib/rubocop/cop/style/float_division.rb
675
682
  - lib/rubocop/cop/style/for.rb
676
683
  - lib/rubocop/cop/style/format_string.rb
@@ -703,6 +710,7 @@ files:
703
710
  - lib/rubocop/cop/style/lambda.rb
704
711
  - lib/rubocop/cop/style/lambda_call.rb
705
712
  - lib/rubocop/cop/style/line_end_concatenation.rb
713
+ - lib/rubocop/cop/style/map_to_hash.rb
706
714
  - lib/rubocop/cop/style/method_call_with_args_parentheses.rb
707
715
  - lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
708
716
  - lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb
@@ -903,7 +911,7 @@ metadata:
903
911
  homepage_uri: https://rubocop.org/
904
912
  changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
905
913
  source_code_uri: https://github.com/rubocop/rubocop/
906
- documentation_uri: https://docs.rubocop.org/rubocop/1.23/
914
+ documentation_uri: https://docs.rubocop.org/rubocop/1.24/
907
915
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
908
916
  rubygems_mfa_required: 'true'
909
917
  post_install_message: