rubocop 1.85.0 → 1.85.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/cop/style/file_open.rb +28 -7
- data/lib/rubocop/cop/style/reduce_to_hash.rb +15 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
- data/lib/rubocop/formatter.rb +22 -21
- data/lib/rubocop/result_cache.rb +12 -9
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d0878d77ab8d3571eaa4e50ac6d4c89bac50ba7b36a740b944293dff7e60e3c5
|
|
4
|
+
data.tar.gz: 21f33042b5a670b5da1b58cbdee49a6250f537326881e34b2766c40a4d9a9f3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87cec420dd37c3c60d6112b9e6ced643ee22fb5b4c95148d714876fb0bfc8171634dd9b39ac6a0f7be7373e59c960a6bdbc74c01489daad3e9fcc7dbddb78e0d
|
|
7
|
+
data.tar.gz: 3f7c8637950adec215950b600ef61565b8847f1ba90f82f0ec9720ea6e7d4215f9d0312247324ea0976e4829b1bd3de3b11a4662d0a2a865433825d42779e7be
|
|
@@ -11,11 +11,17 @@ module RuboCop
|
|
|
11
11
|
# to resource exhaustion. Using the block form ensures the file is
|
|
12
12
|
# automatically closed when the block exits.
|
|
13
13
|
#
|
|
14
|
+
# This cop only registers an offense when the result of `File.open` is
|
|
15
|
+
# assigned to a variable or has a method chained on it, as those are the
|
|
16
|
+
# clearest indicators that the block form should be used instead. When
|
|
17
|
+
# `File.open` is used as a return value or passed as an argument, the
|
|
18
|
+
# caller is likely managing the file descriptor intentionally.
|
|
19
|
+
#
|
|
14
20
|
# @safety
|
|
15
|
-
# This cop is unsafe because it
|
|
16
|
-
#
|
|
17
|
-
# (`File.open("f").read`) where
|
|
18
|
-
# garbage collector.
|
|
21
|
+
# This cop is unsafe because it relies on syntax heuristics and cannot
|
|
22
|
+
# verify whether the file descriptor is safely managed. For example, it
|
|
23
|
+
# still flags intentional one-shot reads (`File.open("f").read`) where
|
|
24
|
+
# the file descriptor is closed by the garbage collector.
|
|
19
25
|
#
|
|
20
26
|
# @example
|
|
21
27
|
# # bad
|
|
@@ -32,6 +38,14 @@ module RuboCop
|
|
|
32
38
|
# # good
|
|
33
39
|
# File.open('file', &:read)
|
|
34
40
|
#
|
|
41
|
+
# # good - pass an open file object to an API that manages its lifecycle
|
|
42
|
+
# process(io: File.open('file'))
|
|
43
|
+
#
|
|
44
|
+
# # good - return an open file object for the caller to manage
|
|
45
|
+
# def json_key_io
|
|
46
|
+
# File.open('file')
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
35
49
|
# # good - use File.read for one-shot reads
|
|
36
50
|
# File.read('file')
|
|
37
51
|
#
|
|
@@ -46,7 +60,8 @@ module RuboCop
|
|
|
46
60
|
|
|
47
61
|
def on_send(node)
|
|
48
62
|
return unless file_open?(node)
|
|
49
|
-
return if
|
|
63
|
+
return if node.block_argument?
|
|
64
|
+
return unless offensive_usage?(node)
|
|
50
65
|
|
|
51
66
|
add_offense(node)
|
|
52
67
|
end
|
|
@@ -54,8 +69,14 @@ module RuboCop
|
|
|
54
69
|
|
|
55
70
|
private
|
|
56
71
|
|
|
57
|
-
def
|
|
58
|
-
|
|
72
|
+
def offensive_usage?(node)
|
|
73
|
+
return true unless node.value_used?
|
|
74
|
+
|
|
75
|
+
node.parent.assignment? || receiver_of_chained_call?(node)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def receiver_of_chained_call?(node)
|
|
79
|
+
node.parent.receiver == node
|
|
59
80
|
end
|
|
60
81
|
end
|
|
61
82
|
end
|
|
@@ -98,10 +98,25 @@ module RuboCop
|
|
|
98
98
|
inject_to_hash?(block_node)
|
|
99
99
|
end
|
|
100
100
|
return unless key
|
|
101
|
+
return if accumulator_used_in_expressions?(block_node, key, value)
|
|
101
102
|
|
|
102
103
|
register_offense(node, block_node, key, value)
|
|
103
104
|
end
|
|
104
105
|
|
|
106
|
+
def accumulator_used_in_expressions?(block_node, key, value)
|
|
107
|
+
acc_name = accumulator_name(block_node)
|
|
108
|
+
references_variable?(key, acc_name) || references_variable?(value, acc_name)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def accumulator_name(block_node)
|
|
112
|
+
index = block_node.method?(:each_with_object) ? 1 : 0
|
|
113
|
+
block_node.argument_list[index].name
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def references_variable?(node, name)
|
|
117
|
+
node.each_node(:lvar).any? { |lvar| lvar.children.first == name }
|
|
118
|
+
end
|
|
119
|
+
|
|
105
120
|
def register_offense(send_node, block_node, key_expr, value_expr)
|
|
106
121
|
message = format(MSG, method: send_node.method_name)
|
|
107
122
|
|
|
@@ -155,9 +155,7 @@ module RuboCop
|
|
|
155
155
|
return 'a literal' if node.literal? && disallowed_literal?(begin_node, node)
|
|
156
156
|
return 'a variable' if node.variable?
|
|
157
157
|
return 'a constant' if node.const_type?
|
|
158
|
-
if begin_node.parent&.any_block_type? &&
|
|
159
|
-
return 'block body'
|
|
160
|
-
end
|
|
158
|
+
return 'block body' if begin_node.parent&.any_block_type? && !node.range_type?
|
|
161
159
|
if node.assignment? && (begin_node.parent.nil? || begin_node.parent.begin_type?)
|
|
162
160
|
return 'an assignment'
|
|
163
161
|
end
|
data/lib/rubocop/formatter.rb
CHANGED
|
@@ -3,32 +3,33 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
# The bootstrap module for formatter.
|
|
5
5
|
module Formatter
|
|
6
|
-
|
|
6
|
+
autoload :Colorizable, 'rubocop/formatter/colorizable'
|
|
7
|
+
autoload :TextUtil, 'rubocop/formatter/text_util'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
autoload :BaseFormatter, 'rubocop/formatter/base_formatter'
|
|
10
|
+
autoload :SimpleTextFormatter, 'rubocop/formatter/simple_text_formatter'
|
|
10
11
|
|
|
11
12
|
# relies on simple text
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
autoload :ClangStyleFormatter, 'rubocop/formatter/clang_style_formatter'
|
|
14
|
+
autoload :DisabledConfigFormatter, 'rubocop/formatter/disabled_config_formatter'
|
|
15
|
+
autoload :EmacsStyleFormatter, 'rubocop/formatter/emacs_style_formatter'
|
|
16
|
+
autoload :FileListFormatter, 'rubocop/formatter/file_list_formatter'
|
|
17
|
+
autoload :FuubarStyleFormatter, 'rubocop/formatter/fuubar_style_formatter'
|
|
18
|
+
autoload :GitHubActionsFormatter, 'rubocop/formatter/github_actions_formatter'
|
|
19
|
+
autoload :HTMLFormatter, 'rubocop/formatter/html_formatter'
|
|
20
|
+
autoload :JSONFormatter, 'rubocop/formatter/json_formatter'
|
|
21
|
+
autoload :JUnitFormatter, 'rubocop/formatter/junit_formatter'
|
|
22
|
+
autoload :MarkdownFormatter, 'rubocop/formatter/markdown_formatter'
|
|
23
|
+
autoload :OffenseCountFormatter, 'rubocop/formatter/offense_count_formatter'
|
|
24
|
+
autoload :PacmanFormatter, 'rubocop/formatter/pacman_formatter'
|
|
25
|
+
autoload :ProgressFormatter, 'rubocop/formatter/progress_formatter'
|
|
26
|
+
autoload :QuietFormatter, 'rubocop/formatter/quiet_formatter'
|
|
27
|
+
autoload :TapFormatter, 'rubocop/formatter/tap_formatter'
|
|
28
|
+
autoload :WorstOffendersFormatter, 'rubocop/formatter/worst_offenders_formatter'
|
|
28
29
|
|
|
29
30
|
# relies on progress formatter
|
|
30
|
-
|
|
31
|
+
autoload :AutoGenConfigFormatter, 'rubocop/formatter/auto_gen_config_formatter'
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
autoload :FormatterSet, 'rubocop/formatter/formatter_set'
|
|
33
34
|
end
|
|
34
35
|
end
|
data/lib/rubocop/result_cache.rb
CHANGED
|
@@ -196,6 +196,17 @@ module RuboCop
|
|
|
196
196
|
end
|
|
197
197
|
end
|
|
198
198
|
|
|
199
|
+
# Return a hash of the options given at invocation, minus the ones that have
|
|
200
|
+
# no effect on which offenses and disabled line ranges are found, and thus
|
|
201
|
+
# don't affect caching.
|
|
202
|
+
def relevant_options_digest(options)
|
|
203
|
+
@relevant_options_digest ||= {}
|
|
204
|
+
@relevant_options_digest[options] ||= begin
|
|
205
|
+
options = options.reject { |key, _| NON_CHANGING.include?(key) }
|
|
206
|
+
options.to_s.gsub(/[^a-z]+/i, '_')
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
199
210
|
private
|
|
200
211
|
|
|
201
212
|
def digest(path)
|
|
@@ -227,20 +238,12 @@ module RuboCop
|
|
|
227
238
|
end
|
|
228
239
|
end
|
|
229
240
|
|
|
230
|
-
# Return a hash of the options given at invocation, minus the ones that have
|
|
231
|
-
# no effect on which offenses and disabled line ranges are found, and thus
|
|
232
|
-
# don't affect caching.
|
|
233
|
-
def relevant_options_digest(options)
|
|
234
|
-
options = options.reject { |key, _| NON_CHANGING.include?(key) }
|
|
235
|
-
options.to_s.gsub(/[^a-z]+/i, '_')
|
|
236
|
-
end
|
|
237
|
-
|
|
238
241
|
# We combine team and options into a single "context" checksum to avoid
|
|
239
242
|
# making file names that are too long for some filesystems to handle.
|
|
240
243
|
# This context is for anything that's not (1) the RuboCop executable
|
|
241
244
|
# checksum or (2) the inspected file checksum.
|
|
242
245
|
def context_checksum(team, options)
|
|
243
|
-
keys = [team.external_dependency_checksum, relevant_options_digest(options)]
|
|
246
|
+
keys = [team.external_dependency_checksum, self.class.relevant_options_digest(options)]
|
|
244
247
|
Digest::SHA1.hexdigest(keys.join)
|
|
245
248
|
end
|
|
246
249
|
end
|
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.85.
|
|
4
|
+
version: 1.85.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bozhidar Batsov
|
|
@@ -1128,7 +1128,7 @@ licenses:
|
|
|
1128
1128
|
- MIT
|
|
1129
1129
|
metadata:
|
|
1130
1130
|
homepage_uri: https://rubocop.org/
|
|
1131
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.85.
|
|
1131
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.85.1
|
|
1132
1132
|
source_code_uri: https://github.com/rubocop/rubocop/
|
|
1133
1133
|
documentation_uri: https://docs.rubocop.org/rubocop/1.85/
|
|
1134
1134
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|