rubocop 0.57.0 → 0.57.1

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
  SHA1:
3
- metadata.gz: 18bcf8548b6c61400893885a6ef649baeae5d368
4
- data.tar.gz: edd6b617b454f944d114b9a9e40f4bd7b60e6629
3
+ metadata.gz: e577b73a80f270f2f18699b1b34a563a60565d5c
4
+ data.tar.gz: 364776f0704be1ae1e85e158623f5ded6f81cc14
5
5
  SHA512:
6
- metadata.gz: '08121a25d44c4a2a976adf2a1dcc894fa0c432443518e17dc07588294cdb2d18fecee5aea9e57bd21de7e0b8af125a37214fe9b4daabda4262ff4cfbac798626'
7
- data.tar.gz: 4f5f292778ffa5e92480d931a0a12a784e0fc9e825aabcd9145adbe4704382feef4166b651ecfdb7522670501ff7a87781509da4995ac91ac14b3f485f8d5a37
6
+ metadata.gz: ee89c88fe1ad2bca660483e3e47bd7a59783f0989ff9e5b67d51cf182bfc9cbe9ea8d82e26ae5da2215ddbf23cb5c5bbbb84c28c9831da5d1ae8e34d9ba6e464
7
+ data.tar.gz: f6d4fbf74aff8a775ed6ff8f0336de11c40885c270aece677d8e45ebb0dbe3079b13b3015979734650f6fb4de7bbd80897ecf1f34004176115a3383a4e11823c
data/README.md CHANGED
@@ -51,7 +51,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
51
51
  might want to use a conservative version locking in your `Gemfile`:
52
52
 
53
53
  ```rb
54
- gem 'rubocop', '~> 0.57.0', require: false
54
+ gem 'rubocop', '~> 0.57.1', require: false
55
55
  ```
56
56
 
57
57
  ## Quickstart
@@ -459,6 +459,11 @@ module RuboCop
459
459
  # There could be a custom cop with this name. If so, don't warn
460
460
  next if Cop::Cop.registry.contains_cop_matching?([name])
461
461
 
462
+ # Special case for inherit_mode, which is a directive that we keep in
463
+ # the configuration (even though it's not a cop), because it's easier
464
+ # to do so than to pass the value around to various methods.
465
+ next if name == 'inherit_mode'
466
+
462
467
  warn Rainbow("Warning: unrecognized cop #{name} found in " \
463
468
  "#{smart_loaded_path}").yellow
464
469
  end
@@ -42,7 +42,7 @@ module RuboCop
42
42
  end
43
43
 
44
44
  hash['inherit_from'] = Array(hash['inherit_from'])
45
- Array(config_path).reverse.each do |path|
45
+ Array(config_path).reverse_each do |path|
46
46
  # Put gem configuration first so local configuration overrides it.
47
47
  hash['inherit_from'].unshift gem_config_path(gem_name, path)
48
48
  end
@@ -137,15 +137,58 @@ module RuboCop
137
137
 
138
138
  private
139
139
 
140
+ # Not all nodes define `bare_access_modifier?` (for example,
141
+ # `RuboCop::AST::DefNode` does not), so we must check `send_type?` first
142
+ # to avoid a NoMethodError.
143
+ def bare_access_modifier?(node)
144
+ node.send_type? && node.bare_access_modifier?
145
+ end
146
+
147
+ # Returns an integer representing the correct indentation, or nil to
148
+ # indicate that the correct indentation is that of the first child that
149
+ # is not an access modifier.
150
+ def base_column_for_normal_style(node)
151
+ first_child = node.children.first
152
+ return unless bare_access_modifier?(first_child)
153
+
154
+ # If, as is most common, the access modifier is indented deeper than
155
+ # the module (`access_modifier_indent > module_indent`) then the
156
+ # indentation of the access modifier determines the correct
157
+ # indentation.
158
+ #
159
+ # Otherwise, in the rare event that the access modifier is outdented
160
+ # to the level of the module (see `AccessModifierIndentation` cop) we
161
+ # return nil so that `check_alignment` will derive the correct
162
+ # indentation from the first child that is not an access modifier.
163
+ module_indent = display_column(node.parent.source_range)
164
+ access_modifier_indent = display_column(first_child.source_range)
165
+ access_modifier_indent if access_modifier_indent > module_indent
166
+ end
167
+
140
168
  def check(node)
169
+ if style == :rails
170
+ check_rails_style(node)
171
+ else
172
+ check_normal_style(node)
173
+ end
174
+ end
175
+
176
+ def check_normal_style(node)
177
+ check_alignment(
178
+ node.children.reject { |child| bare_access_modifier?(child) },
179
+ base_column_for_normal_style(node)
180
+ )
181
+ end
182
+
183
+ def check_rails_style(node)
141
184
  children_to_check = [[]]
142
185
  node.children.each do |child|
143
186
  # Modifier nodes have special indentation and will be checked by
144
187
  # the AccessModifierIndentation cop. This cop uses them as dividers
145
188
  # in rails mode. Then consistency is checked only within each
146
189
  # section delimited by a modifier node.
147
- if child.send_type? && child.bare_access_modifier?
148
- children_to_check << [] if style == :rails
190
+ if bare_access_modifier?(child)
191
+ children_to_check << []
149
192
  else
150
193
  children_to_check.last << child
151
194
  end
@@ -152,11 +152,17 @@ module RuboCop
152
152
  check_indentation(base, members.first)
153
153
 
154
154
  return unless members.any? && members.first.begin_type?
155
- return unless indentation_consistency_style == 'rails'
156
155
 
157
- each_member(members) do |member, previous_modifier|
158
- check_indentation(previous_modifier, member,
159
- indentation_consistency_style)
156
+ if indentation_consistency_style == 'rails'
157
+ each_member(members) do |member, previous_modifier|
158
+ check_indentation(previous_modifier, member,
159
+ indentation_consistency_style)
160
+ end
161
+ else
162
+ members.first.children.each do |member|
163
+ next if member.send_type? && member.access_modifier?
164
+ check_indentation(base, member)
165
+ end
160
166
  end
161
167
  end
162
168
 
@@ -8,25 +8,25 @@ module RuboCop
8
8
  #
9
9
  # @example
10
10
  #
11
- # # bad
12
- # # (start of file)
11
+ # # bad
12
+ # # (start of file)
13
13
  #
14
- # class Foo
15
- # end
14
+ # class Foo
15
+ # end
16
16
  #
17
- # # bad
18
- # # (start of file)
17
+ # # bad
18
+ # # (start of file)
19
19
  #
20
- # # a comment
20
+ # # a comment
21
21
  #
22
- # # good
23
- # # (start of file)
24
- # class Foo
25
- # end
22
+ # # good
23
+ # # (start of file)
24
+ # class Foo
25
+ # end
26
26
  #
27
- # # good
28
- # # (start of file)
29
- # # a comment
27
+ # # good
28
+ # # (start of file)
29
+ # # a comment
30
30
  class LeadingBlankLines < Cop
31
31
  MSG = 'Unnecessary blank line at the beginning of the source.'.freeze
32
32
 
@@ -19,7 +19,7 @@ module RuboCop
19
19
  UNDERSCORE = '_'.freeze
20
20
 
21
21
  def_node_matcher :reverse_each?, <<-MATCHER
22
- (send $(send array :reverse) :each)
22
+ (send $(send _ :reverse) :each)
23
23
  MATCHER
24
24
 
25
25
  def on_send(node)
@@ -135,6 +135,7 @@ module RuboCop
135
135
  def on_def(node)
136
136
  return unless support_bulk_alter?
137
137
  return unless MIGRATIION_METHODS.include?(node.method_name)
138
+ return unless node.body
138
139
 
139
140
  recorder = AlterMethodsRecorder.new
140
141
 
@@ -22,6 +22,14 @@ module RuboCop
22
22
  #
23
23
  # # good
24
24
  # b || c
25
+ #
26
+ # # good
27
+ # if b
28
+ # b
29
+ # elsif cond
30
+ # c
31
+ # end
32
+ #
25
33
  class UnneededCondition < Cop
26
34
  include RangeHelp
27
35
 
@@ -53,6 +61,8 @@ module RuboCop
53
61
  end
54
62
 
55
63
  def offense?(node)
64
+ return false if node.elsif_conditional?
65
+
56
66
  condition, if_branch, else_branch = *node
57
67
 
58
68
  condition == if_branch && !node.elsif? && (
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.57.0'.freeze
6
+ STRING = '0.57.1'.freeze
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
9
9
  '%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
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: 0.57.0
4
+ version: 0.57.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 1.4.0
21
+ version: 1.5.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 1.4.0
28
+ version: 1.5.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: parallel
31
31
  requirement: !ruby/object:Gem::Requirement