rubocop 0.80.0 → 0.84.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 +4 -4
- data/config/default.yml +171 -34
- data/lib/rubocop.rb +15 -62
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +11 -5
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/config.rb +41 -13
- data/lib/rubocop/config_loader.rb +40 -36
- data/lib/rubocop/config_loader_resolver.rb +27 -4
- data/lib/rubocop/config_obsoletion.rb +2 -0
- data/lib/rubocop/config_validator.rb +18 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- 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 +49 -27
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
- 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/parentheses_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/generator.rb +4 -3
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- 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_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -8
- 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/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +7 -4
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- 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 +129 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +40 -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 +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
- 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 +3 -7
- 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 +31 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- 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_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 +20 -25
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- 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 +13 -3
- 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/migration/department_name.rb +21 -12
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -3
- 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/multiline_element_indentation.rb +1 -3
- 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/surrounding_space.rb +1 -3
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- 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/file_name.rb +1 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.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 +13 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- 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 +7 -8
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
- 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 +9 -11
- 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/double_negation.rb +41 -4
- 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_literal.rb +1 -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 +2 -4
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +5 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +15 -10
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
- 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/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- 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 +6 -9
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- 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_parentheses.rb +2 -6
- 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 +3 -7
- 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 +3 -7
- 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 +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
- 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/trailing_underscore_variable.rb +2 -6
- 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 +3 -9
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/branch.rb +2 -6
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +3 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -4
- data/lib/rubocop/formatter/junit_formatter.rb +17 -6
- 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/options.rb +20 -13
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +1 -3
- data/lib/rubocop/rspec/cop_helper.rb +2 -4
- data/lib/rubocop/rspec/expect_offense.rb +4 -10
- data/lib/rubocop/rspec/shared_contexts.rb +54 -20
- data/lib/rubocop/runner.rb +15 -12
- data/lib/rubocop/target_finder.rb +5 -7
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +32 -77
- data/lib/rubocop/ast/builder.rb +0 -83
- data/lib/rubocop/ast/node.rb +0 -632
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -57
- data/lib/rubocop/ast/node/block_node.rb +0 -117
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -13
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -200
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -216
- data/lib/rubocop/string_util.rb +0 -14
- data/lib/rubocop/token.rb +0 -114
@@ -98,13 +98,9 @@ module RuboCop
|
|
98
98
|
lambda do |corrector|
|
99
99
|
fix_closing_parenthesis(node, corrector)
|
100
100
|
|
101
|
-
if internal_trailing_comma?(node)
|
102
|
-
remove_internal_trailing_comma(node, corrector)
|
103
|
-
end
|
101
|
+
remove_internal_trailing_comma(node, corrector) if internal_trailing_comma?(node)
|
104
102
|
|
105
|
-
if external_trailing_comma?(node)
|
106
|
-
fix_external_trailing_comma(node, corrector)
|
107
|
-
end
|
103
|
+
fix_external_trailing_comma(node, corrector) if external_trailing_comma?(node)
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
@@ -169,7 +165,7 @@ module RuboCop
|
|
169
165
|
end
|
170
166
|
|
171
167
|
def add_correct_closing_paren(node, corrector)
|
172
|
-
corrector.insert_after(node.arguments.last
|
168
|
+
corrector.insert_after(node.arguments.last, ')')
|
173
169
|
end
|
174
170
|
|
175
171
|
def remove_incorrect_closing_paren(node, corrector)
|
@@ -249,7 +245,7 @@ module RuboCop
|
|
249
245
|
def add_correct_external_trailing_comma(node, corrector)
|
250
246
|
return unless external_trailing_comma?(node)
|
251
247
|
|
252
|
-
corrector.insert_after(node.arguments.last
|
248
|
+
corrector.insert_after(node.arguments.last, ',')
|
253
249
|
end
|
254
250
|
|
255
251
|
def remove_incorrect_external_trailing_comma(node, corrector)
|
@@ -184,14 +184,14 @@ module RuboCop
|
|
184
184
|
def adjust_minus(corrector, node)
|
185
185
|
heredoc_beginning = node.loc.expression.source
|
186
186
|
corrected = heredoc_beginning.sub(/<<-?/, '<<~')
|
187
|
-
corrector.replace(node
|
187
|
+
corrector.replace(node, corrected)
|
188
188
|
end
|
189
189
|
|
190
190
|
def correct_by_library(node)
|
191
191
|
lambda do |corrector|
|
192
192
|
corrector.replace(node.loc.heredoc_body, indented_body(node))
|
193
193
|
corrected = ".#{STRIP_METHODS[style]}"
|
194
|
-
corrector.insert_after(node
|
194
|
+
corrector.insert_after(node, corrected)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -5,9 +5,10 @@ require 'set'
|
|
5
5
|
module RuboCop
|
6
6
|
module Cop
|
7
7
|
module Layout
|
8
|
-
# This cop checks
|
8
|
+
# This cop checks that the indentation method is consistent.
|
9
|
+
# Either tabs only or spaces only are used for indentation.
|
9
10
|
#
|
10
|
-
# @example
|
11
|
+
# @example EnforcedStyle: spaces (default)
|
11
12
|
# # bad
|
12
13
|
# # This example uses a tab to indent bar.
|
13
14
|
# def foo
|
@@ -20,17 +21,30 @@ module RuboCop
|
|
20
21
|
# bar
|
21
22
|
# end
|
22
23
|
#
|
23
|
-
|
24
|
+
# @example EnforcedStyle: tabs
|
25
|
+
# # bad
|
26
|
+
# # This example uses spaces to indent bar.
|
27
|
+
# def foo
|
28
|
+
# bar
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# # This example uses a tab to indent bar.
|
33
|
+
# def foo
|
34
|
+
# bar
|
35
|
+
# end
|
36
|
+
class IndentationStyle < Cop
|
24
37
|
include Alignment
|
38
|
+
include ConfigurableEnforcedStyle
|
25
39
|
include RangeHelp
|
26
40
|
|
27
|
-
MSG = '
|
41
|
+
MSG = '%<type>s detected in indentation.'
|
28
42
|
|
29
43
|
def investigate(processed_source)
|
30
44
|
str_ranges = string_literal_ranges(processed_source.ast)
|
31
45
|
|
32
46
|
processed_source.lines.each.with_index(1) do |line, lineno|
|
33
|
-
match = line
|
47
|
+
match = find_offence(line)
|
34
48
|
next unless match
|
35
49
|
|
36
50
|
range = source_range(processed_source.buffer,
|
@@ -43,13 +57,37 @@ module RuboCop
|
|
43
57
|
end
|
44
58
|
|
45
59
|
def autocorrect(range)
|
60
|
+
if range.source.include?("\t")
|
61
|
+
autocorrect_lambda_for_tabs(range)
|
62
|
+
else
|
63
|
+
autocorrect_lambda_for_spaces(range)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def find_offence(line)
|
70
|
+
if style == :spaces
|
71
|
+
line.match(/\A\s*\t+/)
|
72
|
+
else
|
73
|
+
line.match(/\A\s* +/)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def autocorrect_lambda_for_tabs(range)
|
46
78
|
lambda do |corrector|
|
47
79
|
spaces = ' ' * configured_indentation_width
|
48
80
|
corrector.replace(range, range.source.gsub(/\t/, spaces))
|
49
81
|
end
|
50
82
|
end
|
51
83
|
|
52
|
-
|
84
|
+
def autocorrect_lambda_for_spaces(range)
|
85
|
+
lambda do |corrector|
|
86
|
+
corrector.replace(range, range.source.gsub(/\A\s+/) do |match|
|
87
|
+
"\t" * (match.size / configured_indentation_width)
|
88
|
+
end)
|
89
|
+
end
|
90
|
+
end
|
53
91
|
|
54
92
|
def in_string_literal?(ranges, tabs_range)
|
55
93
|
ranges.any? { |range| range.contains?(tabs_range) }
|
@@ -69,6 +107,10 @@ module RuboCop
|
|
69
107
|
end
|
70
108
|
end
|
71
109
|
end
|
110
|
+
|
111
|
+
def message(_node)
|
112
|
+
format(MSG, type: style == :spaces ? 'Tab' : 'Space')
|
113
|
+
end
|
72
114
|
end
|
73
115
|
end
|
74
116
|
end
|
@@ -263,9 +263,7 @@ module RuboCop
|
|
263
263
|
def offense(body_node, indentation, style)
|
264
264
|
# This cop only auto-corrects the first statement in a def body, for
|
265
265
|
# example.
|
266
|
-
if body_node.begin_type? && !parentheses?(body_node)
|
267
|
-
body_node = body_node.children.first
|
268
|
-
end
|
266
|
+
body_node = body_node.children.first if body_node.begin_type? && !parentheses?(body_node)
|
269
267
|
|
270
268
|
# Since autocorrect changes a number of lines, and not only the line
|
271
269
|
# where the reported offending range is, we avoid auto-correction if
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
|
57
57
|
def investigate(processed_source)
|
58
58
|
processed_source.each_comment do |comment|
|
59
|
-
next unless
|
59
|
+
next unless /\A#+[^#\s=:+-]/.match?(comment.text)
|
60
60
|
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
|
61
61
|
next if doxygen_comment_style?(comment)
|
62
62
|
next if gemfile_ruby_comment?(comment)
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# This cop checks the length of lines in the source code.
|
9
9
|
# The maximum length is configurable.
|
10
10
|
# The tab size is configured in the `IndentationWidth`
|
11
|
-
# of the `Layout/
|
11
|
+
# of the `Layout/IndentationStyle` cop.
|
12
12
|
# It also ignores a shebang line by default.
|
13
13
|
#
|
14
14
|
# This cop has some autocorrection capabilities.
|
@@ -131,7 +131,7 @@ module RuboCop
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def breakable_block_range(block_node)
|
134
|
-
if block_node.arguments?
|
134
|
+
if block_node.arguments? && !block_node.lambda?
|
135
135
|
block_node.arguments.loc.end
|
136
136
|
else
|
137
137
|
block_node.loc.begin
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
145
145
|
return nil unless next_range.line == range.line
|
146
146
|
|
147
147
|
next_char = next_range.source
|
148
|
-
return nil if /[\r\n]
|
148
|
+
return nil if /[\r\n]/.match?(next_char)
|
149
149
|
return nil if next_char == ';'
|
150
150
|
|
151
151
|
next_range
|
@@ -160,7 +160,10 @@ module RuboCop
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def highlight_start(line)
|
163
|
-
max
|
163
|
+
# TODO: The max with 0 is a quick fix to avoid crashes when a line
|
164
|
+
# begins with many tabs, but getting a correct highlighting range
|
165
|
+
# when tabs are used for indentation doesn't work currently.
|
166
|
+
[max - indentation_difference(line), 0].max
|
164
167
|
end
|
165
168
|
|
166
169
|
def check_line(line, line_index)
|
@@ -81,9 +81,7 @@ module RuboCop
|
|
81
81
|
|
82
82
|
expr_before_body ||= node.loc.begin
|
83
83
|
|
84
|
-
if expr_before_body.line == node.body.first_line
|
85
|
-
autocorrect_body(corrector, node, node.body)
|
86
|
-
end
|
84
|
+
autocorrect_body(corrector, node, node.body) if expr_before_body.line == node.body.first_line
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -129,7 +127,7 @@ module RuboCop
|
|
129
127
|
|
130
128
|
block_start_col = node.source_range.column
|
131
129
|
|
132
|
-
corrector.insert_before(first_node
|
130
|
+
corrector.insert_before(first_node,
|
133
131
|
"\n #{' ' * block_start_col}")
|
134
132
|
end
|
135
133
|
|
@@ -37,9 +37,7 @@ module RuboCop
|
|
37
37
|
# ...then each key/value pair is treated as a method 'argument'
|
38
38
|
# when determining where line breaks should appear.
|
39
39
|
if (last_arg = args.last)
|
40
|
-
if last_arg.hash_type? && !last_arg.braces?
|
41
|
-
args = args.concat(args.pop.children)
|
42
|
-
end
|
40
|
+
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
|
43
41
|
end
|
44
42
|
|
45
43
|
check_line_breaks(node, args)
|
@@ -193,7 +193,7 @@ module RuboCop
|
|
193
193
|
node = node.receiver while node.receiver
|
194
194
|
# ascend to first call which has a dot
|
195
195
|
node = node.parent
|
196
|
-
node = node.parent until node.loc.dot
|
196
|
+
node = node.parent until node.loc.respond_to?(:dot) && node.loc.dot
|
197
197
|
|
198
198
|
return if node.loc.dot.line != node.first_line
|
199
199
|
|
@@ -6,30 +6,39 @@ module RuboCop
|
|
6
6
|
# This cop checks the indentation of the right hand side operand in
|
7
7
|
# binary operations that span more than one line.
|
8
8
|
#
|
9
|
+
# The `aligned` style checks that operators are aligned if they are part
|
10
|
+
# of an `if` or `while` condition, a `return` statement, etc. In other
|
11
|
+
# contexts, the second operand should be indented regardless of enforced
|
12
|
+
# style.
|
13
|
+
#
|
9
14
|
# @example EnforcedStyle: aligned (default)
|
10
15
|
# # bad
|
11
16
|
# if a +
|
12
17
|
# b
|
13
|
-
# something
|
18
|
+
# something &&
|
19
|
+
# something_else
|
14
20
|
# end
|
15
21
|
#
|
16
22
|
# # good
|
17
23
|
# if a +
|
18
24
|
# b
|
19
|
-
# something
|
25
|
+
# something &&
|
26
|
+
# something_else
|
20
27
|
# end
|
21
28
|
#
|
22
29
|
# @example EnforcedStyle: indented
|
23
30
|
# # bad
|
24
31
|
# if a +
|
25
32
|
# b
|
26
|
-
# something
|
33
|
+
# something &&
|
34
|
+
# something_else
|
27
35
|
# end
|
28
36
|
#
|
29
37
|
# # good
|
30
38
|
# if a +
|
31
39
|
# b
|
32
|
-
# something
|
40
|
+
# something &&
|
41
|
+
# something_else
|
33
42
|
# end
|
34
43
|
#
|
35
44
|
class MultilineOperationIndentation < Cop
|
@@ -43,11 +43,11 @@ module RuboCop
|
|
43
43
|
lambda do |corrector|
|
44
44
|
if target.is_a?(RuboCop::AST::Node)
|
45
45
|
if target.parent.children.first == target
|
46
|
-
corrector.insert_before(target
|
46
|
+
corrector.insert_before(target, ' ')
|
47
47
|
else
|
48
|
-
corrector.insert_after(target
|
48
|
+
corrector.insert_after(target, ' ')
|
49
49
|
end
|
50
|
-
elsif target.source
|
50
|
+
elsif /^\s+$/.match?(target.source)
|
51
51
|
corrector.remove(target)
|
52
52
|
else
|
53
53
|
corrector.insert_after(target, ' ')
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# Checks method call operators to not have spaces around them.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# foo. bar
|
11
|
+
# foo .bar
|
12
|
+
# foo . bar
|
13
|
+
# foo. bar .buzz
|
14
|
+
# foo
|
15
|
+
# . bar
|
16
|
+
# . buzz
|
17
|
+
# foo&. bar
|
18
|
+
# foo &.bar
|
19
|
+
# foo &. bar
|
20
|
+
# foo &. bar&. buzz
|
21
|
+
# RuboCop:: Cop
|
22
|
+
# RuboCop:: Cop:: Cop
|
23
|
+
# :: RuboCop::Cop
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# foo.bar
|
27
|
+
# foo.bar.buzz
|
28
|
+
# foo
|
29
|
+
# .bar
|
30
|
+
# .buzz
|
31
|
+
# foo&.bar
|
32
|
+
# foo&.bar&.buzz
|
33
|
+
# RuboCop::Cop
|
34
|
+
# RuboCop::Cop::Cop
|
35
|
+
# ::RuboCop::Cop
|
36
|
+
#
|
37
|
+
class SpaceAroundMethodCallOperator < Cop
|
38
|
+
include SurroundingSpace
|
39
|
+
|
40
|
+
MSG = 'Avoid using spaces around a method call operator.'
|
41
|
+
|
42
|
+
def on_send(node)
|
43
|
+
return unless dot_or_safe_navigation_operator?(node)
|
44
|
+
|
45
|
+
check_and_add_offense(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
def on_const(node)
|
49
|
+
return unless node.loc.double_colon
|
50
|
+
|
51
|
+
check_and_add_offense(node, false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def autocorrect(node)
|
55
|
+
operator = operator_token(node)
|
56
|
+
left = left_token_for_auto_correction(node, operator)
|
57
|
+
right = right_token_for_auto_correction(operator)
|
58
|
+
|
59
|
+
lambda do |corrector|
|
60
|
+
SpaceCorrector.remove_space(
|
61
|
+
processed_source, corrector, left, right
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
alias on_csend on_send
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def check_and_add_offense(node, add_left_offense = true)
|
71
|
+
operator = operator_token(node)
|
72
|
+
left = previous_token(operator)
|
73
|
+
right = next_token(operator)
|
74
|
+
|
75
|
+
no_space_offenses(node, operator, right, MSG) if !right.comment? && valid_right_token?(right, operator)
|
76
|
+
return unless valid_left_token?(left, operator)
|
77
|
+
|
78
|
+
no_space_offenses(node, left, operator, MSG) if add_left_offense
|
79
|
+
end
|
80
|
+
|
81
|
+
def operator_token(node)
|
82
|
+
operator_location =
|
83
|
+
node.const_type? ? node.loc.double_colon : node.loc.dot
|
84
|
+
|
85
|
+
processed_source.find_token do |token|
|
86
|
+
token.pos == operator_location
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def previous_token(current_token)
|
91
|
+
index = processed_source.tokens.index(current_token)
|
92
|
+
index.zero? ? nil : processed_source.tokens[index - 1]
|
93
|
+
end
|
94
|
+
|
95
|
+
def next_token(current_token)
|
96
|
+
index = processed_source.tokens.index(current_token)
|
97
|
+
processed_source.tokens[index + 1]
|
98
|
+
end
|
99
|
+
|
100
|
+
def dot_or_safe_navigation_operator?(node)
|
101
|
+
node.dot? || node.safe_navigation?
|
102
|
+
end
|
103
|
+
|
104
|
+
def valid_left_token?(left, operator)
|
105
|
+
left && left.line == operator.line
|
106
|
+
end
|
107
|
+
|
108
|
+
def valid_right_token?(right, operator)
|
109
|
+
right && right.line == operator.line
|
110
|
+
end
|
111
|
+
|
112
|
+
def left_token_for_auto_correction(node, operator)
|
113
|
+
left_token = previous_token(operator)
|
114
|
+
return operator if node.const_type?
|
115
|
+
return left_token if valid_left_token?(left_token, operator)
|
116
|
+
|
117
|
+
operator
|
118
|
+
end
|
119
|
+
|
120
|
+
def right_token_for_auto_correction(operator)
|
121
|
+
right_token = next_token(operator)
|
122
|
+
return right_token if !right_token.comment? && valid_right_token?(right_token, operator)
|
123
|
+
|
124
|
+
operator
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -139,7 +139,7 @@ module RuboCop
|
|
139
139
|
elsif range.source.end_with?("\n")
|
140
140
|
corrector.replace(range, " #{range.source.strip}\n")
|
141
141
|
else
|
142
|
-
corrector
|
142
|
+
enclose_operator_with_space(corrector, range)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
@@ -170,12 +170,25 @@ module RuboCop
|
|
170
170
|
yield msg if msg
|
171
171
|
end
|
172
172
|
|
173
|
+
def enclose_operator_with_space(corrector, range)
|
174
|
+
operator = range.source
|
175
|
+
|
176
|
+
# If `ForceEqualSignAlignment` is true, `Layout/ExtraSpacing` cop
|
177
|
+
# inserts spaces before operator. If `Layout/SpaceAroundOperators` cop
|
178
|
+
# inserts a space, it collides and raises the infinite loop error.
|
179
|
+
if force_equal_sign_alignment?
|
180
|
+
corrector.insert_after(range, ' ') unless operator.end_with?(' ')
|
181
|
+
else
|
182
|
+
corrector.replace(range, " #{operator.strip} ")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
173
186
|
def offense_message(type, operator, with_space, right_operand)
|
174
187
|
if should_not_have_surrounding_space?(operator)
|
175
188
|
return if with_space.is?(operator.source)
|
176
189
|
|
177
190
|
"Space around operator `#{operator.source}` detected."
|
178
|
-
elsif with_space.source
|
191
|
+
elsif !/^\s.*\s$/.match?(with_space.source)
|
179
192
|
"Surrounding space missing for operator `#{operator.source}`."
|
180
193
|
elsif excess_leading_space?(type, operator, with_space) ||
|
181
194
|
excess_trailing_space?(right_operand, with_space)
|
@@ -216,6 +229,10 @@ module RuboCop
|
|
216
229
|
cop_config['EnforcedStyleForExponentOperator'] == 'space'
|
217
230
|
end
|
218
231
|
|
232
|
+
def force_equal_sign_alignment?
|
233
|
+
config.for_cop('Layout/ExtraSpacing')['ForceEqualSignAlignment']
|
234
|
+
end
|
235
|
+
|
219
236
|
def should_not_have_surrounding_space?(operator)
|
220
237
|
operator.is?('**') ? !space_around_exponent_operator? : false
|
221
238
|
end
|