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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b7a7f1354d34c7b282f0a66c18b8df22bd5d0e01c9b826158a40654e93d8b87
4
- data.tar.gz: 744bf8c170922c28cea44ad76376a795b4399e190184a1223c6ecf23ff49bd8b
3
+ metadata.gz: fd891aa24d19c875913eea3b0955d179e0755ff691e7f7b79dbc297e97a2970f
4
+ data.tar.gz: be6d7b62c97c7da10a6b2e0862f012eeacd50c6f33b5ab92fee1af27cd76be20
5
5
  SHA512:
6
- metadata.gz: 3171cee77f3145866206436f222b721594e19818126088d91ddadee423f4057bd6a392f714c96238c88429d650b5551741848bad6ca2ba9f3b37ff6182e5fb75
7
- data.tar.gz: b96428cd9b0e6cceb9bb43a0b7a22d59e8f99c41ccbae6e9722f7572905ff942c0831039026046d49af8ebc047ebfebe9a80a403689edee386a477b89adb559f
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.0', require: false
43
+ gem 'rbhint', '~> 0.85.1.rc1', require: false
44
44
  ```
45
45
 
46
46
  ## Quickstart
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RbHint
4
4
  module Version
5
- STRING = '0.8.5.rc1'
5
+ STRING = '0.85.1.rc1'
6
6
  end
7
7
  end
@@ -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 == "\n" }
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
- COMPARISON_OPERATORS = RuboCop::AST::Node::COMPARISON_OPERATORS
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 _ {:#{COMPARISON_OPERATORS.join(' :')}} _) true false)
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 _ {:#{COMPARISON_OPERATORS.join(' :')}} _) false true)
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
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.85.0'
6
+ STRING = '0.85.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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.8.5.rc1
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-07 00:00:00.000000000 Z
14
+ date: 2020-06-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: parallel