rubocop 0.59.0 → 0.59.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: 3604f5385c9cdb9a48c56e4b02e873b1f03adc3c
4
- data.tar.gz: '039e08df8dc0c3fa47b0a035e650dbdc52068527'
3
+ metadata.gz: c194b5622ecc91385098a2b68a32fefb80dfe3c1
4
+ data.tar.gz: 6b77f223ef06685ee4af7543faed16456c38d7cb
5
5
  SHA512:
6
- metadata.gz: 0c6b9b6cce39cf4f4977f691a58b43362249e537e798ecb52d639147b8a92df7b32b6aa8553258b66f7093638c0afc11427390ea71cb90c872dbc8510d14359f
7
- data.tar.gz: 2f529fb7c60a2ffc733582edec86c1f66059a41e23a0835adf4d3f05593e6e49d0b061d91d06e4e968e7d5c544505e6781a71bfbe20234262eaa080091d86ffe
6
+ metadata.gz: 14a31079c85a1f77781219df27ffaeb0756ef006ca737c92a4690ff50f3cff68e407520b3d389bb03cdba4853eddcb07fa375955478547d4bfd219f8dc1e84dc
7
+ data.tar.gz: cee68c85b7430c9fb32e11206d9e8b8b1f87dd3cc29b0a878daf62b91e26cbd54793e4ead915b4894e1082c5f6d7dcd8584bf5f0a96e4123df32009ca11ff438
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rubocop.svg)](http://badge.fury.io/rb/rubocop)
2
- [![Travis Status](https://travis-ci.org/rubocop-hq/rubocop.svg?branch=master)](https://travis-ci.org/rubocop-hq/rubocop)
3
2
  [![CircleCI Status](https://circleci.com/gh/rubocop-hq/rubocop/tree/master.svg?style=svg)](https://circleci.com/gh/rubocop-hq/rubocop/tree/master)
4
3
  [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/sj3ye7n5690d0nvg?svg=true)](https://ci.appveyor.com/project/bbatsov/rubocop)
5
4
  [![Coverage Status](https://img.shields.io/codeclimate/coverage/github/bbatsov/rubocop.svg)](https://codeclimate.com/github/bbatsov/rubocop)
@@ -54,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
54
53
  might want to use a conservative version locking in your `Gemfile`:
55
54
 
56
55
  ```rb
57
- gem 'rubocop', '~> 0.59.0', require: false
56
+ gem 'rubocop', '~> 0.59.1', require: false
58
57
  ```
59
58
 
60
59
  ## Quickstart
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module AST
5
5
  # Common functionality for nodes that are a kind of method dispatch:
6
- # `send`, `csend`, `super`, `zsuper`, `yield`
6
+ # `send`, `csend`, `super`, `zsuper`, `yield`, `defined?`
7
7
  module MethodDispatchNode
8
8
  extend NodePattern::Macros
9
9
  include MethodIdentifierPredicates
@@ -163,6 +163,25 @@ module RuboCop
163
163
  [self, *each_descendant(:send)].any?(&:adjacent_def_modifier?)
164
164
  end
165
165
 
166
+ # Checks whether this is a lambda. Some versions of parser parses
167
+ # non-literal lambdas as a method send.
168
+ #
169
+ # @return [Boolean] whether this method is a lambda
170
+ def lambda?
171
+ block_literal? && command?(:lambda)
172
+ end
173
+
174
+ # Checks whether this is a lambda literal (stabby lambda.)
175
+ #
176
+ # @example
177
+ #
178
+ # -> (foo) { bar }
179
+ #
180
+ # @return [Boolean] whether this method is a lambda literal
181
+ def lambda_literal?
182
+ block_literal? && loc.expression && loc.expression.source == '->'
183
+ end
184
+
166
185
  private
167
186
 
168
187
  def_node_matcher :macro_scope?, <<-PATTERN
@@ -8,21 +8,6 @@ module RuboCop
8
8
  class SendNode < Node
9
9
  include ParameterizedNode
10
10
  include MethodDispatchNode
11
-
12
- # Checks whether this is a lambda. Some versions of parser parses
13
- # non-literal lambdas as a method send.
14
- #
15
- # @return [Boolean] whether this method is a lambda
16
- def lambda?
17
- block_literal? && method?(:lambda)
18
- end
19
-
20
- # Checks whether this is a stabby lambda. e.g. `-> () {}`
21
- #
22
- # @return [Boolean] whether this method is a stabby lambda
23
- def stabby_lambda?
24
- loc.selector && loc.selector.source == '->'
25
- end
26
11
  end
27
12
  end
28
13
  end
@@ -383,6 +383,11 @@ module RuboCop
383
383
  end
384
384
 
385
385
  def allowed_camel_case_file?(file)
386
+ # Gemspecs are allowed to have dashes because that fits with bundler best
387
+ # practices in the case when the gem is nested under a namespace (e.g.,
388
+ # `bundler-console` conveys `Bundler::Console`).
389
+ return true if File.extname(file) == '.gemspec'
390
+
386
391
  file_to_include?(file) do |pattern, relative_path, absolute_path|
387
392
  pattern.to_s =~ /[A-Z]/ &&
388
393
  (match_path?(pattern, relative_path) ||
@@ -47,7 +47,10 @@ module RuboCop
47
47
  if last_argument_is_heredoc?(node)
48
48
  heredoc_node = last_argument(node)
49
49
 
50
- num_of_heredoc_lines = heredoc_node.children.size
50
+ heredoc_body = heredoc_node.loc.heredoc_body
51
+ num_of_heredoc_lines =
52
+ heredoc_body.last_line - heredoc_body.first_line
53
+
51
54
  line = node.last_line + num_of_heredoc_lines + END_OF_HEREDOC_LINE
52
55
 
53
56
  return if next_line_empty?(line)
@@ -62,7 +65,12 @@ module RuboCop
62
65
 
63
66
  def autocorrect(node)
64
67
  lambda do |corrector|
65
- node_range = range_by_whole_lines(node.source_range)
68
+ node_range = if node.respond_to?(:heredoc?) && node.heredoc?
69
+ range_by_whole_lines(node.loc.heredoc_body)
70
+ else
71
+ range_by_whole_lines(node.source_range)
72
+ end
73
+
66
74
  corrector.insert_after(node_range, "\n")
67
75
  end
68
76
  end
@@ -106,19 +114,17 @@ module RuboCop
106
114
  end
107
115
 
108
116
  def last_argument_is_heredoc?(node)
109
- last_children = node.children.last
117
+ last_children = node.if_branch
110
118
 
111
119
  return false unless last_children && last_children.send_type?
112
120
 
113
121
  last_argument = last_argument(node)
114
122
 
115
- last_argument &&
116
- (last_argument.str_type? || last_argument.dstr_type?) &&
117
- last_argument.heredoc?
123
+ last_argument.respond_to?(:heredoc?) && last_argument.heredoc?
118
124
  end
119
125
 
120
126
  def last_argument(node)
121
- node.children.last.last_argument
127
+ node.if_branch.children.last
122
128
  end
123
129
  end
124
130
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  return next break retry redo
57
57
  (send
58
58
  {nil? (const {nil? cbase} :Kernel)}
59
- {:raise :fail :throw}
59
+ {:raise :fail :throw :exit :exit! :abort}
60
60
  ...)
61
61
  }
62
62
  PATTERN
@@ -18,7 +18,7 @@ module RuboCop
18
18
  'name its argument `other`.'.freeze
19
19
 
20
20
  OP_LIKE_METHODS = %i[eql? equal?].freeze
21
- BLACKLISTED = %i[+@ -@ [] []= << `].freeze
21
+ BLACKLISTED = %i[+@ -@ [] []= << === `].freeze
22
22
 
23
23
  def_node_matcher :op_method_candidate?, <<-PATTERN
24
24
  (def [#op_method? $_] (args $(arg [!:other !:_other])) _)
@@ -9,6 +9,11 @@ module RuboCop
9
9
  # names. Ruby scripts (i.e. source files with a shebang in the
10
10
  # first line) are ignored.
11
11
  #
12
+ # The cop also ignores `.gemspec` files, because Bundler
13
+ # recommends using dashes to separate namespaces in nested gems
14
+ # (i.e. `bundler-console` becomes `Bundler::Console`). As such, the
15
+ # gemspec is supposed to be named `bundler-console.gemspec`.
16
+ #
12
17
  # @example
13
18
  # # bad
14
19
  # lib/layoutManager.rb
@@ -91,7 +96,11 @@ module RuboCop
91
96
  end
92
97
 
93
98
  def filename_good?(basename)
99
+ basename = basename.sub(/^\./, '')
94
100
  basename = basename.sub(/\.[^\.]+$/, '')
101
+ # special handling for Action Pack Variants file names like
102
+ # some_file.xlsx+mobile.axlsx
103
+ basename = basename.sub('+', '_')
95
104
  basename =~ (regex || SNAKE_CASE)
96
105
  end
97
106
 
@@ -164,7 +173,7 @@ module RuboCop
164
173
  # To convert a pathname to a Ruby namespace, we need a starting point
165
174
  # But RC can be run from any working directory, and can check any path
166
175
  # We can't assume that the working directory, or any other, is the
167
- # "starting point" to build a namespace
176
+ # "starting point" to build a namespace.
168
177
  start = %w[lib spec test src]
169
178
  start_index = nil
170
179
 
@@ -39,7 +39,7 @@ module RuboCop
39
39
  private
40
40
 
41
41
  def method_chain(node)
42
- [*node.ancestors, node].map(&:method_name)
42
+ [*node.descendants.select(&:send_type?), node].map(&:method_name)
43
43
  end
44
44
 
45
45
  def ignored_by_find_each?(relation_method)
@@ -29,7 +29,7 @@ module RuboCop
29
29
 
30
30
  def on_block(node)
31
31
  send_node = node.send_node
32
- check(node) unless send_node.send_type? && send_node.stabby_lambda?
32
+ check(node) unless send_node.send_type? && send_node.lambda_literal?
33
33
  end
34
34
 
35
35
  def autocorrect(node)
@@ -67,9 +67,8 @@ module RuboCop
67
67
  private
68
68
 
69
69
  def correct_case_when(corrector, case_node, when_nodes)
70
- case_range = case_node.loc.keyword.join(when_nodes.first.loc.keyword)
71
-
72
- corrector.replace(case_range, 'if')
70
+ remove_case_node(corrector, case_node)
71
+ corrector.replace(when_nodes.first.loc.keyword, 'if')
73
72
 
74
73
  when_nodes[1..-1].each do |when_node|
75
74
  corrector.replace(when_node.loc.keyword, 'elsif')
@@ -88,6 +87,14 @@ module RuboCop
88
87
  corrector.replace(range, conditions.map(&:source).join(' || '))
89
88
  end
90
89
  end
90
+
91
+ def remove_case_node(corrector, case_node)
92
+ range = range_by_whole_lines(
93
+ case_node.loc.keyword, include_final_newline: true
94
+ )
95
+
96
+ corrector.remove(range)
97
+ end
91
98
  end
92
99
  end
93
100
  end
@@ -26,7 +26,7 @@ module RuboCop
26
26
  send_node = node.send_node
27
27
  return unless send_node.send_type?
28
28
 
29
- check(node) if node.send_node.stabby_lambda?
29
+ check(node) if node.send_node.lambda_literal?
30
30
  end
31
31
 
32
32
  def autocorrect(node)
@@ -22,6 +22,7 @@ module RuboCop
22
22
  MSG = 'Avoid multi-line method signatures.'.freeze
23
23
 
24
24
  def on_def(node)
25
+ return unless node.arguments?
25
26
  return if opening_line(node) == closing_line(node)
26
27
  return if correction_exceeds_max_line_length?(node)
27
28
 
@@ -36,11 +37,7 @@ module RuboCop
36
37
  end
37
38
 
38
39
  def closing_line(node)
39
- if node.arguments?
40
- node.arguments.last_line
41
- else
42
- node.first_line
43
- end
40
+ node.arguments.last_line
44
41
  end
45
42
 
46
43
  def correction_exceeds_max_line_length?(node)
@@ -52,8 +49,7 @@ module RuboCop
52
49
  end
53
50
 
54
51
  def definition_width(node)
55
- node.loc.expression.source.squeeze.length -
56
- node.loc.end.source.length
52
+ node.source_range.begin.join(node.arguments.source_range.end).length
57
53
  end
58
54
 
59
55
  def max_line_length
@@ -65,7 +65,7 @@ module RuboCop
65
65
  def on_block(node)
66
66
  return if target_ruby_version < 2.5
67
67
 
68
- return if node.send_node.stabby_lambda?
68
+ return if node.send_node.lambda_literal?
69
69
  return if node.braces?
70
70
 
71
71
  check(node)
@@ -30,7 +30,7 @@ module RuboCop
30
30
  return unless redundant_parentheses?(node) ||
31
31
  missing_parentheses?(node)
32
32
 
33
- add_offense(node.parent.arguments)
33
+ add_offense(node.block_node.arguments)
34
34
  end
35
35
 
36
36
  def autocorrect(node)
@@ -57,7 +57,7 @@ module RuboCop
57
57
 
58
58
  def missing_parentheses_corrector(node)
59
59
  lambda do |corrector|
60
- args_loc = node.parent.arguments.source_range
60
+ args_loc = node.loc.expression
61
61
 
62
62
  corrector.insert_before(args_loc, '(')
63
63
  corrector.insert_after(args_loc, ')')
@@ -66,7 +66,7 @@ module RuboCop
66
66
 
67
67
  def unwanted_parentheses_corrector(node)
68
68
  lambda do |corrector|
69
- args_loc = node.parent.arguments.loc
69
+ args_loc = node.loc
70
70
 
71
71
  corrector.replace(args_loc.begin, '')
72
72
  corrector.remove(args_loc.end)
@@ -74,11 +74,11 @@ module RuboCop
74
74
  end
75
75
 
76
76
  def stabby_lambda_with_args?(node)
77
- node.stabby_lambda? && node.parent.arguments?
77
+ node.lambda_literal? && node.block_node.arguments?
78
78
  end
79
79
 
80
80
  def parentheses?(node)
81
- node.parent.arguments.loc.begin
81
+ node.block_node.arguments.loc.begin
82
82
  end
83
83
  end
84
84
  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.59.0'.freeze
6
+ STRING = '0.59.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.59.0
4
+ version: 0.59.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: 2018-09-09 00:00:00.000000000 Z
13
+ date: 2018-09-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jaro_winkler