rubocop 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +21 -6
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +3 -3
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +4 -2
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -2
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +9 -1
- data/lib/rubocop/cop/style/format_string.rb +8 -3
- data/lib/rubocop/cop/style/redundant_argument.rb +2 -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: ea427ad9cf52b48c6d81ea6b730474acccb359cef988e0e00020a358f1e4662e
|
4
|
+
data.tar.gz: fb7383af86d50886bef707d52c835e0af030f002cbd22f0864fab28494f0f592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b35dbc1cb654f63c19fe863c6e1cc64778a94ac3b961505a565fa8202c20ea8a45a75347c8166456a5e5d420072c30516a51f31c0b76c456ecd53eade62d743
|
7
|
+
data.tar.gz: aa36afc87c4bef92a5032e26c81a31c6a26623f1257180b55db693cd56f2926130639b99220786c6f7708db374ab57eff90d280aa0d4519c7d9c651059efe95b
|
data/config/default.yml
CHANGED
@@ -459,7 +459,7 @@ Layout/EmptyLineAfterMultilineCondition:
|
|
459
459
|
- https://github.com/airbnb/ruby#multiline-if-newline
|
460
460
|
|
461
461
|
Layout/EmptyLineBetweenDefs:
|
462
|
-
Description: 'Use empty lines between defs.'
|
462
|
+
Description: 'Use empty lines between class/module/method defs.'
|
463
463
|
StyleGuide: '#empty-lines-between-methods'
|
464
464
|
Enabled: true
|
465
465
|
VersionAdded: '0.49'
|
@@ -2456,7 +2456,7 @@ Naming/VariableNumber:
|
|
2456
2456
|
StyleGuide: '#snake-case-symbols-methods-vars-with-numbers'
|
2457
2457
|
Enabled: true
|
2458
2458
|
VersionAdded: '0.50'
|
2459
|
-
VersionChanged: '1.
|
2459
|
+
VersionChanged: '1.4'
|
2460
2460
|
EnforcedStyle: normalcase
|
2461
2461
|
SupportedStyles:
|
2462
2462
|
- snake_case
|
@@ -39,16 +39,31 @@ module RuboCop
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def disable_offense(range)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
disable_offense_at_end_of_line(range_of_first_line(range),
|
46
|
-
eol_comment)
|
42
|
+
heredoc_range = surrounding_heredoc(range)
|
43
|
+
if heredoc_range
|
44
|
+
disable_offense_before_and_after(range_by_lines(heredoc_range))
|
47
45
|
else
|
48
|
-
|
46
|
+
eol_comment = " # rubocop:todo #{cop_name}"
|
47
|
+
needed_line_length = (range.source_line + eol_comment).length
|
48
|
+
if needed_line_length <= max_line_length
|
49
|
+
disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
|
50
|
+
else
|
51
|
+
disable_offense_before_and_after(range_by_lines(range))
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
56
|
+
def surrounding_heredoc(offense_range)
|
57
|
+
# The empty offense range is an edge case that can be reached from the Lint/Syntax cop.
|
58
|
+
return nil if offense_range.empty?
|
59
|
+
|
60
|
+
heredoc_nodes = processed_source.ast.each_descendant.select do |node|
|
61
|
+
node.respond_to?(:heredoc?) && node.heredoc?
|
62
|
+
end
|
63
|
+
heredoc_nodes.map { |node| node.loc.expression.join(node.loc.heredoc_end) }
|
64
|
+
.find { |range| range.contains?(offense_range) }
|
65
|
+
end
|
66
|
+
|
52
67
|
def range_of_first_line(range)
|
53
68
|
begin_of_first_line = range.begin_pos - range.column
|
54
69
|
end_of_first_line = begin_of_first_line + range.source_line.length
|
@@ -3,15 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# This cop checks whether method definitions are
|
7
|
-
# separated by one empty
|
6
|
+
# This cop checks whether class/module/method definitions are
|
7
|
+
# separated by one or more empty lines.
|
8
8
|
#
|
9
9
|
# `NumberOfEmptyLines` can be an integer (default is 1) or
|
10
10
|
# an array (e.g. [1, 2]) to specify a minimum and maximum
|
11
11
|
# number of empty lines permitted.
|
12
12
|
#
|
13
13
|
# `AllowAdjacentOneLineDefs` configures whether adjacent
|
14
|
-
# one-line
|
14
|
+
# one-line definitions are considered an offense.
|
15
15
|
#
|
16
16
|
# @example EmptyLineBetweenMethodDefs: true (default)
|
17
17
|
# # checks for empty lines between method definitions.
|
@@ -12,7 +12,8 @@ module RuboCop
|
|
12
12
|
# could be rewritten as such without a loop.
|
13
13
|
#
|
14
14
|
# Also catches instances where an index of the accumulator is returned, as
|
15
|
-
# this may change the type of object being retained.
|
15
|
+
# this may change the type of object being retained. As well, detects when
|
16
|
+
# fewer than 2 block arguments are specified.
|
16
17
|
#
|
17
18
|
# NOTE: For the purpose of reducing false positives, this cop only flags
|
18
19
|
# returns in `reduce` blocks where the element is the only variable in
|
@@ -67,7 +68,7 @@ module RuboCop
|
|
67
68
|
MSG_INDEX = 'Do not return an element of the accumulator in `%<method>s`.'
|
68
69
|
|
69
70
|
def_node_matcher :reduce_with_block?, <<~PATTERN
|
70
|
-
(block (send _recv {:reduce :inject} ...)
|
71
|
+
(block (send _recv {:reduce :inject} ...) args ...)
|
71
72
|
PATTERN
|
72
73
|
|
73
74
|
def_node_matcher :accumulator_index?, <<~PATTERN
|
@@ -106,6 +107,7 @@ module RuboCop
|
|
106
107
|
|
107
108
|
def on_block(node)
|
108
109
|
return unless reduce_with_block?(node)
|
110
|
+
return unless node.arguments.length >= 2
|
109
111
|
|
110
112
|
check_return_values(node)
|
111
113
|
end
|
@@ -7,10 +7,11 @@ module RuboCop
|
|
7
7
|
module ConfigurableNumbering
|
8
8
|
include ConfigurableFormatting
|
9
9
|
|
10
|
+
implicit_param = /\A_\d+\z/
|
10
11
|
FORMATS = {
|
11
12
|
snake_case: /(?:\D|_\d+|\A\d+)\z/,
|
12
|
-
normalcase: /(?:\D|[^_\d]\d+|\A\d+)\z/,
|
13
|
-
non_integer: /(\D|\A\d+)\z/
|
13
|
+
normalcase: /(?:\D|[^_\d]\d+|\A\d+)\z|#{implicit_param}/,
|
14
|
+
non_integer: /(\D|\A\d+)\z|#{implicit_param}/
|
14
15
|
}.freeze
|
15
16
|
end
|
16
17
|
end
|
@@ -2,7 +2,15 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
# Common functionality for enforcing a specific superclass
|
5
|
+
# Common functionality for enforcing a specific superclass.
|
6
|
+
#
|
7
|
+
# IMPORTANT: RuboCop core depended on this module when it supported Rails department.
|
8
|
+
# Rails department has been extracted to RuboCop Rails gem.
|
9
|
+
# This module is deprecated and will be removed by RuboCop 2.0.
|
10
|
+
# It will not be updated to `RuboCop::Cop::Base` v1 API to maintain compatibility
|
11
|
+
# with existing RuboCop Rails 2.8 or lower.
|
12
|
+
#
|
13
|
+
# @api private
|
6
14
|
module EnforceSuperclass
|
7
15
|
def self.included(base)
|
8
16
|
base.def_node_matcher :class_definition, <<~PATTERN
|
@@ -111,15 +111,20 @@ module RuboCop
|
|
111
111
|
format = format_arg.source
|
112
112
|
|
113
113
|
args = if param_args.one?
|
114
|
-
|
115
|
-
|
116
|
-
arg.hash_type? ? "{ #{arg.source} }" : arg.source
|
114
|
+
format_single_parameter(param_args.last)
|
117
115
|
else
|
118
116
|
"[#{param_args.map(&:source).join(', ')}]"
|
119
117
|
end
|
120
118
|
|
121
119
|
corrector.replace(node, "#{format} % #{args}")
|
122
120
|
end
|
121
|
+
|
122
|
+
def format_single_parameter(arg)
|
123
|
+
source = arg.source
|
124
|
+
return "{ #{source} }" if arg.hash_type?
|
125
|
+
|
126
|
+
arg.send_type? && arg.operator_method? && !arg.parenthesized? ? "(#{source})" : source
|
127
|
+
end
|
123
128
|
end
|
124
129
|
end
|
125
130
|
end
|
@@ -40,6 +40,8 @@ module RuboCop
|
|
40
40
|
MSG = 'Argument %<arg>s is redundant because it is implied by default.'
|
41
41
|
|
42
42
|
def on_send(node)
|
43
|
+
return if node.receiver.nil?
|
44
|
+
return if node.arguments.count != 1
|
43
45
|
return unless redundant_argument?(node)
|
44
46
|
|
45
47
|
add_offense(node, message: format(MSG, arg: node.arguments.first.source))
|
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.4.
|
4
|
+
version: 1.4.2
|
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: 2020-11-
|
13
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|