rubocop 1.34.1 → 1.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +33 -0
  4. data/lib/rubocop/cli/command/{auto_genenerate_config.rb → auto_generate_config.rb} +0 -0
  5. data/lib/rubocop/config.rb +1 -1
  6. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +32 -2
  7. data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
  8. data/lib/rubocop/cop/generator/require_file_injector.rb +2 -2
  9. data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +69 -0
  10. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
  11. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  12. data/lib/rubocop/cop/layout/block_alignment.rb +16 -12
  13. data/lib/rubocop/cop/layout/block_end_newline.rb +2 -0
  14. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +5 -2
  15. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -0
  16. data/lib/rubocop/cop/layout/end_of_line.rb +4 -4
  17. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
  18. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
  19. data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
  20. data/lib/rubocop/cop/layout/line_length.rb +4 -1
  21. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
  22. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
  23. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  24. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  25. data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -0
  26. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +25 -9
  27. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  28. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  29. data/lib/rubocop/cop/lint/duplicate_require.rb +1 -1
  30. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  31. data/lib/rubocop/cop/lint/empty_conditional_body.rb +31 -1
  32. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -9
  33. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +4 -0
  34. data/lib/rubocop/cop/lint/next_without_accumulator.rb +25 -6
  35. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +6 -6
  36. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +12 -0
  37. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +9 -3
  38. data/lib/rubocop/cop/lint/redundant_with_index.rb +13 -10
  39. data/lib/rubocop/cop/lint/redundant_with_object.rb +12 -11
  40. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  41. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +15 -2
  42. data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
  43. data/lib/rubocop/cop/lint/useless_access_modifier.rb +8 -6
  44. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +1 -1
  45. data/lib/rubocop/cop/lint/void.rb +2 -0
  46. data/lib/rubocop/cop/mixin/allowed_methods.rb +10 -5
  47. data/lib/rubocop/cop/mixin/allowed_pattern.rb +13 -5
  48. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  49. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +76 -1
  50. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -6
  51. data/lib/rubocop/cop/mixin/method_complexity.rb +4 -4
  52. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
  53. data/lib/rubocop/cop/mixin/range_help.rb +2 -3
  54. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  55. data/lib/rubocop/cop/naming/constant_name.rb +2 -2
  56. data/lib/rubocop/cop/style/access_modifier_declarations.rb +77 -1
  57. data/lib/rubocop/cop/style/arguments_forwarding.rb +2 -2
  58. data/lib/rubocop/cop/style/case_equality.rb +40 -10
  59. data/lib/rubocop/cop/style/class_methods_definitions.rb +2 -1
  60. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  61. data/lib/rubocop/cop/style/combinable_loops.rb +3 -1
  62. data/lib/rubocop/cop/style/each_for_simple_loop.rb +41 -6
  63. data/lib/rubocop/cop/style/each_with_object.rb +39 -8
  64. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  65. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  66. data/lib/rubocop/cop/style/for.rb +2 -0
  67. data/lib/rubocop/cop/style/guard_clause.rb +27 -16
  68. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -1
  69. data/lib/rubocop/cop/style/hash_syntax.rb +17 -0
  70. data/lib/rubocop/cop/style/inverse_methods.rb +8 -6
  71. data/lib/rubocop/cop/style/magic_comment_format.rb +307 -0
  72. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
  73. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
  74. data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -1
  75. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
  76. data/lib/rubocop/cop/style/next.rb +3 -5
  77. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  78. data/lib/rubocop/cop/style/object_then.rb +2 -0
  79. data/lib/rubocop/cop/style/perl_backrefs.rb +22 -1
  80. data/lib/rubocop/cop/style/proc.rb +4 -1
  81. data/lib/rubocop/cop/style/redundant_begin.rb +2 -0
  82. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  83. data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
  84. data/lib/rubocop/cop/style/redundant_self.rb +2 -0
  85. data/lib/rubocop/cop/style/redundant_sort_by.rb +24 -8
  86. data/lib/rubocop/cop/style/safe_navigation.rb +4 -2
  87. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  88. data/lib/rubocop/cop/style/sole_nested_conditional.rb +0 -2
  89. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  90. data/lib/rubocop/cop/style/symbol_proc.rb +5 -4
  91. data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -1
  92. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  93. data/lib/rubocop/cop/style/word_array.rb +1 -1
  94. data/lib/rubocop/cop/util.rb +1 -1
  95. data/lib/rubocop/feature_loader.rb +6 -2
  96. data/lib/rubocop/formatter/html_formatter.rb +2 -2
  97. data/lib/rubocop/runner.rb +4 -0
  98. data/lib/rubocop/server/cache.rb +11 -8
  99. data/lib/rubocop/version.rb +3 -2
  100. data/lib/rubocop.rb +3 -2
  101. metadata +9 -7
@@ -63,6 +63,8 @@ module RuboCop
63
63
  add_offense(node)
64
64
  end
65
65
 
66
+ alias on_numblock on_block
67
+
66
68
  private
67
69
 
68
70
  def top_level_method_definition?(node)
@@ -75,7 +77,7 @@ module RuboCop
75
77
 
76
78
  # @!method define_method_block?(node)
77
79
  def_node_matcher :define_method_block?, <<~PATTERN
78
- (block (send _ {:define_method} _) ...)
80
+ ({block numblock} (send _ {:define_method} _) ...)
79
81
  PATTERN
80
82
  end
81
83
  end
@@ -64,7 +64,7 @@ module RuboCop
64
64
 
65
65
  MSG = 'Useless trailing comma present in block arguments.'
66
66
 
67
- def on_block(node)
67
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
68
68
  # lambda literal (`->`) never has block arguments.
69
69
  return if node.send_node.lambda_literal?
70
70
  return unless useless_trailing_comma?(node)
@@ -87,7 +87,7 @@ module RuboCop
87
87
  if word.dstr_type?
88
88
  string_literal = to_string_literal(word.source)
89
89
 
90
- trim_string_interporation_escape_character(string_literal)
90
+ trim_string_interpolation_escape_character(string_literal)
91
91
  else
92
92
  to_string_literal(word.children[0])
93
93
  end
@@ -126,7 +126,7 @@ module RuboCop
126
126
  end
127
127
  end
128
128
 
129
- def trim_string_interporation_escape_character(str)
129
+ def trim_string_interpolation_escape_character(str)
130
130
  str.gsub(/\\\#\{(.*?)\}/) { "\#{#{Regexp.last_match(1)}}" }
131
131
  end
132
132
 
@@ -37,9 +37,13 @@ module RuboCop
37
37
  raise if e.path != target
38
38
 
39
39
  begin
40
- ::Kernel.require(namespaced_target)
40
+ # Don't use `::Kernel.require(target)` to prevent the following error:
41
+ # https://github.com/rubocop/rubocop/issues/10893
42
+ require(namespaced_target)
41
43
  rescue ::LoadError => error_for_namespaced_target
42
- raise e if error_for_namespaced_target.path == namespaced_target
44
+ # NOTE: This wrap is necessary due to JRuby 9.3.4.0 incompatibility:
45
+ # https://github.com/jruby/jruby/issues/7316
46
+ raise LoadError, e if error_for_namespaced_target.path == namespaced_target
43
47
 
44
48
  raise error_for_namespaced_target
45
49
  end
@@ -93,12 +93,12 @@ module RuboCop
93
93
 
94
94
  def highlighted_source_line(offense)
95
95
  source_before_highlight(offense) +
96
- hightlight_source_tag(offense) +
96
+ highlight_source_tag(offense) +
97
97
  source_after_highlight(offense) +
98
98
  possible_ellipses(offense.location)
99
99
  end
100
100
 
101
- def hightlight_source_tag(offense)
101
+ def highlight_source_tag(offense)
102
102
  "<span class=\"highlight #{offense.severity}\">" \
103
103
  "#{escape(offense.highlighted_area.source)}" \
104
104
  '</span>'
@@ -64,6 +64,10 @@ module RuboCop
64
64
  # instances that each inspects its allotted group of files.
65
65
  def warm_cache(target_files)
66
66
  saved_options = @options.dup
67
+ if target_files.length <= 1
68
+ puts 'Skipping parallel inspection: only a single file needs inspection' if @options[:debug]
69
+ return
70
+ end
67
71
  puts 'Running parallel inspection' if @options[:debug]
68
72
  %i[autocorrect safe_autocorrect].each { |opt| @options[opt] = false }
69
73
  Parallel.each(target_files) { |target_file| file_offenses(target_file) }
@@ -62,17 +62,20 @@ module RuboCop
62
62
  # `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
63
63
  # so that only the necessary `CacheRootDirectory` can be obtained.
64
64
  require 'yaml'
65
-
66
65
  config_path = ConfigFinder.find_config_path(Dir.pwd)
67
66
 
68
- # Ruby 3.1+
69
- config_yaml = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('4.0.0')
70
- YAML.safe_load_file(config_path, permitted_classes: [Regexp, Symbol])
71
- else
72
- YAML.load_file(config_path)
73
- end
67
+ require 'erb'
68
+ file_contents = File.read(config_path)
69
+ yaml_code = ERB.new(file_contents).result
70
+
71
+ config_yaml = YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol])
72
+
73
+ # For compatibility with Ruby 3.0 or lower.
74
+ if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
75
+ config_yaml == false ? nil : config_yaml
76
+ end
74
77
 
75
- config_yaml.dig('AllCops', 'CacheRootDirectory')
78
+ config_yaml&.dig('AllCops', 'CacheRootDirectory')
76
79
  end
77
80
  end
78
81
 
@@ -3,11 +3,11 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.34.1'
6
+ STRING = '1.36.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
10
- 'running on %<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'
10
+ 'running on %<ruby_engine>s %<ruby_version>s)%<server>s [%<ruby_platform>s]'
11
11
 
12
12
  CANONICAL_FEATURE_NAMES = { 'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown',
13
13
  'Thread_safety' => 'ThreadSafety' }.freeze
@@ -19,6 +19,7 @@ module RuboCop
19
19
  verbose_version = format(MSG, version: STRING, parser_version: Parser::VERSION,
20
20
  rubocop_ast_version: RuboCop::AST::Version::STRING,
21
21
  ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
22
+ server: Server.running? ? ' +server' : '',
22
23
  ruby_platform: RUBY_PLATFORM)
23
24
  return verbose_version unless env
24
25
 
data/lib/rubocop.rb CHANGED
@@ -48,6 +48,7 @@ require_relative 'rubocop/cop/severity'
48
48
  require_relative 'rubocop/cop/generator'
49
49
  require_relative 'rubocop/cop/generator/configuration_injector'
50
50
  require_relative 'rubocop/cop/generator/require_file_injector'
51
+ require_relative 'rubocop/magic_comment'
51
52
 
52
53
  require_relative 'rubocop/cop/variable_force'
53
54
  require_relative 'rubocop/cop/variable_force/branch'
@@ -529,6 +530,7 @@ require_relative 'rubocop/cop/style/keyword_parameters_order'
529
530
  require_relative 'rubocop/cop/style/lambda'
530
531
  require_relative 'rubocop/cop/style/lambda_call'
531
532
  require_relative 'rubocop/cop/style/line_end_concatenation'
533
+ require_relative 'rubocop/cop/style/magic_comment_format'
532
534
  require_relative 'rubocop/cop/style/map_to_hash'
533
535
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
534
536
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
@@ -695,14 +697,13 @@ require_relative 'rubocop/lockfile'
695
697
  require_relative 'rubocop/target_finder'
696
698
  require_relative 'rubocop/directive_comment'
697
699
  require_relative 'rubocop/comment_config'
698
- require_relative 'rubocop/magic_comment'
699
700
  require_relative 'rubocop/result_cache'
700
701
  require_relative 'rubocop/runner'
701
702
  require_relative 'rubocop/cli'
702
703
  require_relative 'rubocop/cli/command'
703
704
  require_relative 'rubocop/cli/environment'
704
705
  require_relative 'rubocop/cli/command/base'
705
- require_relative 'rubocop/cli/command/auto_genenerate_config'
706
+ require_relative 'rubocop/cli/command/auto_generate_config'
706
707
  require_relative 'rubocop/cli/command/execute_runner'
707
708
  require_relative 'rubocop/cli/command/init_dotfile'
708
709
  require_relative 'rubocop/cli/command/show_cops'
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.34.1
4
+ version: 1.36.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: 2022-08-09 00:00:00.000000000 Z
13
+ date: 2022-09-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -120,7 +120,7 @@ dependencies:
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: 1.20.0
123
+ version: 1.20.1
124
124
  - - "<"
125
125
  - !ruby/object:Gem::Version
126
126
  version: '2.0'
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.20.0
133
+ version: 1.20.1
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '2.0'
@@ -212,7 +212,7 @@ files:
212
212
  - lib/rubocop/cached_data.rb
213
213
  - lib/rubocop/cli.rb
214
214
  - lib/rubocop/cli/command.rb
215
- - lib/rubocop/cli/command/auto_genenerate_config.rb
215
+ - lib/rubocop/cli/command/auto_generate_config.rb
216
216
  - lib/rubocop/cli/command/base.rb
217
217
  - lib/rubocop/cli/command/execute_runner.rb
218
218
  - lib/rubocop/cli/command/init_dotfile.rb
@@ -293,6 +293,7 @@ files:
293
293
  - lib/rubocop/cop/internal_affairs/node_destructuring.rb
294
294
  - lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
295
295
  - lib/rubocop/cop/internal_affairs/node_type_predicate.rb
296
+ - lib/rubocop/cop/internal_affairs/numblock_handler.rb
296
297
  - lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
297
298
  - lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb
298
299
  - lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
@@ -748,6 +749,7 @@ files:
748
749
  - lib/rubocop/cop/style/lambda.rb
749
750
  - lib/rubocop/cop/style/lambda_call.rb
750
751
  - lib/rubocop/cop/style/line_end_concatenation.rb
752
+ - lib/rubocop/cop/style/magic_comment_format.rb
751
753
  - lib/rubocop/cop/style/map_compact_with_conditional_block.rb
752
754
  - lib/rubocop/cop/style/map_to_hash.rb
753
755
  - lib/rubocop/cop/style/method_call_with_args_parentheses.rb
@@ -975,7 +977,7 @@ metadata:
975
977
  homepage_uri: https://rubocop.org/
976
978
  changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
977
979
  source_code_uri: https://github.com/rubocop/rubocop/
978
- documentation_uri: https://docs.rubocop.org/rubocop/1.34/
980
+ documentation_uri: https://docs.rubocop.org/rubocop/1.36/
979
981
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
980
982
  rubygems_mfa_required: 'true'
981
983
  post_install_message:
@@ -993,7 +995,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
993
995
  - !ruby/object:Gem::Version
994
996
  version: '0'
995
997
  requirements: []
996
- rubygems_version: 3.2.22
998
+ rubygems_version: 3.1.2
997
999
  signing_key:
998
1000
  specification_version: 4
999
1001
  summary: Automatic Ruby code style checking tool.