rbhint 0.8.5.rc1 → 0.85.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rbhint/version.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +33 -2
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/utils/format_string.rb +18 -0
- 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: fd891aa24d19c875913eea3b0955d179e0755ff691e7f7b79dbc297e97a2970f
|
4
|
+
data.tar.gz: be6d7b62c97c7da10a6b2e0862f012eeacd50c6f33b5ab92fee1af27cd76be20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1029fa48c588e4c8b393917d72a1c717120e5ef262dcadeae0db9969e99feb8ca1d17abc0e281a64cf166499483543b31510f09df405e31a441db6497f8c5cd3
|
7
|
+
data.tar.gz: a49e77b5ff8ac7bec74499e55d61c63d506aad88c31ccee30572c235a49eb1cd816eb72ae3da8e3e68139284c9c4ae9f4963b0174ac0908e074f07f2bdada15d
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RbHint update you
|
|
40
40
|
might want to use a conservative version lock in your `Gemfile`:
|
41
41
|
|
42
42
|
```rb
|
43
|
-
gem 'rbhint', '~> 0.85.
|
43
|
+
gem 'rbhint', '~> 0.85.1.rc1', require: false
|
44
44
|
```
|
45
45
|
|
46
46
|
## Quickstart
|
data/lib/rbhint/version.rb
CHANGED
@@ -147,7 +147,7 @@ module RuboCop
|
|
147
147
|
def indent_level(str)
|
148
148
|
indentations = str.lines
|
149
149
|
.map { |line| line[/^\s*/] }
|
150
|
-
.reject { |line| line
|
150
|
+
.reject { |line| line.end_with?("\n") }
|
151
151
|
indentations.empty? ? 0 : indentations.min_by(&:size).size
|
152
152
|
end
|
153
153
|
|
@@ -7,6 +7,10 @@ module RuboCop
|
|
7
7
|
# expected fields for format/sprintf/#% and what is actually
|
8
8
|
# passed as arguments.
|
9
9
|
#
|
10
|
+
# In addition it checks whether different formats are used in the same
|
11
|
+
# format string. Do not mix numbered, unnumbered, and named formats in
|
12
|
+
# the same format string.
|
13
|
+
#
|
10
14
|
# @example
|
11
15
|
#
|
12
16
|
# # bad
|
@@ -18,16 +22,37 @@ module RuboCop
|
|
18
22
|
# # good
|
19
23
|
#
|
20
24
|
# format('A value: %s and another: %i', a_value, another)
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
#
|
28
|
+
# # bad
|
29
|
+
#
|
30
|
+
# format('Unnumbered format: %s and numbered: %2$s', a_value, another)
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
#
|
36
|
+
# format('Numbered format: %1$s and numbered %2$s', a_value, another)
|
21
37
|
class FormatParameterMismatch < Cop
|
22
38
|
# http://rubular.com/r/CvpbxkcTzy
|
23
39
|
MSG = "Number of arguments (%<arg_num>i) to `%<method>s` doesn't " \
|
24
40
|
'match the number of fields (%<field_num>i).'
|
41
|
+
MSG_INVALID = 'Format string is invalid because formatting sequence types ' \
|
42
|
+
'(numbered, named or unnumbered) are mixed.'
|
25
43
|
|
26
44
|
KERNEL = 'Kernel'
|
27
45
|
SHOVEL = '<<'
|
28
46
|
STRING_TYPES = %i[str dstr].freeze
|
29
47
|
|
30
48
|
def on_send(node)
|
49
|
+
return unless format_string?(node)
|
50
|
+
|
51
|
+
if invalid_format_string?(node)
|
52
|
+
add_offense(node, location: :selector, message: MSG_INVALID)
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
31
56
|
return unless offending_node?(node)
|
32
57
|
|
33
58
|
add_offense(node, location: :selector)
|
@@ -35,9 +60,15 @@ module RuboCop
|
|
35
60
|
|
36
61
|
private
|
37
62
|
|
63
|
+
def format_string?(node)
|
64
|
+
called_on_string?(node) && method_with_format_args?(node)
|
65
|
+
end
|
66
|
+
|
67
|
+
def invalid_format_string?(node)
|
68
|
+
!RuboCop::Cop::Utils::FormatString.new(node.source).valid?
|
69
|
+
end
|
70
|
+
|
38
71
|
def offending_node?(node)
|
39
|
-
return false unless called_on_string?(node)
|
40
|
-
return false unless method_with_format_args?(node)
|
41
72
|
return false if splat_args?(node)
|
42
73
|
|
43
74
|
num_of_format_args, num_of_expected_fields = count_matches(node)
|
@@ -27,7 +27,8 @@ module RuboCop
|
|
27
27
|
class RedundantConditional < Cop
|
28
28
|
include Alignment
|
29
29
|
|
30
|
-
|
30
|
+
operators = RuboCop::AST::Node::COMPARISON_OPERATORS.to_a
|
31
|
+
COMPARISON_OPERATOR_MATCHER = "{:#{operators.join(' :')}}"
|
31
32
|
|
32
33
|
MSG = 'This conditional expression can just be replaced ' \
|
33
34
|
'by `%<msg>s`.'
|
@@ -54,11 +55,11 @@ module RuboCop
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def_node_matcher :redundant_condition?, <<~RUBY
|
57
|
-
(if (send _ {
|
58
|
+
(if (send _ #{COMPARISON_OPERATOR_MATCHER} _) true false)
|
58
59
|
RUBY
|
59
60
|
|
60
61
|
def_node_matcher :redundant_condition_inverted?, <<~RUBY
|
61
|
-
(if (send _ {
|
62
|
+
(if (send _ #{COMPARISON_OPERATOR_MATCHER} _) false true)
|
62
63
|
RUBY
|
63
64
|
|
64
65
|
def offense?(node)
|
@@ -97,6 +97,10 @@ module RuboCop
|
|
97
97
|
@format_sequences ||= parse
|
98
98
|
end
|
99
99
|
|
100
|
+
def valid?
|
101
|
+
!mixed_formats?
|
102
|
+
end
|
103
|
+
|
100
104
|
def named_interpolation?
|
101
105
|
format_sequences.any?(&:name)
|
102
106
|
end
|
@@ -114,6 +118,20 @@ module RuboCop
|
|
114
118
|
)
|
115
119
|
end
|
116
120
|
end
|
121
|
+
|
122
|
+
def mixed_formats?
|
123
|
+
formats = format_sequences.map do |seq|
|
124
|
+
if seq.name
|
125
|
+
:named
|
126
|
+
elsif seq.max_digit_dollar_num
|
127
|
+
:numbered
|
128
|
+
else
|
129
|
+
:unnumbered
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
formats.uniq.size > 1
|
134
|
+
end
|
117
135
|
end
|
118
136
|
end
|
119
137
|
end
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbhint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.85.1.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zee Spencer
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-06-
|
14
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: parallel
|