rubocop 1.32.0 → 1.34.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +51 -16
  4. data/config/obsoletion.yml +23 -1
  5. data/lib/rubocop/cache_config.rb +29 -0
  6. data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
  7. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  8. data/lib/rubocop/cli/command/suggest_extensions.rb +53 -15
  9. data/lib/rubocop/config_finder.rb +68 -0
  10. data/lib/rubocop/config_loader.rb +12 -40
  11. data/lib/rubocop/config_loader_resolver.rb +1 -5
  12. data/lib/rubocop/config_obsoletion/changed_parameter.rb +5 -0
  13. data/lib/rubocop/config_obsoletion/parameter_rule.rb +4 -0
  14. data/lib/rubocop/config_obsoletion.rb +7 -2
  15. data/lib/rubocop/cop/cop.rb +1 -1
  16. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +28 -0
  17. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +61 -0
  18. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  19. data/lib/rubocop/cop/layout/block_end_newline.rb +33 -5
  20. data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
  21. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  22. data/lib/rubocop/cop/legacy/corrections_proxy.rb +1 -1
  23. data/lib/rubocop/cop/legacy/corrector.rb +1 -1
  24. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +21 -8
  25. data/lib/rubocop/cop/lint/debugger.rb +26 -16
  26. data/lib/rubocop/cop/lint/empty_conditional_body.rb +65 -1
  27. data/lib/rubocop/cop/lint/number_conversion.rb +24 -8
  28. data/lib/rubocop/cop/lint/shadowed_exception.rb +15 -0
  29. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +9 -1
  30. data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
  31. data/lib/rubocop/cop/metrics/block_length.rb +6 -7
  32. data/lib/rubocop/cop/metrics/method_length.rb +8 -8
  33. data/lib/rubocop/cop/mixin/allowed_methods.rb +15 -1
  34. data/lib/rubocop/cop/mixin/allowed_pattern.rb +9 -1
  35. data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
  36. data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -1
  37. data/lib/rubocop/cop/mixin/method_complexity.rb +4 -9
  38. data/lib/rubocop/cop/mixin/range_help.rb +2 -2
  39. data/lib/rubocop/cop/naming/predicate_name.rb +24 -3
  40. data/lib/rubocop/cop/style/block_delimiters.rb +26 -7
  41. data/lib/rubocop/cop/style/class_and_module_children.rb +4 -4
  42. data/lib/rubocop/cop/style/class_equality_comparison.rb +32 -7
  43. data/lib/rubocop/cop/style/double_negation.rb +2 -0
  44. data/lib/rubocop/cop/style/empty_heredoc.rb +15 -1
  45. data/lib/rubocop/cop/style/format_string_token.rb +21 -8
  46. data/lib/rubocop/cop/style/hash_except.rb +0 -4
  47. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
  48. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +5 -1
  49. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -7
  50. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -6
  51. data/lib/rubocop/cop/style/numeric_literals.rb +16 -1
  52. data/lib/rubocop/cop/style/numeric_predicate.rb +28 -8
  53. data/lib/rubocop/cop/style/redundant_condition.rb +19 -4
  54. data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -22
  55. data/lib/rubocop/cop/style/redundant_sort.rb +21 -6
  56. data/lib/rubocop/cop/style/sole_nested_conditional.rb +14 -3
  57. data/lib/rubocop/cop/style/symbol_proc.rb +34 -9
  58. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -13
  59. data/lib/rubocop/ext/range.rb +15 -0
  60. data/lib/rubocop/feature_loader.rb +90 -0
  61. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  62. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  63. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  64. data/lib/rubocop/formatter/markdown_formatter.rb +1 -1
  65. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  66. data/lib/rubocop/result_cache.rb +22 -20
  67. data/lib/rubocop/server/cache.rb +33 -1
  68. data/lib/rubocop/server/cli.rb +19 -2
  69. data/lib/rubocop/version.rb +1 -1
  70. data/lib/rubocop.rb +2 -1
  71. metadata +13 -9
  72. data/lib/rubocop/cop/mixin/ignored_methods.rb +0 -52
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
+ require_relative '../cache_config'
5
+ require_relative '../config_finder'
4
6
 
5
7
  #
6
8
  # This code is based on https://github.com/fohte/rubocop-daemon.
@@ -19,6 +21,8 @@ module RuboCop
19
21
  GEMFILE_NAMES = %w[Gemfile gems.rb].freeze
20
22
 
21
23
  class << self
24
+ attr_accessor :cache_root_path
25
+
22
26
  # Searches for Gemfile or gems.rb in the current dir or any parent dirs
23
27
  def project_dir
24
28
  current_dir = Dir.pwd
@@ -38,12 +42,40 @@ module RuboCop
38
42
  end
39
43
 
40
44
  def dir
41
- cache_path = File.expand_path('~/.cache/rubocop_cache/server')
42
45
  Pathname.new(File.join(cache_path, project_dir_cache_key)).tap do |d|
43
46
  d.mkpath unless d.exist?
44
47
  end
45
48
  end
46
49
 
50
+ def cache_path
51
+ cache_root_dir = if cache_root_path
52
+ File.join(cache_root_path, 'rubocop_cache')
53
+ else
54
+ cache_root_dir_from_config
55
+ end
56
+
57
+ File.expand_path(File.join(cache_root_dir, 'server'))
58
+ end
59
+
60
+ def cache_root_dir_from_config
61
+ CacheConfig.root_dir do
62
+ # `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
63
+ # so that only the necessary `CacheRootDirectory` can be obtained.
64
+ require 'yaml'
65
+
66
+ config_path = ConfigFinder.find_config_path(Dir.pwd)
67
+
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
74
+
75
+ config_yaml.dig('AllCops', 'CacheRootDirectory')
76
+ end
77
+ end
78
+
47
79
  def port_path
48
80
  dir.join('port')
49
81
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
4
3
  require 'rainbow'
5
4
 
6
5
  #
@@ -30,6 +29,7 @@ module RuboCop
30
29
  @exit = false
31
30
  end
32
31
 
32
+ # rubocop:disable Metrics/MethodLength
33
33
  def run(argv = ARGV)
34
34
  unless Server.support_server?
35
35
  return error('RuboCop server is not supported by this Ruby.') if use_server_option?(argv)
@@ -37,6 +37,7 @@ module RuboCop
37
37
  return STATUS_SUCCESS
38
38
  end
39
39
 
40
+ Cache.cache_root_path = fetch_cache_root_path_from(argv)
40
41
  deleted_server_arguments = delete_server_argument_from(argv)
41
42
 
42
43
  if deleted_server_arguments.size >= 2
@@ -45,7 +46,7 @@ module RuboCop
45
46
 
46
47
  server_command = deleted_server_arguments.first
47
48
 
48
- if EXCLUSIVE_OPTIONS.include?(server_command) && argv.count >= 2
49
+ if EXCLUSIVE_OPTIONS.include?(server_command) && argv.count > allowed_option_count
49
50
  return error("#{server_command} cannot be combined with other options.")
50
51
  end
51
52
 
@@ -53,6 +54,7 @@ module RuboCop
53
54
 
54
55
  STATUS_SUCCESS
55
56
  end
57
+ # rubocop:enable Metrics/MethodLength
56
58
 
57
59
  def exit?
58
60
  @exit
@@ -83,6 +85,17 @@ module RuboCop
83
85
  end
84
86
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength:
85
87
 
88
+ def fetch_cache_root_path_from(arguments)
89
+ cache_root = arguments.detect { |argument| argument.start_with?('--cache-root') }
90
+ return unless cache_root
91
+
92
+ if cache_root.start_with?('--cache-root=')
93
+ cache_root.split('=')[1]
94
+ else
95
+ arguments[arguments.index(cache_root) + 1]
96
+ end
97
+ end
98
+
86
99
  def delete_server_argument_from(all_arguments)
87
100
  SERVER_OPTIONS.each_with_object([]) do |server_option, server_arguments|
88
101
  server_arguments << all_arguments.delete(server_option)
@@ -93,6 +106,10 @@ module RuboCop
93
106
  (argv & SERVER_OPTIONS).any?
94
107
  end
95
108
 
109
+ def allowed_option_count
110
+ Cache.cache_root_path ? 2 : 1
111
+ end
112
+
96
113
  def error(message)
97
114
  @exit = true
98
115
  warn Rainbow(message).red
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.32.0'
6
+ STRING = '1.34.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
@@ -16,6 +16,7 @@ require 'rubocop-ast'
16
16
  require_relative 'rubocop/ast_aliases'
17
17
  require_relative 'rubocop/ext/regexp_node'
18
18
  require_relative 'rubocop/ext/regexp_parser'
19
+ require_relative 'rubocop/ext/range'
19
20
 
20
21
  require_relative 'rubocop/core_ext/string'
21
22
  require_relative 'rubocop/ext/processed_source'
@@ -86,7 +87,6 @@ require_relative 'rubocop/cop/mixin/gem_declaration'
86
87
  require_relative 'rubocop/cop/mixin/gemspec_help'
87
88
  require_relative 'rubocop/cop/mixin/hash_alignment_styles'
88
89
  require_relative 'rubocop/cop/mixin/hash_transform_method'
89
- require_relative 'rubocop/cop/mixin/ignored_methods'
90
90
  require_relative 'rubocop/cop/mixin/integer_node'
91
91
  require_relative 'rubocop/cop/mixin/interpolation'
92
92
  require_relative 'rubocop/cop/mixin/line_length_help'
@@ -690,6 +690,7 @@ require_relative 'rubocop/config_obsoletion/split_cop'
690
690
  require_relative 'rubocop/config_obsoletion'
691
691
  require_relative 'rubocop/config_store'
692
692
  require_relative 'rubocop/config_validator'
693
+ require_relative 'rubocop/feature_loader'
693
694
  require_relative 'rubocop/lockfile'
694
695
  require_relative 'rubocop/target_finder'
695
696
  require_relative 'rubocop/directive_comment'
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.32.0
4
+ version: 1.34.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: 2022-07-21 00:00:00.000000000 Z
13
+ date: 2022-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.1.0.0
49
+ version: 3.1.2.1
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 3.1.0.0
56
+ version: 3.1.2.1
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rainbow
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,7 @@ dependencies:
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: 1.19.1
123
+ version: 1.20.0
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.19.1
133
+ version: 1.20.0
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '2.0'
@@ -208,6 +208,7 @@ files:
208
208
  - exe/rubocop
209
209
  - lib/rubocop.rb
210
210
  - lib/rubocop/ast_aliases.rb
211
+ - lib/rubocop/cache_config.rb
211
212
  - lib/rubocop/cached_data.rb
212
213
  - lib/rubocop/cli.rb
213
214
  - lib/rubocop/cli/command.rb
@@ -222,6 +223,7 @@ files:
222
223
  - lib/rubocop/cli/environment.rb
223
224
  - lib/rubocop/comment_config.rb
224
225
  - lib/rubocop/config.rb
226
+ - lib/rubocop/config_finder.rb
225
227
  - lib/rubocop/config_loader.rb
226
228
  - lib/rubocop/config_loader_resolver.rb
227
229
  - lib/rubocop/config_obsoletion.rb
@@ -298,6 +300,7 @@ files:
298
300
  - lib/rubocop/cop/internal_affairs/redundant_location_argument.rb
299
301
  - lib/rubocop/cop/internal_affairs/redundant_message_argument.rb
300
302
  - lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb
303
+ - lib/rubocop/cop/internal_affairs/single_line_comparison.rb
301
304
  - lib/rubocop/cop/internal_affairs/style_detected_api_use.rb
302
305
  - lib/rubocop/cop/internal_affairs/undefined_config.rb
303
306
  - lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
@@ -581,7 +584,6 @@ files:
581
584
  - lib/rubocop/cop/mixin/hash_shorthand_syntax.rb
582
585
  - lib/rubocop/cop/mixin/hash_transform_method.rb
583
586
  - lib/rubocop/cop/mixin/heredoc.rb
584
- - lib/rubocop/cop/mixin/ignored_methods.rb
585
587
  - lib/rubocop/cop/mixin/integer_node.rb
586
588
  - lib/rubocop/cop/mixin/interpolation.rb
587
589
  - lib/rubocop/cop/mixin/line_length_help.rb
@@ -897,8 +899,10 @@ files:
897
899
  - lib/rubocop/directive_comment.rb
898
900
  - lib/rubocop/error.rb
899
901
  - lib/rubocop/ext/processed_source.rb
902
+ - lib/rubocop/ext/range.rb
900
903
  - lib/rubocop/ext/regexp_node.rb
901
904
  - lib/rubocop/ext/regexp_parser.rb
905
+ - lib/rubocop/feature_loader.rb
902
906
  - lib/rubocop/file_finder.rb
903
907
  - lib/rubocop/formatter.rb
904
908
  - lib/rubocop/formatter/auto_gen_config_formatter.rb
@@ -971,7 +975,7 @@ metadata:
971
975
  homepage_uri: https://rubocop.org/
972
976
  changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
973
977
  source_code_uri: https://github.com/rubocop/rubocop/
974
- documentation_uri: https://docs.rubocop.org/rubocop/1.32/
978
+ documentation_uri: https://docs.rubocop.org/rubocop/1.34/
975
979
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
976
980
  rubygems_mfa_required: 'true'
977
981
  post_install_message:
@@ -989,7 +993,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
989
993
  - !ruby/object:Gem::Version
990
994
  version: '0'
991
995
  requirements: []
992
- rubygems_version: 3.1.2
996
+ rubygems_version: 3.2.22
993
997
  signing_key:
994
998
  specification_version: 4
995
999
  summary: Automatic Ruby code style checking tool.
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- # This module encapsulates the ability to ignore certain methods when
6
- # parsing.
7
- # Cops that use `IgnoredMethods` can accept either strings or regexes to match
8
- # against.
9
- module IgnoredMethods
10
- # Configuration for IgnoredMethods. It is added to classes that include
11
- # the module so that configuration can be set using the `ignored_methods`
12
- # class macro.
13
- module Config
14
- attr_accessor :deprecated_key
15
-
16
- def ignored_methods(**config)
17
- self.deprecated_key = config[:deprecated_key]
18
- end
19
- end
20
-
21
- def self.included(base)
22
- base.extend(Config)
23
- end
24
-
25
- def ignored_method?(name)
26
- ignored_methods.any? do |value|
27
- case value
28
- when Regexp
29
- value.match? String(name)
30
- else
31
- value == String(name)
32
- end
33
- end
34
- end
35
-
36
- def ignored_methods
37
- keys = %w[IgnoredMethods]
38
- keys << deprecated_key if deprecated_key
39
-
40
- cop_config.slice(*keys).values.reduce(&:concat)
41
- end
42
-
43
- private
44
-
45
- def deprecated_key
46
- return unless self.class.respond_to?(:deprecated_key)
47
-
48
- self.class.deprecated_key&.to_s
49
- end
50
- end
51
- end
52
- end