rubocop 0.86.0 → 0.87.0
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/config/default.yml +46 -4
- data/lib/rubocop.rb +7 -1
- data/lib/rubocop/cli.rb +0 -2
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +40 -5
- data/lib/rubocop/cli/command/show_cops.rb +1 -1
- data/lib/rubocop/config_loader.rb +22 -62
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +13 -23
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -50
- data/lib/rubocop/cop/cop.rb +85 -236
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -8
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -0
- data/lib/rubocop/cop/layout/hash_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +0 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -23
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +8 -0
- data/lib/rubocop/cop/lint/syntax.rb +11 -26
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -2
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +2 -2
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +5 -5
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +26 -7
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +97 -81
- data/lib/rubocop/cop/utils/format_string.rb +1 -2
- data/lib/rubocop/name_similarity.rb +1 -3
- data/lib/rubocop/options.rb +15 -8
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/rspec/cop_helper.rb +4 -4
- data/lib/rubocop/rspec/expect_offense.rb +10 -16
- data/lib/rubocop/rspec/shared_contexts.rb +7 -7
- data/lib/rubocop/runner.rb +31 -29
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +15 -7
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
@@ -8,117 +8,25 @@ module RuboCop
|
|
8
8
|
# Important!
|
9
9
|
# The nodes modified by the corrections should be part of the
|
10
10
|
# AST of the source_buffer.
|
11
|
-
class Corrector
|
11
|
+
class Corrector < ::Parser::Source::TreeRewriter
|
12
|
+
# @param source [Parser::Source::Buffer, or anything
|
13
|
+
# leading to one via `(processed_source.)buffer`]
|
12
14
|
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# @example
|
19
|
-
#
|
20
|
-
# class AndOrCorrector
|
21
|
-
# def initialize(node)
|
22
|
-
# @node = node
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# def call(corrector)
|
26
|
-
# replacement = (@node.type == :and ? '&&' : '||')
|
27
|
-
# corrector.replace(@node.loc.operator, replacement)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# corrections = [AndOrCorrector.new(node)]
|
32
|
-
# corrector = Corrector.new(source_buffer, corrections)
|
33
|
-
def initialize(source_buffer, corrections = [])
|
34
|
-
@source_buffer = source_buffer
|
35
|
-
raise 'source_buffer should be a Parser::Source::Buffer' unless \
|
36
|
-
source_buffer.is_a? Parser::Source::Buffer
|
37
|
-
|
38
|
-
@corrections = corrections
|
39
|
-
@source_rewriter = Parser::Source::TreeRewriter.new(
|
40
|
-
source_buffer,
|
15
|
+
# corrector = Corrector.new(cop)
|
16
|
+
def initialize(source)
|
17
|
+
source = self.class.source_buffer(source)
|
18
|
+
super(
|
19
|
+
source,
|
41
20
|
different_replacements: :raise,
|
42
21
|
swallowed_insertions: :raise,
|
43
22
|
crossing_deletions: :accept
|
44
23
|
)
|
45
24
|
|
46
|
-
@diagnostics = []
|
47
25
|
# Don't print warnings to stderr if corrections conflict with each other
|
48
|
-
|
49
|
-
@diagnostics << diagnostic
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
attr_reader :corrections, :diagnostics
|
54
|
-
|
55
|
-
# Does the actual rewrite and returns string corresponding to
|
56
|
-
# the rewritten source.
|
57
|
-
#
|
58
|
-
# @return [String]
|
59
|
-
def rewrite
|
60
|
-
@corrections.each do |correction|
|
61
|
-
begin
|
62
|
-
@source_rewriter.transaction do
|
63
|
-
correction.call(self)
|
64
|
-
end
|
65
|
-
rescue ErrorWithAnalyzedFileLocation => e
|
66
|
-
raise e unless e.cause.is_a?(::Parser::ClobberingError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
@source_rewriter.process
|
71
|
-
end
|
72
|
-
|
73
|
-
# Removes the source range.
|
74
|
-
#
|
75
|
-
# @param [Parser::Source::Range, Rubocop::AST::Node] range or node
|
76
|
-
def remove(node_or_range)
|
77
|
-
range = to_range(node_or_range)
|
78
|
-
@source_rewriter.remove(range)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Inserts new code before the given source range.
|
82
|
-
#
|
83
|
-
# @param [Parser::Source::Range, Rubocop::AST::Node] range or node
|
84
|
-
# @param [String] content
|
85
|
-
def insert_before(node_or_range, content)
|
86
|
-
range = to_range(node_or_range)
|
87
|
-
# TODO: Fix Cops using bad ranges instead
|
88
|
-
if range.end_pos > @source_buffer.source.size
|
89
|
-
range = range.with(end_pos: @source_buffer.source.size)
|
90
|
-
end
|
91
|
-
|
92
|
-
@source_rewriter.insert_before(range, content)
|
93
|
-
end
|
94
|
-
|
95
|
-
# Inserts new code after the given source range.
|
96
|
-
#
|
97
|
-
# @param [Parser::Source::Range, Rubocop::AST::Node] range or node
|
98
|
-
# @param [String] content
|
99
|
-
def insert_after(node_or_range, content)
|
100
|
-
range = to_range(node_or_range)
|
101
|
-
@source_rewriter.insert_after(range, content)
|
26
|
+
diagnostics.consumer = ->(diagnostic) {}
|
102
27
|
end
|
103
28
|
|
104
|
-
|
105
|
-
#
|
106
|
-
# @param [Parser::Source::Range, Rubocop::AST::Node] range or node
|
107
|
-
# @param [String] before
|
108
|
-
# @param [String] after
|
109
|
-
def wrap(node_or_range, before, after)
|
110
|
-
range = to_range(node_or_range)
|
111
|
-
@source_rewriter.wrap(range, before, after)
|
112
|
-
end
|
113
|
-
|
114
|
-
# Replaces the code of the source range `range` with `content`.
|
115
|
-
#
|
116
|
-
# @param [Parser::Source::Range, Rubocop::AST::Node] range or node
|
117
|
-
# @param [String] content
|
118
|
-
def replace(node_or_range, content)
|
119
|
-
range = to_range(node_or_range)
|
120
|
-
@source_rewriter.replace(range, content)
|
121
|
-
end
|
29
|
+
alias rewrite process # Legacy
|
122
30
|
|
123
31
|
# Removes `size` characters prior to the source range.
|
124
32
|
#
|
@@ -126,10 +34,11 @@ module RuboCop
|
|
126
34
|
# @param [Integer] size
|
127
35
|
def remove_preceding(node_or_range, size)
|
128
36
|
range = to_range(node_or_range)
|
129
|
-
to_remove =
|
130
|
-
|
131
|
-
|
132
|
-
|
37
|
+
to_remove = range.with(
|
38
|
+
begin_pos: range.begin_pos - size,
|
39
|
+
end_pos: range.begin_pos
|
40
|
+
)
|
41
|
+
remove(to_remove)
|
133
42
|
end
|
134
43
|
|
135
44
|
# Removes `size` characters from the beginning of the given range.
|
@@ -140,10 +49,8 @@ module RuboCop
|
|
140
49
|
# @param [Integer] size
|
141
50
|
def remove_leading(node_or_range, size)
|
142
51
|
range = to_range(node_or_range)
|
143
|
-
to_remove =
|
144
|
-
|
145
|
-
range.begin_pos + size)
|
146
|
-
@source_rewriter.remove(to_remove)
|
52
|
+
to_remove = range.with(end_pos: range.begin_pos + size)
|
53
|
+
remove(to_remove)
|
147
54
|
end
|
148
55
|
|
149
56
|
# Removes `size` characters from the end of the given range.
|
@@ -154,10 +61,22 @@ module RuboCop
|
|
154
61
|
# @param [Integer] size
|
155
62
|
def remove_trailing(node_or_range, size)
|
156
63
|
range = to_range(node_or_range)
|
157
|
-
to_remove =
|
158
|
-
|
159
|
-
|
160
|
-
|
64
|
+
to_remove = range.with(begin_pos: range.end_pos - size)
|
65
|
+
remove(to_remove)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Duck typing for get to a ::Parser::Source::Buffer
|
69
|
+
def self.source_buffer(source)
|
70
|
+
source = source.processed_source if source.respond_to?(:processed_source)
|
71
|
+
source = source.buffer if source.respond_to?(:buffer)
|
72
|
+
source = source.source_buffer if source.respond_to?(:source_buffer)
|
73
|
+
|
74
|
+
unless source.is_a? ::Parser::Source::Buffer
|
75
|
+
raise TypeError, 'Expected argument to lead to a Parser::Source::Buffer ' \
|
76
|
+
"but got #{source.inspect}"
|
77
|
+
end
|
78
|
+
|
79
|
+
source
|
161
80
|
end
|
162
81
|
|
163
82
|
private
|
@@ -178,8 +97,12 @@ module RuboCop
|
|
178
97
|
range
|
179
98
|
end
|
180
99
|
|
100
|
+
def check_range_validity(node_or_range)
|
101
|
+
super(to_range(node_or_range))
|
102
|
+
end
|
103
|
+
|
181
104
|
def validate_buffer(buffer)
|
182
|
-
return if buffer ==
|
105
|
+
return if buffer == source_buffer
|
183
106
|
|
184
107
|
unless buffer.is_a?(::Parser::Source::Buffer)
|
185
108
|
# actually this should be enforced by parser gem
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
class RubyVersionGlobalsUsage < Cop
|
29
29
|
MSG = 'Do not use `RUBY_VERSION` in gemspec file.'
|
30
30
|
|
31
|
-
def_node_matcher :ruby_version?, '(const nil? :RUBY_VERSION)'
|
31
|
+
def_node_matcher :ruby_version?, '(const {cbase nil?} :RUBY_VERSION)'
|
32
32
|
|
33
33
|
def_node_search :gem_specification?, <<~PATTERN
|
34
34
|
(block
|
@@ -13,7 +13,9 @@ module RuboCop
|
|
13
13
|
# # good
|
14
14
|
# node.send_type?
|
15
15
|
#
|
16
|
-
class NodeTypePredicate <
|
16
|
+
class NodeTypePredicate < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
17
19
|
MSG = 'Use `#%<type>s_type?` to check node type.'
|
18
20
|
|
19
21
|
def_node_matcher :node_type_check, <<~PATTERN
|
@@ -21,21 +23,16 @@ module RuboCop
|
|
21
23
|
PATTERN
|
22
24
|
|
23
25
|
def on_send(node)
|
24
|
-
node_type_check(node) do |
|
26
|
+
node_type_check(node) do |receiver, node_type|
|
25
27
|
return unless Parser::Meta::NODE_TYPES.include?(node_type)
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
receiver.loc.expression.end_pos + 1,
|
35
|
-
node.loc.expression.end_pos)
|
36
|
-
|
37
|
-
lambda do |corrector|
|
38
|
-
corrector.replace(range, "#{node_type}_type?")
|
29
|
+
message = format(MSG, type: node_type)
|
30
|
+
add_offense(node, message: message) do |corrector|
|
31
|
+
range = node.loc.expression.with(
|
32
|
+
begin_pos: receiver.loc.expression.end_pos + 1
|
33
|
+
)
|
34
|
+
corrector.replace(range, "#{node_type}_type?")
|
35
|
+
end
|
39
36
|
end
|
40
37
|
end
|
41
38
|
end
|
@@ -67,10 +67,11 @@ module RuboCop
|
|
67
67
|
# else
|
68
68
|
# y / 3
|
69
69
|
# end
|
70
|
-
class CaseIndentation <
|
70
|
+
class CaseIndentation < Base
|
71
71
|
include Alignment
|
72
72
|
include ConfigurableEnforcedStyle
|
73
73
|
include RangeHelp
|
74
|
+
extend AutoCorrector
|
74
75
|
|
75
76
|
MSG = 'Indent `when` %<depth>s `%<base>s`.'
|
76
77
|
|
@@ -82,16 +83,6 @@ module RuboCop
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
def autocorrect(node)
|
86
|
-
whitespace = whitespace_range(node)
|
87
|
-
|
88
|
-
return false unless whitespace.source.strip.empty?
|
89
|
-
|
90
|
-
lambda do |corrector|
|
91
|
-
corrector.replace(whitespace, replacement(node))
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
86
|
private
|
96
87
|
|
97
88
|
def check_when(when_node)
|
@@ -114,22 +105,30 @@ module RuboCop
|
|
114
105
|
end
|
115
106
|
|
116
107
|
def incorrect_style(when_node)
|
108
|
+
add_offense(when_node.loc.keyword) do |corrector|
|
109
|
+
detect_incorrect_style(when_node)
|
110
|
+
|
111
|
+
whitespace = whitespace_range(when_node)
|
112
|
+
|
113
|
+
corrector.replace(whitespace, replacement(when_node)) if whitespace.source.strip.empty?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def detect_incorrect_style(when_node)
|
117
118
|
when_column = when_node.loc.keyword.column
|
118
119
|
base_column = base_column(when_node.parent, alternative_style)
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
unrecognized_style_detected
|
125
|
-
end
|
121
|
+
if when_column == base_column
|
122
|
+
opposite_style_detected
|
123
|
+
else
|
124
|
+
unrecognized_style_detected
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
129
|
-
def
|
128
|
+
def find_message(*)
|
130
129
|
depth = indent_one_step? ? 'one step more than' : 'as deep as'
|
131
130
|
|
132
|
-
format(MSG, depth: depth, base:
|
131
|
+
format(MSG, depth: depth, base: style)
|
133
132
|
end
|
134
133
|
|
135
134
|
def base_column(case_node, base)
|
@@ -62,6 +62,7 @@ module RuboCop
|
|
62
62
|
#
|
63
63
|
class EmptyLinesAroundAttributeAccessor < Cop
|
64
64
|
include RangeHelp
|
65
|
+
include AllowedMethods
|
65
66
|
|
66
67
|
MSG = 'Add an empty line after attribute accessor.'
|
67
68
|
|
@@ -114,14 +115,6 @@ module RuboCop
|
|
114
115
|
def allow_alias_syntax?
|
115
116
|
cop_config.fetch('AllowAliasSyntax', true)
|
116
117
|
end
|
117
|
-
|
118
|
-
def allowed_method?(name)
|
119
|
-
allowed_methods.include?(name.to_s)
|
120
|
-
end
|
121
|
-
|
122
|
-
def allowed_methods
|
123
|
-
cop_config.fetch('AllowedMethods', [])
|
124
|
-
end
|
125
118
|
end
|
126
119
|
end
|
127
120
|
end
|
@@ -24,9 +24,10 @@ module RuboCop
|
|
24
24
|
# # good
|
25
25
|
# {}.each { | x, y | puts x }
|
26
26
|
# ->( x, y ) { puts x }
|
27
|
-
class SpaceAroundBlockParameters <
|
27
|
+
class SpaceAroundBlockParameters < Base
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
include RangeHelp
|
30
|
+
extend AutoCorrector
|
30
31
|
|
31
32
|
def on_block(node)
|
32
33
|
arguments = node.arguments
|
@@ -38,23 +39,6 @@ module RuboCop
|
|
38
39
|
check_each_arg(arguments)
|
39
40
|
end
|
40
41
|
|
41
|
-
# @param target [RuboCop::AST::Node,Parser::Source::Range]
|
42
|
-
def autocorrect(target)
|
43
|
-
lambda do |corrector|
|
44
|
-
if target.is_a?(RuboCop::AST::Node)
|
45
|
-
if target.parent.children.first == target
|
46
|
-
corrector.insert_before(target, ' ')
|
47
|
-
else
|
48
|
-
corrector.insert_after(target, ' ')
|
49
|
-
end
|
50
|
-
elsif /^\s+$/.match?(target.source)
|
51
|
-
corrector.remove(target)
|
52
|
-
else
|
53
|
-
corrector.insert_after(target, ' ')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
42
|
private
|
59
43
|
|
60
44
|
def pipes(arguments)
|
@@ -97,7 +81,7 @@ module RuboCop
|
|
97
81
|
|
98
82
|
check_no_space(opening_pipe.end_pos, first.begin_pos,
|
99
83
|
'Space before first')
|
100
|
-
check_no_space(last_end_pos_inside_pipes(last
|
84
|
+
check_no_space(last_end_pos_inside_pipes(last),
|
101
85
|
closing_pipe.begin_pos, 'Space after last')
|
102
86
|
end
|
103
87
|
|
@@ -118,7 +102,7 @@ module RuboCop
|
|
118
102
|
|
119
103
|
def check_closing_pipe_space(args, closing_pipe)
|
120
104
|
last = args.last.source_range
|
121
|
-
last_end_pos = last_end_pos_inside_pipes(last
|
105
|
+
last_end_pos = last_end_pos_inside_pipes(last)
|
122
106
|
|
123
107
|
check_space(last_end_pos, closing_pipe.begin_pos, last,
|
124
108
|
'after last block parameter')
|
@@ -126,8 +110,9 @@ module RuboCop
|
|
126
110
|
'Extra space after last')
|
127
111
|
end
|
128
112
|
|
129
|
-
def last_end_pos_inside_pipes(
|
130
|
-
|
113
|
+
def last_end_pos_inside_pipes(range)
|
114
|
+
pos = range.end_pos
|
115
|
+
range.source_buffer.source[pos] == ',' ? pos + 1 : pos
|
131
116
|
end
|
132
117
|
|
133
118
|
def check_each_arg(args)
|
@@ -151,7 +136,14 @@ module RuboCop
|
|
151
136
|
return if space_begin_pos != space_end_pos
|
152
137
|
|
153
138
|
target = node || range
|
154
|
-
|
139
|
+
message = "Space #{msg} missing."
|
140
|
+
add_offense(target, message: message) do |corrector|
|
141
|
+
if node
|
142
|
+
corrector.insert_before(node, ' ')
|
143
|
+
else
|
144
|
+
corrector.insert_after(target, ' ')
|
145
|
+
end
|
146
|
+
end
|
155
147
|
end
|
156
148
|
|
157
149
|
def check_no_space(space_begin_pos, space_end_pos, msg)
|
@@ -160,8 +152,10 @@ module RuboCop
|
|
160
152
|
range = range_between(space_begin_pos, space_end_pos)
|
161
153
|
return if range.source.include?("\n")
|
162
154
|
|
163
|
-
|
164
|
-
|
155
|
+
message = "#{msg} block parameter detected."
|
156
|
+
add_offense(range, message: message) do |corrector|
|
157
|
+
corrector.remove(range)
|
158
|
+
end
|
165
159
|
end
|
166
160
|
end
|
167
161
|
end
|