rubocop 0.79.0 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/config/default.yml +184 -50
- data/lib/rubocop.rb +15 -5
- data/lib/rubocop/ast/builder.rb +2 -0
- data/lib/rubocop/ast/node.rb +12 -19
- data/lib/rubocop/ast/node/array_node.rb +13 -0
- data/lib/rubocop/ast/node/block_node.rb +5 -1
- data/lib/rubocop/ast/node/case_match_node.rb +56 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +8 -0
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/node/send_node.rb +4 -0
- data/lib/rubocop/ast/traversal.rb +20 -9
- data/lib/rubocop/cli.rb +11 -5
- data/lib/rubocop/comment_config.rb +6 -1
- data/lib/rubocop/config.rb +40 -10
- data/lib/rubocop/config_loader.rb +43 -33
- data/lib/rubocop/config_loader_resolver.rb +28 -1
- data/lib/rubocop/config_obsoletion.rb +4 -1
- data/lib/rubocop/config_validator.rb +18 -1
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/corrector.rb +48 -24
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/generator.rb +3 -2
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +68 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +16 -10
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/leading_comment_space.rb +34 -3
- data/lib/rubocop/cop/layout/line_length.rb +36 -4
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +133 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +37 -2
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +38 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +18 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +6 -4
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +21 -9
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +12 -7
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -28
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +12 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +5 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -0
- data/lib/rubocop/cop/migration/department_name.rb +36 -10
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +16 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +178 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +2 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -10
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +26 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +11 -4
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/alias.rb +4 -4
- data/lib/rubocop/cop/style/and_or.rb +5 -6
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/case_equality.rb +24 -1
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -5
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +89 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -5
- data/lib/rubocop/cop/style/hash_transform_keys.rb +83 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +80 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
- data/lib/rubocop/cop/style/lambda.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -21
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +5 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +5 -4
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +58 -12
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -4
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +4 -3
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +4 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +18 -6
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +5 -7
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +3 -3
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -22
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +0 -4
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/cop/util.rb +24 -0
- data/lib/rubocop/cop/variable_force.rb +4 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +1 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +74 -0
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/node_pattern.rb +96 -10
- data/lib/rubocop/options.rb +18 -5
- data/lib/rubocop/processed_source.rb +1 -4
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +0 -4
- data/lib/rubocop/runner.rb +7 -2
- data/lib/rubocop/target_finder.rb +6 -4
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +35 -25
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/string_util.rb +0 -14
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
unless range.resize(1).source == "\n"
|
52
52
|
corrector.insert_before(range, ' ' * column_delta)
|
53
53
|
end
|
54
|
-
elsif
|
54
|
+
elsif /\A[ \t]+\z/.match?(range.source)
|
55
55
|
remove(range, corrector)
|
56
56
|
end
|
57
57
|
end
|
@@ -112,7 +112,7 @@ module RuboCop
|
|
112
112
|
corrector.remove(range)
|
113
113
|
rescue RuntimeError
|
114
114
|
range = range_between(range.begin_pos + 1, range.end_pos + 1)
|
115
|
-
retry if range.source
|
115
|
+
retry if /^ +$/.match?(range.source)
|
116
116
|
ensure
|
117
117
|
$stderr = original_stderr
|
118
118
|
end
|
@@ -10,8 +10,7 @@ module RuboCop
|
|
10
10
|
|
11
11
|
lambda do |corrector|
|
12
12
|
corrector.replace(node.loc.keyword, node.inverse_keyword)
|
13
|
-
corrector.replace(condition.
|
14
|
-
condition.children.first.source)
|
13
|
+
corrector.replace(condition, condition.children.first.source)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -44,13 +44,13 @@ module RuboCop
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def replace_selector(corrector)
|
47
|
-
corrector.replace(method
|
47
|
+
corrector.replace(method, 'lambda')
|
48
48
|
end
|
49
49
|
|
50
50
|
def remove_arguments(corrector)
|
51
51
|
return if arguments.empty_and_without_delimiters?
|
52
52
|
|
53
|
-
corrector.remove(arguments
|
53
|
+
corrector.remove(arguments)
|
54
54
|
end
|
55
55
|
|
56
56
|
def insert_arguments(corrector)
|
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
|
63
63
|
def remove_leading_whitespace(corrector)
|
64
64
|
corrector.remove_preceding(
|
65
|
-
arguments
|
65
|
+
arguments,
|
66
66
|
arguments.source_range.begin_pos -
|
67
67
|
block_node.send_node.source_range.end_pos
|
68
68
|
)
|
@@ -38,9 +38,9 @@ module RuboCop
|
|
38
38
|
return unless eol_comment
|
39
39
|
|
40
40
|
text = eol_comment.loc.expression.source
|
41
|
-
corrector.insert_before(node
|
41
|
+
corrector.insert_before(node,
|
42
42
|
text + "\n" + (' ' * node.loc.keyword.column))
|
43
|
-
corrector.remove(eol_comment
|
43
|
+
corrector.remove(eol_comment)
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
@@ -13,9 +13,9 @@ module RuboCop
|
|
13
13
|
lambda do |corrector|
|
14
14
|
str = node.str_content
|
15
15
|
if style == :single_quotes
|
16
|
-
corrector.replace(node
|
16
|
+
corrector.replace(node, to_string_literal(str))
|
17
17
|
else
|
18
|
-
corrector.replace(node
|
18
|
+
corrector.replace(node, str.inspect)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -132,11 +132,12 @@ module RuboCop
|
|
132
132
|
).inject
|
133
133
|
end
|
134
134
|
|
135
|
-
def inject_config(config_file_path: 'config/default.yml'
|
135
|
+
def inject_config(config_file_path: 'config/default.yml',
|
136
|
+
version_added: bump_minor_version)
|
136
137
|
injector =
|
137
138
|
ConfigurationInjector.new(configuration_file_path: config_file_path,
|
138
139
|
badge: badge,
|
139
|
-
version_added:
|
140
|
+
version_added: version_added)
|
140
141
|
|
141
142
|
injector.inject do
|
142
143
|
output.puts(format(CONFIGURATION_ADDED_MESSAGE,
|
@@ -6,33 +6,76 @@ module RuboCop
|
|
6
6
|
# Here we check if the elements of a multi-line array literal are
|
7
7
|
# aligned.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example EnforcedStyle: with_first_element (default)
|
10
|
+
# # good
|
11
|
+
#
|
12
|
+
# array = [1, 2, 3,
|
13
|
+
# 4, 5, 6]
|
14
|
+
# array = ['run',
|
15
|
+
# 'forrest',
|
16
|
+
# 'run']
|
17
|
+
#
|
10
18
|
# # bad
|
11
|
-
#
|
19
|
+
#
|
20
|
+
# array = [1, 2, 3,
|
12
21
|
# 4, 5, 6]
|
13
22
|
# array = ['run',
|
14
23
|
# 'forrest',
|
15
24
|
# 'run']
|
16
25
|
#
|
26
|
+
# @example EnforcedStyle: with_fixed_indentation
|
17
27
|
# # good
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
28
|
+
#
|
29
|
+
# array = [1, 2, 3,
|
30
|
+
# 4, 5, 6]
|
31
|
+
#
|
32
|
+
# # bad
|
33
|
+
#
|
34
|
+
# array = [1, 2, 3,
|
35
|
+
# 4, 5, 6]
|
23
36
|
class ArrayAlignment < Cop
|
24
37
|
include Alignment
|
25
38
|
|
26
|
-
|
27
|
-
|
39
|
+
ALIGN_ELEMENTS_MSG = 'Align the elements of an array literal ' \
|
40
|
+
'if they span more than one line.'
|
41
|
+
|
42
|
+
FIXED_INDENT_MSG = 'Use one level of indentation for elements ' \
|
43
|
+
'following the first line of a multi-line array.'
|
28
44
|
|
29
45
|
def on_array(node)
|
30
|
-
|
46
|
+
return if node.children.size < 2
|
47
|
+
|
48
|
+
check_alignment(node.children, base_column(node, node.children))
|
31
49
|
end
|
32
50
|
|
33
51
|
def autocorrect(node)
|
34
52
|
AlignmentCorrector.correct(processed_source, node, column_delta)
|
35
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def message(_node)
|
58
|
+
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_ELEMENTS_MSG
|
59
|
+
end
|
60
|
+
|
61
|
+
def fixed_indentation?
|
62
|
+
cop_config['EnforcedStyle'] == 'with_fixed_indentation'
|
63
|
+
end
|
64
|
+
|
65
|
+
def base_column(node, args)
|
66
|
+
if fixed_indentation?
|
67
|
+
lineno = target_method_lineno(node)
|
68
|
+
line = node.source_range.source_buffer.source_line(lineno)
|
69
|
+
indentation_of_line = /\S.*/.match(line).begin(0)
|
70
|
+
indentation_of_line + configured_indentation_width
|
71
|
+
else
|
72
|
+
display_column(args.first.source_range)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def target_method_lineno(node)
|
77
|
+
node.loc.line
|
78
|
+
end
|
36
79
|
end
|
37
80
|
end
|
38
81
|
end
|
@@ -52,9 +52,11 @@ module RuboCop
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def delimiter_range(node)
|
55
|
-
Parser::Source::Range.new(
|
56
|
-
|
57
|
-
|
55
|
+
Parser::Source::Range.new(
|
56
|
+
node.loc.expression.source_buffer,
|
57
|
+
node.children.compact.last.loc.expression.end_pos,
|
58
|
+
node.loc.expression.end_pos
|
59
|
+
)
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -23,6 +23,8 @@ module RuboCop
|
|
23
23
|
# do_something
|
24
24
|
# end
|
25
25
|
class ConditionPosition < Cop
|
26
|
+
include RangeHelp
|
27
|
+
|
26
28
|
MSG = 'Place the condition on the same line as `%<keyword>s`.'
|
27
29
|
|
28
30
|
def on_if(node)
|
@@ -34,9 +36,17 @@ module RuboCop
|
|
34
36
|
def on_while(node)
|
35
37
|
check(node)
|
36
38
|
end
|
39
|
+
alias on_until on_while
|
37
40
|
|
38
|
-
def
|
39
|
-
|
41
|
+
def autocorrect(node)
|
42
|
+
lambda do |corrector|
|
43
|
+
range = range_by_whole_lines(
|
44
|
+
node.source_range, include_final_newline: true
|
45
|
+
)
|
46
|
+
|
47
|
+
corrector.insert_after(node.parent.loc.keyword, " #{node.source}")
|
48
|
+
corrector.remove(range)
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
52
|
private
|
@@ -59,6 +59,14 @@ module RuboCop
|
|
59
59
|
check_alignment(node.when_branches.last.loc.keyword, node.loc.else)
|
60
60
|
end
|
61
61
|
|
62
|
+
def on_case_match(node)
|
63
|
+
return unless node.else?
|
64
|
+
|
65
|
+
check_alignment(
|
66
|
+
node.in_pattern_branches.last.loc.keyword, node.loc.else
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
62
70
|
def autocorrect(node)
|
63
71
|
AlignmentCorrector.correct(processed_source, node, column_delta)
|
64
72
|
end
|
@@ -56,7 +56,8 @@ module RuboCop
|
|
56
56
|
return if nodes.all?(&:single_line?) &&
|
57
57
|
cop_config['AllowAdjacentOneLineDefs']
|
58
58
|
|
59
|
-
|
59
|
+
location = nodes.last.loc.keyword.join(nodes.last.loc.name)
|
60
|
+
add_offense(nodes.last, location: location)
|
60
61
|
end
|
61
62
|
|
62
63
|
def autocorrect(node)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# Checks for a newline after attribute accessor.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# attr_accessor :foo
|
11
|
+
# def do_something
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# attr_accessor :foo
|
16
|
+
#
|
17
|
+
# def do_something
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# attr_accessor :foo
|
22
|
+
# attr_reader :bar
|
23
|
+
# attr_writer :baz
|
24
|
+
# attr :qux
|
25
|
+
#
|
26
|
+
# def do_something
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
class EmptyLinesAroundAttributeAccessor < Cop
|
30
|
+
include RangeHelp
|
31
|
+
|
32
|
+
MSG = 'Add an empty line after attribute accessor.'
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
return unless node.attribute_accessor?
|
36
|
+
return if next_line_empty?(node.last_line)
|
37
|
+
|
38
|
+
next_line_node = next_line_node(node)
|
39
|
+
return if next_line_node.nil? || attribute_accessor?(next_line_node)
|
40
|
+
|
41
|
+
add_offense(node)
|
42
|
+
end
|
43
|
+
|
44
|
+
def autocorrect(node)
|
45
|
+
lambda do |corrector|
|
46
|
+
range = range_by_whole_lines(node.source_range)
|
47
|
+
|
48
|
+
corrector.insert_after(range, "\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def next_line_empty?(line)
|
55
|
+
processed_source[line].blank?
|
56
|
+
end
|
57
|
+
|
58
|
+
def next_line_node(node)
|
59
|
+
node.parent.children[node.sibling_index + 1]
|
60
|
+
end
|
61
|
+
|
62
|
+
def attribute_accessor?(node)
|
63
|
+
node.send_type? && node.attribute_accessor?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -125,21 +125,15 @@ module RuboCop
|
|
125
125
|
|
126
126
|
def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
|
127
127
|
# if the right bracket is on the same line as the last value, accept
|
128
|
-
|
128
|
+
if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
|
129
|
+
return
|
130
|
+
end
|
129
131
|
|
130
132
|
expected_column = base_column(left_bracket, left_parenthesis)
|
131
133
|
@column_delta = expected_column - right_bracket.column
|
132
134
|
return if @column_delta.zero?
|
133
135
|
|
134
|
-
msg =
|
135
|
-
'Indent the right bracket the same as the left bracket.'
|
136
|
-
elsif style == :special_inside_parentheses && left_parenthesis
|
137
|
-
'Indent the right bracket the same as the first position ' \
|
138
|
-
'after the preceding left parenthesis.'
|
139
|
-
else
|
140
|
-
'Indent the right bracket the same as the start of the line' \
|
141
|
-
' where the left bracket is.'
|
142
|
-
end
|
136
|
+
msg = msg(left_parenthesis)
|
143
137
|
add_offense(right_bracket, location: right_bracket, message: msg)
|
144
138
|
end
|
145
139
|
|
@@ -161,6 +155,18 @@ module RuboCop
|
|
161
155
|
base_description: base_description
|
162
156
|
)
|
163
157
|
end
|
158
|
+
|
159
|
+
def msg(left_parenthesis)
|
160
|
+
if style == :align_brackets
|
161
|
+
'Indent the right bracket the same as the left bracket.'
|
162
|
+
elsif style == :special_inside_parentheses && left_parenthesis
|
163
|
+
'Indent the right bracket the same as the first position ' \
|
164
|
+
'after the preceding left parenthesis.'
|
165
|
+
else
|
166
|
+
'Indent the right bracket the same as the start of the line' \
|
167
|
+
' where the left bracket is.'
|
168
|
+
end
|
169
|
+
end
|
164
170
|
end
|
165
171
|
end
|
166
172
|
end
|
@@ -128,7 +128,7 @@ module RuboCop
|
|
128
128
|
|
129
129
|
def check_right_brace(right_brace, left_brace, left_parenthesis)
|
130
130
|
# if the right brace is on the same line as the last value, accept
|
131
|
-
return if right_brace.source_line[0...right_brace.column]
|
131
|
+
return if /\S/.match?(right_brace.source_line[0...right_brace.column])
|
132
132
|
|
133
133
|
expected_column = base_column(left_brace, left_parenthesis)
|
134
134
|
@column_delta = expected_column - right_brace.column
|
@@ -169,7 +169,7 @@ module RuboCop
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def add_correct_closing_paren(node, corrector)
|
172
|
-
corrector.insert_after(node.arguments.last
|
172
|
+
corrector.insert_after(node.arguments.last, ')')
|
173
173
|
end
|
174
174
|
|
175
175
|
def remove_incorrect_closing_paren(node, corrector)
|
@@ -249,7 +249,7 @@ module RuboCop
|
|
249
249
|
def add_correct_external_trailing_comma(node, corrector)
|
250
250
|
return unless external_trailing_comma?(node)
|
251
251
|
|
252
|
-
corrector.insert_after(node.arguments.last
|
252
|
+
corrector.insert_after(node.arguments.last, ',')
|
253
253
|
end
|
254
254
|
|
255
255
|
def remove_incorrect_external_trailing_comma(node, corrector)
|