rubocop 1.66.0 → 1.66.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.
- checksums.yaml +4 -4
- data/lib/rubocop/comment_config.rb +4 -8
- data/lib/rubocop/config.rb +4 -16
- data/lib/rubocop/config_loader.rb +14 -8
- data/lib/rubocop/config_validator.rb +5 -9
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/style/empty_else.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +9 -2
- data/lib/rubocop/cop/style/magic_comment_format.rb +3 -8
- data/lib/rubocop/cop/style/map_into_array.rb +1 -3
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop/yaml_duplication_checker.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a10568527197e80492a28c5b524fa524dbce965513daff4f47e260e03b49d98
|
4
|
+
data.tar.gz: 8ea447437cbd36aa805b3941cf51b07eecc9dc538ed6a4584f09a1335e21cb48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f292c70ffac1cb186e5be899582c4849a29866722c87ab92a60a723dd16fe86fdf12073c8a7190bba197d246eae3b25ba3cdc6b586b28061cef39ac22b3b438
|
7
|
+
data.tar.gz: 2dbfc28779854fae0d28fd266ba269b92cb0e3b5c26200aa250df02ff9810804b7b1fcc289a43bac1913dc04c79f788487f9351444f7242cbcdad6854a821d69
|
@@ -4,6 +4,8 @@ module RuboCop
|
|
4
4
|
# This class parses the special `rubocop:disable` comments in a source
|
5
5
|
# and provides a way to check if each cop is enabled at arbitrary line.
|
6
6
|
class CommentConfig
|
7
|
+
extend SimpleForwardable
|
8
|
+
|
7
9
|
CONFIG_DISABLED_LINE_RANGE_MIN = -Float::INFINITY
|
8
10
|
|
9
11
|
# This class provides an API compatible with RuboCop::DirectiveComment
|
@@ -27,19 +29,13 @@ module RuboCop
|
|
27
29
|
|
28
30
|
attr_reader :processed_source
|
29
31
|
|
32
|
+
def_delegators :@processed_source, :config, :registry
|
33
|
+
|
30
34
|
def initialize(processed_source)
|
31
35
|
@processed_source = processed_source
|
32
36
|
@no_directives = !processed_source.raw_source.include?('rubocop')
|
33
37
|
end
|
34
38
|
|
35
|
-
def config
|
36
|
-
@processed_source.config
|
37
|
-
end
|
38
|
-
|
39
|
-
def registry
|
40
|
-
@processed_source.registry
|
41
|
-
end
|
42
|
-
|
43
39
|
def cop_enabled_at_line?(cop, line_number)
|
44
40
|
cop = cop.cop_name if cop.respond_to?(:cop_name)
|
45
41
|
disabled_line_ranges = cop_disabled_line_ranges[cop]
|
data/lib/rubocop/config.rb
CHANGED
@@ -12,6 +12,7 @@ module RuboCop
|
|
12
12
|
class Config
|
13
13
|
include PathUtil
|
14
14
|
include FileFinder
|
15
|
+
extend SimpleForwardable
|
15
16
|
|
16
17
|
CopConfig = Struct.new(:name, :metadata)
|
17
18
|
|
@@ -59,22 +60,9 @@ module RuboCop
|
|
59
60
|
self
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
def #{method}(...) # def key?(...)
|
66
|
-
@hash.#{method}(...) # @hash.key?(...)
|
67
|
-
end # end
|
68
|
-
RUBY
|
69
|
-
end
|
70
|
-
|
71
|
-
def validate(...)
|
72
|
-
@validator.validate(...)
|
73
|
-
end
|
74
|
-
|
75
|
-
def target_ruby_version
|
76
|
-
@validator.target_ruby_version
|
77
|
-
end
|
63
|
+
def_delegators :@hash, :[], :[]=, :delete, :dig, :each, :key?, :keys, :each_key,
|
64
|
+
:fetch, :map, :merge, :replace, :to_h, :to_hash, :transform_values
|
65
|
+
def_delegators :@validator, :validate, :target_ruby_version
|
78
66
|
|
79
67
|
def to_s
|
80
68
|
@to_s ||= @hash.to_s
|
@@ -67,8 +67,8 @@ module RuboCop
|
|
67
67
|
def load_yaml_configuration(absolute_path)
|
68
68
|
file_contents = read_file(absolute_path)
|
69
69
|
yaml_code = Dir.chdir(File.dirname(absolute_path)) { ERB.new(file_contents).result }
|
70
|
-
check_duplication(yaml_code, absolute_path)
|
71
|
-
hash =
|
70
|
+
yaml_tree = check_duplication(yaml_code, absolute_path)
|
71
|
+
hash = yaml_tree_to_hash(yaml_tree) || {}
|
72
72
|
|
73
73
|
puts "configuration from #{absolute_path}" if debug?
|
74
74
|
|
@@ -235,8 +235,8 @@ module RuboCop
|
|
235
235
|
raise ConfigNotFoundError, "Configuration file not found: #{absolute_path}"
|
236
236
|
end
|
237
237
|
|
238
|
-
def
|
239
|
-
|
238
|
+
def yaml_tree_to_hash(yaml_tree)
|
239
|
+
yaml_tree_to_hash!(yaml_tree)
|
240
240
|
rescue ::StandardError
|
241
241
|
if defined?(::SafeYAML)
|
242
242
|
raise 'SafeYAML is unmaintained, no longer needed and should be removed'
|
@@ -245,10 +245,16 @@ module RuboCop
|
|
245
245
|
raise
|
246
246
|
end
|
247
247
|
|
248
|
-
def
|
249
|
-
|
250
|
-
|
251
|
-
|
248
|
+
def yaml_tree_to_hash!(yaml_tree)
|
249
|
+
return nil unless yaml_tree
|
250
|
+
|
251
|
+
# Optimization: Because we checked for duplicate keys, we already have the
|
252
|
+
# yaml tree and don't need to parse it again.
|
253
|
+
# Also see https://github.com/ruby/psych/blob/v5.1.2/lib/psych.rb#L322-L336
|
254
|
+
class_loader = YAML::ClassLoader::Restricted.new(%w[Regexp Symbol], [])
|
255
|
+
scanner = YAML::ScalarScanner.new(class_loader)
|
256
|
+
visitor = YAML::Visitors::ToRuby.new(scanner, class_loader)
|
257
|
+
visitor.accept(yaml_tree)
|
252
258
|
end
|
253
259
|
end
|
254
260
|
|
@@ -3,7 +3,9 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# Handles validation of configuration, for example cop names, parameter
|
5
5
|
# names, and Ruby versions.
|
6
|
-
class ConfigValidator
|
6
|
+
class ConfigValidator
|
7
|
+
extend SimpleForwardable
|
8
|
+
|
7
9
|
# @api private
|
8
10
|
COMMON_PARAMS = %w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details].freeze
|
9
11
|
# @api private
|
@@ -19,20 +21,14 @@ module RuboCop
|
|
19
21
|
CONFIG_CHECK_AUTOCORRECTS = %w[always contextual disabled].freeze
|
20
22
|
private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS
|
21
23
|
|
24
|
+
def_delegators :@config, :smart_loaded_path, :for_all_cops
|
25
|
+
|
22
26
|
def initialize(config)
|
23
27
|
@config = config
|
24
28
|
@config_obsoletion = ConfigObsoletion.new(config)
|
25
29
|
@target_ruby = TargetRuby.new(config)
|
26
30
|
end
|
27
31
|
|
28
|
-
def smart_loaded_path
|
29
|
-
@config.smart_loaded_path
|
30
|
-
end
|
31
|
-
|
32
|
-
def for_all_cops
|
33
|
-
@config.for_all_cops
|
34
|
-
end
|
35
|
-
|
36
32
|
def validate
|
37
33
|
check_cop_config_value(@config)
|
38
34
|
reject_conflicting_safe_settings
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
def_node_matcher :array_node, '(send (const {nil? cbase} :Array) :new (array)?)'
|
35
35
|
|
36
36
|
# @!method hash_node(node)
|
37
|
-
def_node_matcher :hash_node, '(send (const {nil? cbase} :Hash) :new
|
37
|
+
def_node_matcher :hash_node, '(send (const {nil? cbase} :Hash) :new)'
|
38
38
|
|
39
39
|
# @!method str_node(node)
|
40
40
|
def_node_matcher :str_node, '(send (const {nil? cbase} :String) :new)'
|
@@ -36,10 +36,12 @@ module RuboCop
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
39
40
|
def message(node)
|
40
41
|
template = if node.if_branch&.begin_type?
|
41
42
|
MSG_NEWLINE
|
42
|
-
elsif node.else_branch&.if_type? || node.else_branch&.begin_type?
|
43
|
+
elsif node.else_branch&.if_type? || node.else_branch&.begin_type? ||
|
44
|
+
use_block_in_branches?(node)
|
43
45
|
MSG_IF_ELSE
|
44
46
|
else
|
45
47
|
MSG_TERNARY
|
@@ -47,15 +49,20 @@ module RuboCop
|
|
47
49
|
|
48
50
|
format(template, expr: node.condition.source)
|
49
51
|
end
|
52
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
50
53
|
|
51
54
|
def autocorrect(corrector, node)
|
52
|
-
if node.
|
55
|
+
if node.branches.compact.any?(&:begin_type?) || use_block_in_branches?(node)
|
53
56
|
corrector.replace(node.loc.begin, "\n")
|
54
57
|
else
|
55
58
|
corrector.replace(node, replacement(node))
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
62
|
+
def use_block_in_branches?(node)
|
63
|
+
node.branches.compact.any? { |branch| branch.block_type? || branch.numblock_type? }
|
64
|
+
end
|
65
|
+
|
59
66
|
def replacement(node)
|
60
67
|
return correct_elsif(node) if node.else_branch&.if_type?
|
61
68
|
|
@@ -105,26 +105,21 @@ module RuboCop
|
|
105
105
|
|
106
106
|
# Value object to extract source ranges for the different parts of a magic comment
|
107
107
|
class CommentRange
|
108
|
+
extend SimpleForwardable
|
109
|
+
|
108
110
|
DIRECTIVE_REGEXP = Regexp.union(MagicComment::KEYWORDS.map do |_, v|
|
109
111
|
Regexp.new(v, Regexp::IGNORECASE)
|
110
112
|
end).freeze
|
111
113
|
|
112
114
|
VALUE_REGEXP = Regexp.new("(?:#{DIRECTIVE_REGEXP}:\s*)(.*?)(?=;|$)")
|
113
115
|
|
116
|
+
def_delegators :@comment, :text, :loc
|
114
117
|
attr_reader :comment
|
115
118
|
|
116
119
|
def initialize(comment)
|
117
120
|
@comment = comment
|
118
121
|
end
|
119
122
|
|
120
|
-
def text
|
121
|
-
@comment.text
|
122
|
-
end
|
123
|
-
|
124
|
-
def loc
|
125
|
-
@comment.loc
|
126
|
-
end
|
127
|
-
|
128
123
|
# A magic comment can contain one directive (normal style) or
|
129
124
|
# multiple directives (emacs style)
|
130
125
|
def directives
|
@@ -147,10 +147,8 @@ module RuboCop
|
|
147
147
|
false
|
148
148
|
when :begin, :kwbegin
|
149
149
|
!node.right_sibling && return_value_used?(parent)
|
150
|
-
when :block, :numblock
|
151
|
-
!parent.void_context?
|
152
150
|
else
|
153
|
-
|
151
|
+
!parent.respond_to?(:void_context?) || !parent.void_context?
|
154
152
|
end
|
155
153
|
end
|
156
154
|
|
data/lib/rubocop/version.rb
CHANGED
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.66.
|
4
|
+
version: 1.66.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: 2024-
|
13
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.32.
|
117
|
+
version: 1.32.2
|
118
118
|
- - "<"
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '2.0'
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
requirements:
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: 1.32.
|
127
|
+
version: 1.32.2
|
128
128
|
- - "<"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '2.0'
|
@@ -1017,7 +1017,7 @@ licenses:
|
|
1017
1017
|
- MIT
|
1018
1018
|
metadata:
|
1019
1019
|
homepage_uri: https://rubocop.org/
|
1020
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.66.
|
1020
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.66.1
|
1021
1021
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1022
1022
|
documentation_uri: https://docs.rubocop.org/rubocop/1.66/
|
1023
1023
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|