rubocop 1.37.0 → 1.37.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cli/command/suggest_extensions.rb +8 -1
- data/lib/rubocop/cop/internal_affairs/create_empty_file.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +111 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/collection_compact.rb +3 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +2 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +13 -5
- data/lib/rubocop/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf1d6d45b2da199a82152b2c5b20ffa6a5f99df5115dbd8fbf4c4e895fd00c5
|
4
|
+
data.tar.gz: 50520bd1d5496971e8b38347dfea57a3387a372b7a815b3c9ef2eb7c1fdc448a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa612429aa29b3ce4480fbbc7d77f1efc6862ac89098bfadf7c8f79a4e255709f6752f1b1075497b9ad17aa261afa006089152d10e0deb4f4361bce95537999
|
7
|
+
data.tar.gz: b55827239ce8508d6f884f03838c7fe8ca89268c93ac7ab88409af176e527c74d0d24a14680fa3c7c84353eb078a97699429015b69e6efdb051582914d37ff30
|
@@ -73,7 +73,14 @@ module RuboCop
|
|
73
73
|
def all_extensions
|
74
74
|
return [] unless lockfile.dependencies.any?
|
75
75
|
|
76
|
-
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
|
76
|
+
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
|
77
|
+
case extensions
|
78
|
+
when true
|
79
|
+
extensions = ConfigLoader.default_configuration.for_all_cops['SuggestExtensions']
|
80
|
+
when false, nil
|
81
|
+
extensions = {}
|
82
|
+
end
|
83
|
+
|
77
84
|
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
|
78
85
|
end
|
79
86
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for uses of `create_file` with empty string second argument.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# create_file(path, '')
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# create_empty_file(path)
|
15
|
+
#
|
16
|
+
class CreateEmptyFile < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Use `%<replacement>s`.'
|
20
|
+
RESTRICT_ON_SEND = %i[create_file].freeze
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
return if node.receiver
|
24
|
+
return unless (argument = node.arguments[1])
|
25
|
+
return unless argument.str_type? && argument.value.empty?
|
26
|
+
|
27
|
+
replacement = "create_empty_file(#{node.first_argument.source})"
|
28
|
+
message = format(MSG, replacement: replacement)
|
29
|
+
|
30
|
+
add_offense(node, message: message) do |corrector|
|
31
|
+
corrector.replace(node, replacement)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Use `RUBY` for heredoc delimiter of example Ruby code.
|
7
|
+
#
|
8
|
+
# Some editors may apply better syntax highlighting by using appropriate language names for
|
9
|
+
# the delimiter.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# expect_offense(<<~CODE)
|
14
|
+
# example_ruby_code
|
15
|
+
# CODE
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# expect_offense(<<~RUBY)
|
19
|
+
# example_ruby_code
|
20
|
+
# RUBY
|
21
|
+
class ExampleHeredocDelimiter < Base
|
22
|
+
extend AutoCorrector
|
23
|
+
|
24
|
+
EXPECTED_HEREDOC_DELIMITER = 'RUBY'
|
25
|
+
|
26
|
+
MSG = 'Use `RUBY` for heredoc delimiter of example Ruby code.'
|
27
|
+
|
28
|
+
RESTRICT_ON_SEND = %i[
|
29
|
+
expect_correction
|
30
|
+
expect_no_corrections
|
31
|
+
expect_no_offenses
|
32
|
+
expect_offense
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
# @param node [RuboCop::AST::SendNode]
|
36
|
+
# @return [void]
|
37
|
+
def on_send(node)
|
38
|
+
heredoc_node = heredoc_node_from(node)
|
39
|
+
return unless heredoc_node
|
40
|
+
return if expected_heredoc_delimiter?(heredoc_node)
|
41
|
+
return if expected_heredoc_delimiter_in_body?(heredoc_node)
|
42
|
+
|
43
|
+
add_offense(heredoc_node) do |corrector|
|
44
|
+
autocorrect(corrector, heredoc_node)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @param corrector [RuboCop::Cop::Corrector]
|
51
|
+
# @param node [RuboCop::AST::StrNode]
|
52
|
+
# @return [void]
|
53
|
+
def autocorrect(corrector, node)
|
54
|
+
[
|
55
|
+
heredoc_openning_delimiter_range_from(node),
|
56
|
+
heredoc_closing_delimiter_range_from(node)
|
57
|
+
].each do |range|
|
58
|
+
corrector.replace(range, EXPECTED_HEREDOC_DELIMITER)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param node [RuboCop::AST::StrNode]
|
63
|
+
# @return [Boolean]
|
64
|
+
def expected_heredoc_delimiter_in_body?(node)
|
65
|
+
node.location.heredoc_body.source.lines.any? do |line|
|
66
|
+
line.strip == EXPECTED_HEREDOC_DELIMITER
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param node [RuboCop::AST::StrNode]
|
71
|
+
# @return [Boolean]
|
72
|
+
def expected_heredoc_delimiter?(node)
|
73
|
+
heredoc_delimiter_string_from(node) == EXPECTED_HEREDOC_DELIMITER
|
74
|
+
end
|
75
|
+
|
76
|
+
# @param node [RuboCop::AST::SendNode]
|
77
|
+
# @return [RuboCop::AST::StrNode, nil]
|
78
|
+
def heredoc_node_from(node)
|
79
|
+
return unless node.first_argument.respond_to?(:heredoc?)
|
80
|
+
return unless node.first_argument.heredoc?
|
81
|
+
|
82
|
+
node.first_argument
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param node [RuboCop::AST::StrNode]
|
86
|
+
# @return [String]
|
87
|
+
def heredoc_delimiter_string_from(node)
|
88
|
+
node.source[Heredoc::OPENING_DELIMITER, 2]
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param node [RuboCop::AST::StrNode]
|
92
|
+
# @return [Parser::Source::Range]
|
93
|
+
def heredoc_openning_delimiter_range_from(node)
|
94
|
+
match_data = node.source.match(Heredoc::OPENING_DELIMITER)
|
95
|
+
node.location.expression.begin.adjust(
|
96
|
+
begin_pos: match_data.begin(2),
|
97
|
+
end_pos: match_data.end(2)
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @param node [RuboCop::AST::StrNode]
|
102
|
+
# @return [Parser::Source::Range]
|
103
|
+
def heredoc_closing_delimiter_range_from(node)
|
104
|
+
node.location.heredoc_end.end.adjust(
|
105
|
+
begin_pos: -heredoc_delimiter_string_from(node).length
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'internal_affairs/cop_description'
|
4
|
+
require_relative 'internal_affairs/create_empty_file'
|
4
5
|
require_relative 'internal_affairs/empty_line_between_expect_offense_and_correction'
|
5
6
|
require_relative 'internal_affairs/example_description'
|
7
|
+
require_relative 'internal_affairs/example_heredoc_delimiter'
|
6
8
|
require_relative 'internal_affairs/inherit_deprecated_cop_class'
|
7
9
|
require_relative 'internal_affairs/location_line_equality_comparison'
|
8
10
|
require_relative 'internal_affairs/method_name_end_with'
|
@@ -85,6 +85,8 @@ module RuboCop
|
|
85
85
|
|
86
86
|
RESTRICT_ON_SEND = %i[private protected public module_function].freeze
|
87
87
|
|
88
|
+
ALLOWED_NODE_TYPES = %i[pair block].freeze
|
89
|
+
|
88
90
|
# @!method access_modifier_with_symbol?(node)
|
89
91
|
def_node_matcher :access_modifier_with_symbol?, <<~PATTERN
|
90
92
|
(send nil? {:private :protected :public :module_function} (sym _))
|
@@ -92,7 +94,7 @@ module RuboCop
|
|
92
94
|
|
93
95
|
def on_send(node)
|
94
96
|
return unless node.access_modifier?
|
95
|
-
return if node.parent&.
|
97
|
+
return if ALLOWED_NODE_TYPES.include?(node.parent&.type)
|
96
98
|
return if allow_modifiers_on_symbols?(node)
|
97
99
|
|
98
100
|
if offense?(node)
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
|
30
30
|
def offense?(node)
|
31
31
|
# we don't register an offense for things like ?\C-\M-d
|
32
|
-
node.
|
32
|
+
node.character_literal? && node.source.size.between?(2, 3)
|
33
33
|
end
|
34
34
|
|
35
35
|
def autocorrect(corrector, node)
|
@@ -96,7 +96,9 @@ module RuboCop
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def to_enum_method?(node)
|
99
|
-
|
99
|
+
return false unless node.receiver.send_type?
|
100
|
+
|
101
|
+
TO_ENUM_METHODS.include?(node.receiver.method_name)
|
100
102
|
end
|
101
103
|
|
102
104
|
def good_method_name(node)
|
@@ -25,9 +25,10 @@ module RuboCop
|
|
25
25
|
|
26
26
|
def on_send(node)
|
27
27
|
return unless (dot = node.loc.dot)
|
28
|
+
return if node.receiver.const_type?
|
28
29
|
|
29
30
|
_lhs, _op, rhs = *node
|
30
|
-
return if rhs.children.first
|
31
|
+
return if rhs.nil? || rhs.children.first
|
31
32
|
|
32
33
|
add_offense(dot) do |corrector|
|
33
34
|
corrector.replace(dot, ' ')
|
@@ -42,10 +42,9 @@ module RuboCop
|
|
42
42
|
MSG = 'Redundant escape of %<char>s inside string literal.'
|
43
43
|
|
44
44
|
def on_str(node)
|
45
|
-
return if node.parent&.regexp_type? || node.parent&.xstr_type?
|
45
|
+
return if node.parent&.regexp_type? || node.parent&.xstr_type? || node.character_literal?
|
46
46
|
|
47
47
|
str_contents_range = str_contents_range(node)
|
48
|
-
return unless str_contents_range.source.include?('\\')
|
49
48
|
|
50
49
|
each_match_range(str_contents_range, /(\\.)/) do |range|
|
51
50
|
next if allowed_escape?(node, range.resize(3))
|
@@ -91,9 +90,7 @@ module RuboCop
|
|
91
90
|
|
92
91
|
return true if escaped[0] == ' ' && percent_array_literal?(node)
|
93
92
|
|
94
|
-
|
95
|
-
# variable interpolations inside
|
96
|
-
return true if /\A#[{$@]/.match?(escaped)
|
93
|
+
return true if disabling_interpolation?(range)
|
97
94
|
return true if delimiter?(node, escaped[0])
|
98
95
|
|
99
96
|
false
|
@@ -167,6 +164,17 @@ module RuboCop
|
|
167
164
|
def literal_in_interpolated_or_multiline_string?(node)
|
168
165
|
node.str_type? && !begin_loc_present?(node) && node.parent&.dstr_type?
|
169
166
|
end
|
167
|
+
|
168
|
+
def disabling_interpolation?(range)
|
169
|
+
# Allow \#{foo}, \#$foo, \#@foo, and \#@@foo
|
170
|
+
# for escaping local, global, instance and class variable interpolations
|
171
|
+
return true if range.source.match?(/\A\\#[{$@]/)
|
172
|
+
|
173
|
+
# Also allow #\{foo}, #\$foo, #\@foo and #\@@foo
|
174
|
+
return true if range.adjust(begin_pos: -2).source.match?(/\A[^\\]#\\[{$@]/)
|
175
|
+
|
176
|
+
false
|
177
|
+
end
|
170
178
|
end
|
171
179
|
end
|
172
180
|
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.37.
|
4
|
+
version: 1.37.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-10-
|
13
|
+
date: 2022-10-24 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.
|
123
|
+
version: 1.23.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.
|
133
|
+
version: 1.23.0
|
134
134
|
- - "<"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '2.0'
|
@@ -286,8 +286,10 @@ files:
|
|
286
286
|
- lib/rubocop/cop/ignored_node.rb
|
287
287
|
- lib/rubocop/cop/internal_affairs.rb
|
288
288
|
- lib/rubocop/cop/internal_affairs/cop_description.rb
|
289
|
+
- lib/rubocop/cop/internal_affairs/create_empty_file.rb
|
289
290
|
- lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb
|
290
291
|
- lib/rubocop/cop/internal_affairs/example_description.rb
|
292
|
+
- lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb
|
291
293
|
- lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb
|
292
294
|
- lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb
|
293
295
|
- lib/rubocop/cop/internal_affairs/method_name_end_with.rb
|