rubocop 0.35.1 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +164 -0
- data/LICENSE.txt +1 -1
- data/README.md +72 -21
- data/bin/rubocop +1 -0
- data/config/default.yml +167 -18
- data/config/disabled.yml +19 -6
- data/config/enabled.yml +159 -14
- data/lib/rubocop.rb +67 -26
- data/lib/rubocop/ast_node.rb +488 -14
- data/lib/rubocop/ast_node/builder.rb +24 -0
- data/lib/rubocop/ast_node/sexp.rb +13 -0
- data/lib/rubocop/cached_data.rb +58 -0
- data/lib/rubocop/cli.rb +47 -10
- data/lib/rubocop/comment_config.rb +9 -2
- data/lib/rubocop/config.rb +99 -31
- data/lib/rubocop/config_loader.rb +23 -14
- data/lib/rubocop/config_store.rb +1 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +2 -1
- data/lib/rubocop/cop/commissioner.rb +3 -5
- data/lib/rubocop/cop/cop.rb +23 -17
- data/lib/rubocop/cop/corrector.rb +25 -0
- data/lib/rubocop/cop/force.rb +1 -0
- data/lib/rubocop/cop/ignored_node.rb +3 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -3
- data/lib/rubocop/cop/lint/block_alignment.rb +29 -91
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -1
- data/lib/rubocop/cop/lint/condition_position.rb +2 -1
- data/lib/rubocop/cop/lint/debugger.rb +29 -12
- data/lib/rubocop/cop/lint/def_end_alignment.rb +16 -18
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +6 -6
- data/lib/rubocop/cop/lint/duplicate_methods.rb +98 -74
- data/lib/rubocop/cop/lint/duplicated_key.rb +3 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -2
- data/lib/rubocop/cop/lint/else_layout.rb +2 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +2 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +2 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +77 -39
- data/lib/rubocop/cop/lint/end_in_method.rb +2 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +2 -1
- data/lib/rubocop/cop/lint/eval.rb +2 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +31 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -30
- data/lib/rubocop/cop/lint/handle_exceptions.rb +2 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +85 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +120 -0
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +3 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -9
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +6 -9
- data/lib/rubocop/cop/lint/loop.rb +2 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +19 -3
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +38 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +5 -8
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -6
- data/lib/rubocop/cop/lint/rand_one.rb +36 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +6 -5
- data/lib/rubocop/cop/lint/rescue_exception.rb +3 -2
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -4
- data/lib/rubocop/cop/lint/syntax.rb +9 -5
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +3 -2
- data/lib/rubocop/cop/lint/unneeded_disable.rb +121 -18
- data/lib/rubocop/cop/lint/unreachable_code.rb +5 -4
- data/lib/rubocop/cop/lint/unused_block_argument.rb +9 -7
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +56 -29
- data/lib/rubocop/cop/lint/useless_assignment.rb +4 -16
- data/lib/rubocop/cop/lint/useless_comparison.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +2 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -20
- data/lib/rubocop/cop/lint/void.rb +10 -11
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -2
- data/lib/rubocop/cop/metrics/line_length.rb +35 -13
- data/lib/rubocop/cop/metrics/method_length.rb +2 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +2 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +4 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +3 -10
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +80 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +14 -20
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +5 -4
- data/lib/rubocop/cop/mixin/check_assignment.rb +20 -15
- data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
- data/lib/rubocop/cop/mixin/code_length.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +17 -15
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +4 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +9 -4
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +24 -16
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -2
- data/lib/rubocop/cop/mixin/hash_node.rb +15 -0
- data/lib/rubocop/cop/mixin/if_node.rb +1 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/method_preference.rb +1 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +1 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +177 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -0
- data/lib/rubocop/cop/mixin/on_method_def.rb +6 -5
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +1 -0
- data/lib/rubocop/cop/mixin/parentheses.rb +22 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +79 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_inside.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -5
- data/lib/rubocop/cop/mixin/string_help.rb +2 -9
- data/lib/rubocop/cop/mixin/string_literals_help.rb +13 -7
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +134 -0
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -0
- data/lib/rubocop/cop/offense.rb +19 -14
- data/lib/rubocop/cop/performance/case_when_splat.rb +8 -8
- data/lib/rubocop/cop/performance/casecmp.rb +54 -0
- data/lib/rubocop/cop/performance/count.rb +10 -9
- data/lib/rubocop/cop/performance/detect.rb +6 -5
- data/lib/rubocop/cop/performance/double_start_end_with.rb +65 -0
- data/lib/rubocop/cop/performance/end_with.rb +55 -0
- data/lib/rubocop/cop/performance/fixed_size.rb +1 -0
- data/lib/rubocop/cop/performance/flat_map.rb +9 -8
- data/lib/rubocop/cop/performance/hash_each.rb +86 -0
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +44 -0
- data/lib/rubocop/cop/performance/range_include.rb +40 -0
- data/lib/rubocop/cop/performance/redundant_block_call.rb +57 -0
- data/lib/rubocop/cop/performance/redundant_match.rb +51 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +85 -0
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +45 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +3 -2
- data/lib/rubocop/cop/performance/sample.rb +6 -5
- data/lib/rubocop/cop/performance/size.rb +2 -1
- data/lib/rubocop/cop/performance/start_with.rb +58 -0
- data/lib/rubocop/cop/performance/string_replacement.rb +18 -23
- data/lib/rubocop/cop/performance/times_map.rb +49 -0
- data/lib/rubocop/cop/rails/action_filter.rb +4 -3
- data/lib/rubocop/cop/rails/date.rb +5 -4
- data/lib/rubocop/cop/rails/delegate.rb +3 -2
- data/lib/rubocop/cop/rails/find_by.rb +20 -14
- data/lib/rubocop/cop/rails/find_each.rb +23 -2
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +3 -2
- data/lib/rubocop/cop/rails/output.rb +4 -2
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -7
- data/lib/rubocop/cop/rails/scope_args.rb +3 -2
- data/lib/rubocop/cop/rails/time_zone.rb +14 -10
- data/lib/rubocop/cop/rails/validation.rb +4 -3
- data/lib/rubocop/cop/severity.rb +8 -7
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +5 -4
- data/lib/rubocop/cop/style/accessor_method_name.rb +1 -0
- data/lib/rubocop/cop/style/alias.rb +84 -24
- data/lib/rubocop/cop/style/align_array.rb +2 -1
- data/lib/rubocop/cop/style/align_hash.rb +13 -14
- data/lib/rubocop/cop/style/align_parameters.rb +3 -2
- data/lib/rubocop/cop/style/and_or.rb +9 -7
- data/lib/rubocop/cop/style/array_join.rb +5 -5
- data/lib/rubocop/cop/style/ascii_comments.rb +2 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -1
- data/lib/rubocop/cop/style/attr.rb +30 -5
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -1
- data/lib/rubocop/cop/style/begin_block.rb +2 -1
- data/lib/rubocop/cop/style/block_comments.rb +2 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +10 -9
- data/lib/rubocop/cop/style/block_end_newline.rb +3 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +9 -8
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/case_indentation.rb +2 -1
- data/lib/rubocop/cop/style/character_literal.rb +11 -7
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +2 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +3 -2
- data/lib/rubocop/cop/style/class_check.rb +2 -1
- data/lib/rubocop/cop/style/class_methods.rb +2 -1
- data/lib/rubocop/cop/style/class_vars.rb +2 -1
- data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +3 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +3 -2
- data/lib/rubocop/cop/style/command_literal.rb +8 -7
- data/lib/rubocop/cop/style/comment_annotation.rb +3 -2
- data/lib/rubocop/cop/style/comment_indentation.rb +4 -6
- data/lib/rubocop/cop/style/conditional_assignment.rb +362 -0
- data/lib/rubocop/cop/style/constant_name.rb +2 -1
- data/lib/rubocop/cop/style/copyright.rb +7 -6
- data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +3 -2
- data/lib/rubocop/cop/style/documentation.rb +7 -11
- data/lib/rubocop/cop/style/dot_position.rb +3 -2
- data/lib/rubocop/cop/style/double_negation.rb +2 -1
- data/lib/rubocop/cop/style/each_with_object.rb +4 -3
- data/lib/rubocop/cop/style/else_alignment.rb +3 -2
- data/lib/rubocop/cop/style/empty_else.rb +4 -3
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/style/empty_lines.rb +10 -4
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +13 -5
- data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +7 -3
- data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +6 -3
- data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +4 -3
- data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +4 -2
- data/lib/rubocop/cop/style/empty_literal.rb +20 -5
- data/lib/rubocop/cop/style/encoding.rb +8 -11
- data/lib/rubocop/cop/style/end_block.rb +3 -1
- data/lib/rubocop/cop/style/end_of_line.rb +2 -1
- data/lib/rubocop/cop/style/even_odd.rb +4 -3
- data/lib/rubocop/cop/style/extra_spacing.rb +110 -74
- data/lib/rubocop/cop/style/file_name.rb +103 -6
- data/lib/rubocop/cop/style/first_array_element_line_break.rb +3 -2
- data/lib/rubocop/cop/style/first_hash_element_line_break.rb +5 -6
- data/lib/rubocop/cop/style/first_method_argument_line_break.rb +14 -1
- data/lib/rubocop/cop/style/first_method_parameter_line_break.rb +2 -1
- data/lib/rubocop/cop/style/first_parameter_indentation.rb +6 -4
- data/lib/rubocop/cop/style/flip_flop.rb +2 -1
- data/lib/rubocop/cop/style/for.rb +2 -1
- data/lib/rubocop/cop/style/format_string.rb +1 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -0
- data/lib/rubocop/cop/style/global_vars.rb +2 -1
- data/lib/rubocop/cop/style/guard_clause.rb +63 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +10 -10
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +93 -0
- data/lib/rubocop/cop/style/if_inside_else.rb +49 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +6 -5
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -1
- data/lib/rubocop/cop/style/indent_array.rb +89 -38
- data/lib/rubocop/cop/style/indent_assignment.rb +43 -0
- data/lib/rubocop/cop/style/indent_hash.rb +16 -77
- data/lib/rubocop/cop/style/indentation_consistency.rb +2 -1
- data/lib/rubocop/cop/style/indentation_width.rb +11 -11
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -9
- data/lib/rubocop/cop/style/initial_indentation.rb +2 -1
- data/lib/rubocop/cop/style/inline_comment.rb +2 -1
- data/lib/rubocop/cop/style/lambda.rb +14 -11
- data/lib/rubocop/cop/style/lambda_call.rb +4 -4
- data/lib/rubocop/cop/style/leading_comment_space.rb +2 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +3 -1
- data/lib/rubocop/cop/style/method_call_parentheses.rb +9 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -2
- data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -4
- data/lib/rubocop/cop/style/method_name.rb +1 -0
- data/lib/rubocop/cop/style/missing_else.rb +5 -3
- data/lib/rubocop/cop/style/module_function.rb +2 -1
- data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +95 -0
- data/lib/rubocop/cop/style/multiline_assignment_layout.rb +91 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -9
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -0
- data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +137 -0
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +25 -135
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -5
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_while.rb +3 -3
- data/lib/rubocop/cop/style/nested_modifier.rb +6 -5
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +48 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/next.rb +79 -15
- data/lib/rubocop/cop/style/nil_comparison.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
- data/lib/rubocop/cop/style/not.rb +5 -9
- data/lib/rubocop/cop/style/numeric_literals.rb +5 -4
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
- data/lib/rubocop/cop/style/op_method.rb +7 -4
- data/lib/rubocop/cop/style/option_hash.rb +13 -7
- data/lib/rubocop/cop/style/optional_arguments.rb +3 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +40 -16
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +3 -16
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -2
- data/lib/rubocop/cop/style/percent_q_literals.rb +3 -6
- data/lib/rubocop/cop/style/perl_backrefs.rb +4 -3
- data/lib/rubocop/cop/style/predicate_name.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +3 -2
- data/lib/rubocop/cop/style/raise_args.rb +2 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +5 -5
- data/lib/rubocop/cop/style/redundant_freeze.rb +5 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +80 -0
- data/lib/rubocop/cop/style/redundant_return.rb +5 -4
- data/lib/rubocop/cop/style/redundant_self.rb +7 -8
- data/lib/rubocop/cop/style/regexp_literal.rb +9 -8
- data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +3 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +11 -9
- data/lib/rubocop/cop/style/self_assignment.rb +4 -5
- data/lib/rubocop/cop/style/semicolon.rb +3 -2
- data/lib/rubocop/cop/style/send.rb +3 -1
- data/lib/rubocop/cop/style/signal_exception.rb +5 -3
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -7
- data/lib/rubocop/cop/style/space_after_colon.rb +2 -1
- data/lib/rubocop/cop/style/space_after_comma.rb +1 -0
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +5 -5
- data/lib/rubocop/cop/style/space_after_method_name.rb +3 -2
- data/lib/rubocop/cop/style/space_after_not.rb +4 -3
- data/lib/rubocop/cop/style/space_after_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +8 -7
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +72 -32
- data/lib/rubocop/cop/style/space_before_block_braces.rb +2 -1
- data/lib/rubocop/cop/style/space_before_comma.rb +1 -0
- data/lib/rubocop/cop/style/space_before_comment.rb +2 -1
- data/lib/rubocop/cop/style/{single_space_before_first_arg.rb → space_before_first_arg.rb} +13 -4
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +4 -3
- data/lib/rubocop/cop/style/space_before_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +3 -2
- data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +4 -1
- data/lib/rubocop/cop/style/space_inside_parens.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +5 -4
- data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +8 -17
- data/lib/rubocop/cop/style/special_global_vars.rb +97 -52
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +16 -9
- data/lib/rubocop/cop/style/string_literals.rb +41 -1
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +2 -1
- data/lib/rubocop/cop/style/string_methods.rb +2 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -2
- data/lib/rubocop/cop/style/symbol_array.rb +74 -7
- data/lib/rubocop/cop/style/symbol_literal.rb +4 -7
- data/lib/rubocop/cop/style/symbol_proc.rb +11 -7
- data/lib/rubocop/cop/style/tab.rb +25 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +56 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +8 -7
- data/lib/rubocop/cop/style/trailing_whitespace.rb +2 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +18 -9
- data/lib/rubocop/cop/style/unless_else.rb +2 -1
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +4 -3
- data/lib/rubocop/cop/style/unneeded_interpolation.rb +87 -0
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +23 -7
- data/lib/rubocop/cop/style/variable_interpolation.rb +8 -6
- data/lib/rubocop/cop/style/variable_name.rb +1 -0
- data/lib/rubocop/cop/style/when_then.rb +2 -1
- data/lib/rubocop/cop/style/while_until_do.rb +3 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +3 -4
- data/lib/rubocop/cop/style/word_array.rb +74 -51
- data/lib/rubocop/cop/team.rb +21 -15
- data/lib/rubocop/cop/util.rb +102 -69
- data/lib/rubocop/cop/variable_force.rb +2 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +2 -1
- data/lib/rubocop/cop/variable_force/locatable.rb +1 -0
- data/lib/rubocop/cop/variable_force/reference.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +2 -1
- data/lib/rubocop/cop/variable_force/variable.rb +2 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -1
- data/lib/rubocop/error.rb +12 -0
- data/lib/rubocop/formatter/base_formatter.rb +10 -1
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -0
- data/lib/rubocop/formatter/colorizable.rb +6 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +29 -15
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +3 -1
- data/lib/rubocop/formatter/emacs_style_formatter.rb +7 -3
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
- data/lib/rubocop/formatter/formatter_set.rb +10 -19
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -1
- data/lib/rubocop/formatter/html_formatter.rb +15 -14
- data/lib/rubocop/formatter/json_formatter.rb +2 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -0
- data/lib/rubocop/formatter/progress_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +50 -17
- data/lib/rubocop/formatter/text_util.rb +8 -10
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +61 -0
- data/lib/rubocop/name_similarity.rb +22 -0
- data/lib/rubocop/node_pattern.rb +126 -35
- data/lib/rubocop/options.rb +28 -19
- data/lib/rubocop/path_util.rb +1 -0
- data/lib/rubocop/processed_source.rb +41 -16
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -0
- data/lib/rubocop/result_cache.rb +60 -43
- data/lib/rubocop/runner.rb +48 -45
- data/lib/rubocop/string_util.rb +1 -0
- data/lib/rubocop/target_finder.rb +2 -1
- data/lib/rubocop/token.rb +1 -0
- data/lib/rubocop/version.rb +3 -2
- data/lib/rubocop/warning.rb +1 -0
- data/relnotes/v0.36.0.md +306 -0
- data/rubocop.gemspec +3 -9
- metadata +48 -92
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +0 -44
- data/lib/rubocop/cop/rails/default_scope.rb +0 -33
- data/lib/rubocop/cop/style/trailing_comma.rb +0 -182
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Style
|
7
|
+
# This cop checks whether the multiline assignments have a newline
|
8
|
+
# after the assignment operator.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad (with EnforcedStyle set to new_line)
|
12
|
+
# foo = if expression
|
13
|
+
# 'bar'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good (with EnforcedStyle set to same_line)
|
17
|
+
# foo = if expression
|
18
|
+
# 'bar'
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # good (with EnforcedStyle set to new_line)
|
22
|
+
# foo =
|
23
|
+
# if expression
|
24
|
+
# 'bar'
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # good (with EnforcedStyle set to new_line)
|
28
|
+
# foo =
|
29
|
+
# begin
|
30
|
+
# compute
|
31
|
+
# rescue => e
|
32
|
+
# nil
|
33
|
+
# end
|
34
|
+
class MultilineAssignmentLayout < Cop
|
35
|
+
include CheckAssignment
|
36
|
+
include ConfigurableEnforcedStyle
|
37
|
+
|
38
|
+
NEW_LINE_OFFENSE = 'Right hand side of multi-line assignment is on ' \
|
39
|
+
'the same line as the assignment operator `=`.'.freeze
|
40
|
+
|
41
|
+
SAME_LINE_OFFENSE = 'Right hand side of multi-line assignment is not ' \
|
42
|
+
'on the same line as the assignment operator `=`.'.freeze
|
43
|
+
|
44
|
+
def check_assignment(node, rhs)
|
45
|
+
return unless rhs
|
46
|
+
return unless supported_types.include?(rhs.type)
|
47
|
+
return if rhs.loc.first_line == rhs.loc.last_line
|
48
|
+
|
49
|
+
case style
|
50
|
+
when :new_line
|
51
|
+
check_new_line_offense(node, rhs)
|
52
|
+
when :same_line
|
53
|
+
check_same_line_offense(node, rhs)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_new_line_offense(node, rhs)
|
58
|
+
return unless node.loc.operator.line == rhs.loc.line
|
59
|
+
|
60
|
+
add_offense(node, :expression, NEW_LINE_OFFENSE)
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_same_line_offense(node, rhs)
|
64
|
+
return unless node.loc.operator.line != rhs.loc.line
|
65
|
+
|
66
|
+
add_offense(node, :expression, SAME_LINE_OFFENSE)
|
67
|
+
end
|
68
|
+
|
69
|
+
def autocorrect(node)
|
70
|
+
case style
|
71
|
+
when :new_line
|
72
|
+
->(corrector) { corrector.insert_after(node.loc.operator, "\n") }
|
73
|
+
when :same_line
|
74
|
+
range = Parser::Source::Range.new(
|
75
|
+
node.source_range.source_buffer,
|
76
|
+
node.loc.operator.end_pos,
|
77
|
+
extract_rhs(node).source_range.begin_pos)
|
78
|
+
|
79
|
+
->(corrector) { corrector.replace(range, ' ') }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def supported_types
|
86
|
+
@supported_types ||= cop_config['SupportedTypes'].map(&:to_sym)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -14,7 +15,7 @@ module RuboCop
|
|
14
15
|
# t.object_id
|
15
16
|
# end
|
16
17
|
class MultilineBlockChain < Cop
|
17
|
-
MSG = 'Avoid multi-line chains of blocks.'
|
18
|
+
MSG = 'Avoid multi-line chains of blocks.'.freeze
|
18
19
|
|
19
20
|
def on_block(node)
|
20
21
|
method, _args, _body = *node
|
@@ -31,7 +32,7 @@ module RuboCop
|
|
31
32
|
range =
|
32
33
|
Parser::Source::Range.new(end_kw_loc.source_buffer,
|
33
34
|
end_kw_loc.begin_pos,
|
34
|
-
method.
|
35
|
+
method.source_range.end_pos)
|
35
36
|
add_offense(nil, range)
|
36
37
|
# Done. If there are more blocks in the chain, they will be
|
37
38
|
# found by subsequent calls to on_block.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -36,9 +37,10 @@ module RuboCop
|
|
36
37
|
# bar(i)
|
37
38
|
# }
|
38
39
|
class MultilineBlockLayout < Cop
|
39
|
-
MSG = 'Block body expression is on the same line as
|
40
|
+
MSG = 'Block body expression is on the same line as ' \
|
41
|
+
'the block start.'.freeze
|
40
42
|
ARG_MSG = 'Block argument expression is not on the same line as the ' \
|
41
|
-
'block start.'
|
43
|
+
'block start.'.freeze
|
42
44
|
|
43
45
|
def on_block(node)
|
44
46
|
end_loc = node.loc.end
|
@@ -64,7 +66,7 @@ module RuboCop
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def add_offense_for_expression(node, expr, msg)
|
67
|
-
expression = expr.
|
69
|
+
expression = expr.source_range
|
68
70
|
range = Parser::Source::Range.new(expression.source_buffer,
|
69
71
|
expression.begin_pos,
|
70
72
|
expression.end_pos)
|
@@ -78,7 +80,7 @@ module RuboCop
|
|
78
80
|
unless args.children.empty? ||
|
79
81
|
args.loc.end.line == node.loc.begin.line
|
80
82
|
autocorrect_arguments(corrector, node, args, block_body)
|
81
|
-
expr_before_body = args.
|
83
|
+
expr_before_body = args.source_range.end
|
82
84
|
end
|
83
85
|
|
84
86
|
return unless block_body
|
@@ -92,11 +94,11 @@ module RuboCop
|
|
92
94
|
|
93
95
|
def autocorrect_arguments(corrector, node, args, block_body)
|
94
96
|
end_pos = if block_body
|
95
|
-
block_body.
|
97
|
+
block_body.source_range.begin_pos
|
96
98
|
else
|
97
99
|
node.loc.end.begin.begin_pos - 1
|
98
100
|
end
|
99
|
-
range = Parser::Source::Range.new(args.
|
101
|
+
range = Parser::Source::Range.new(args.source_range.source_buffer,
|
100
102
|
node.loc.begin.end.begin_pos,
|
101
103
|
end_pos)
|
102
104
|
corrector.replace(range, " |#{block_arg_string(args)}|")
|
@@ -109,14 +111,14 @@ module RuboCop
|
|
109
111
|
block_body
|
110
112
|
end
|
111
113
|
|
112
|
-
block_start_col = node.
|
114
|
+
block_start_col = node.source_range.column
|
113
115
|
|
114
|
-
corrector.insert_before(first_node.
|
116
|
+
corrector.insert_before(first_node.source_range,
|
115
117
|
"\n #{' ' * block_start_col}")
|
116
118
|
end
|
117
119
|
|
118
120
|
def block_arg_string(args)
|
119
|
-
args.children.map
|
121
|
+
args.children.map(&:source).join(', ')
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Style
|
7
|
+
# This cop checks the indentation of the method name part in method calls
|
8
|
+
# that span more than one line.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# while a
|
13
|
+
# .b
|
14
|
+
# something
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good, EnforcedStyle: aligned
|
18
|
+
# while a
|
19
|
+
# .b
|
20
|
+
# something
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # good, EnforcedStyle: aligned
|
24
|
+
# Thing.a
|
25
|
+
# .b
|
26
|
+
# .c
|
27
|
+
#
|
28
|
+
# # good, EnforcedStyle: indented
|
29
|
+
# while a
|
30
|
+
# .b
|
31
|
+
# something
|
32
|
+
# end
|
33
|
+
class MultilineMethodCallIndentation < Cop
|
34
|
+
include ConfigurableEnforcedStyle
|
35
|
+
include AutocorrectAlignment
|
36
|
+
include MultilineExpressionIndentation
|
37
|
+
|
38
|
+
def validate_config
|
39
|
+
if style == :aligned && cop_config['IndentationWidth']
|
40
|
+
fail ValidationError, 'The `Style/MultilineMethodCallIndentation`' \
|
41
|
+
' cop only accepts an `IndentationWidth` ' \
|
42
|
+
'configuration parameter when ' \
|
43
|
+
'`EnforcedStyle` is `indented`.'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def relevant_node?(send_node)
|
50
|
+
send_node.loc.dot # Only check method calls with dot operator
|
51
|
+
end
|
52
|
+
|
53
|
+
def offending_range(node, lhs, rhs, given_style)
|
54
|
+
return false unless begins_its_line?(rhs)
|
55
|
+
return false if not_for_this_cop?(node)
|
56
|
+
|
57
|
+
@base = alignment_base(node, rhs, given_style)
|
58
|
+
correct_column = if @base
|
59
|
+
@base.column
|
60
|
+
else
|
61
|
+
indentation(lhs) + correct_indentation(node)
|
62
|
+
end
|
63
|
+
@column_delta = correct_column - rhs.column
|
64
|
+
rhs if @column_delta != 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def message(node, lhs, rhs)
|
68
|
+
what = operation_description(node, rhs)
|
69
|
+
if @base
|
70
|
+
"Align `#{rhs.source}` with `#{@base.source[/[^\n]*/]}` on " \
|
71
|
+
"line #{@base.line}."
|
72
|
+
else
|
73
|
+
used_indentation = rhs.column - indentation(lhs)
|
74
|
+
"Use #{correct_indentation(node)} (not #{used_indentation}) " \
|
75
|
+
"spaces for indenting #{what} spanning multiple lines."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def alignment_base(node, rhs, given_style)
|
80
|
+
return nil unless given_style == :aligned
|
81
|
+
|
82
|
+
semantic_alignment_base(node, rhs) ||
|
83
|
+
syntactic_alignment_base(node, rhs)
|
84
|
+
end
|
85
|
+
|
86
|
+
def syntactic_alignment_base(lhs, rhs)
|
87
|
+
# a if b
|
88
|
+
# .c
|
89
|
+
n = kw_node_with_special_indentation(lhs)
|
90
|
+
if n
|
91
|
+
case n.type
|
92
|
+
when :if, :while, :until then expression, = *n
|
93
|
+
when :for then _, expression, = *n
|
94
|
+
when :return then expression, = *n
|
95
|
+
end
|
96
|
+
return expression.source_range
|
97
|
+
end
|
98
|
+
|
99
|
+
# a = b
|
100
|
+
# .c
|
101
|
+
n = part_of_assignment_rhs(lhs, rhs)
|
102
|
+
return assignment_rhs(n).source_range if n
|
103
|
+
|
104
|
+
# a + b
|
105
|
+
# .c
|
106
|
+
n = operation_rhs(lhs)
|
107
|
+
return n.source_range if n
|
108
|
+
end
|
109
|
+
|
110
|
+
# a.b
|
111
|
+
# .c
|
112
|
+
def semantic_alignment_base(node, rhs)
|
113
|
+
return nil unless rhs.source.start_with?('.')
|
114
|
+
return nil if argument_in_method_call(node)
|
115
|
+
|
116
|
+
node, = *node while node.send_type? && node.loc.dot ||
|
117
|
+
node.block_type?
|
118
|
+
return nil unless node.parent.send_type?
|
119
|
+
|
120
|
+
first_send = node.parent
|
121
|
+
return nil if first_send.loc.dot.line != first_send.loc.line
|
122
|
+
|
123
|
+
first_send.loc.dot.join(first_send.loc.selector)
|
124
|
+
end
|
125
|
+
|
126
|
+
def operation_rhs(node)
|
127
|
+
receiver, = *node
|
128
|
+
receiver.each_ancestor.select(&:send_type?).each do |a|
|
129
|
+
_, method, args = *a
|
130
|
+
return args if operator?(method) && within_node?(receiver, args)
|
131
|
+
end
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
5
6
|
module Style
|
6
|
-
# This
|
7
|
+
# This cop checks the indentation of the right hand side operand in
|
7
8
|
# binary operations that span more than one line.
|
8
9
|
#
|
9
10
|
# @example
|
@@ -15,6 +16,7 @@ module RuboCop
|
|
15
16
|
class MultilineOperationIndentation < Cop
|
16
17
|
include ConfigurableEnforcedStyle
|
17
18
|
include AutocorrectAlignment
|
19
|
+
include MultilineExpressionIndentation
|
18
20
|
|
19
21
|
def on_and(node)
|
20
22
|
check_and_or(node)
|
@@ -24,41 +26,25 @@ module RuboCop
|
|
24
26
|
check_and_or(node)
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
range = offending_range(node, lhs, rhs, style)
|
35
|
-
check(range, node, lhs, rhs)
|
29
|
+
def validate_config
|
30
|
+
if style == :aligned && cop_config['IndentationWidth']
|
31
|
+
fail ValidationError, 'The `Style/MultilineOperationIndentation`' \
|
32
|
+
' cop only accepts an `IndentationWidth` ' \
|
33
|
+
'configuration parameter when ' \
|
34
|
+
'`EnforcedStyle` is `indented`.'
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
def
|
41
|
-
|
42
|
-
range = offending_range(node, lhs, rhs.loc.expression, style)
|
43
|
-
check(range, node, lhs, rhs.loc.expression)
|
44
|
-
end
|
45
|
-
|
46
|
-
def check(range, node, lhs, rhs)
|
47
|
-
if range
|
48
|
-
incorrect_style_detected(range, node, lhs, rhs)
|
49
|
-
else
|
50
|
-
correct_style_detected
|
51
|
-
end
|
40
|
+
def relevant_node?(node)
|
41
|
+
!node.loc.dot # Don't check method calls with dot operator.
|
52
42
|
end
|
53
43
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
opposite_style_detected
|
60
|
-
end
|
61
|
-
end
|
44
|
+
def check_and_or(node)
|
45
|
+
lhs, rhs = *node
|
46
|
+
range = offending_range(node, lhs, rhs.source_range, style)
|
47
|
+
check(range, node, lhs, rhs.source_range)
|
62
48
|
end
|
63
49
|
|
64
50
|
def offending_range(node, lhs, rhs, given_style)
|
@@ -66,7 +52,7 @@ module RuboCop
|
|
66
52
|
return false if lhs.loc.line == rhs.line # Needed for unary op.
|
67
53
|
return false if not_for_this_cop?(node)
|
68
54
|
|
69
|
-
correct_column = if should_align?(node, given_style)
|
55
|
+
correct_column = if should_align?(node, rhs, given_style)
|
70
56
|
lhs.loc.column
|
71
57
|
else
|
72
58
|
indentation(lhs) + correct_indentation(node)
|
@@ -75,9 +61,15 @@ module RuboCop
|
|
75
61
|
rhs if @column_delta != 0
|
76
62
|
end
|
77
63
|
|
64
|
+
def should_align?(node, rhs, given_style)
|
65
|
+
given_style == :aligned && (kw_node_with_special_indentation(node) ||
|
66
|
+
part_of_assignment_rhs(node, rhs) ||
|
67
|
+
argument_in_method_call(node))
|
68
|
+
end
|
69
|
+
|
78
70
|
def message(node, lhs, rhs)
|
79
|
-
what = operation_description(node)
|
80
|
-
if should_align?(node, style)
|
71
|
+
what = operation_description(node, rhs)
|
72
|
+
if should_align?(node, rhs, style)
|
81
73
|
"Align the operands of #{what} spanning multiple lines."
|
82
74
|
else
|
83
75
|
used_indentation = rhs.column - indentation(lhs)
|
@@ -85,108 +77,6 @@ module RuboCop
|
|
85
77
|
"spaces for indenting #{what} spanning multiple lines."
|
86
78
|
end
|
87
79
|
end
|
88
|
-
|
89
|
-
def indentation(node)
|
90
|
-
node.loc.expression.source_line =~ /\S/
|
91
|
-
end
|
92
|
-
|
93
|
-
def operation_description(node)
|
94
|
-
ancestor = kw_node_with_special_indentation(node)
|
95
|
-
if ancestor
|
96
|
-
kw = ancestor.loc.keyword.source
|
97
|
-
kind = kw == 'for' ? 'collection' : 'condition'
|
98
|
-
article = kw =~ /^[iu]/ ? 'an' : 'a'
|
99
|
-
"a #{kind} in #{article} `#{kw}` statement"
|
100
|
-
else
|
101
|
-
'an expression' + (assignment_rhs?(node) ? ' in an assignment' : '')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# In a chain of method calls, we regard the top send node as the base
|
106
|
-
# for indentation of all lines following the first. For example:
|
107
|
-
# a.
|
108
|
-
# b c { block }. <-- b is indented relative to a
|
109
|
-
# d <-- d is indented relative to a
|
110
|
-
def left_hand_side(receiver)
|
111
|
-
lhs = receiver
|
112
|
-
while lhs.parent && lhs.parent.type == :send
|
113
|
-
_receiver, method_name, *_args = *lhs.parent
|
114
|
-
break if operator?(method_name)
|
115
|
-
lhs = lhs.parent
|
116
|
-
end
|
117
|
-
lhs
|
118
|
-
end
|
119
|
-
|
120
|
-
def right_hand_side(send_node)
|
121
|
-
_, method_name, *args = *send_node
|
122
|
-
if operator?(method_name) && args.any?
|
123
|
-
args.first.loc.expression
|
124
|
-
else
|
125
|
-
dot = send_node.loc.dot
|
126
|
-
selector = send_node.loc.selector
|
127
|
-
if dot && selector && dot.line == selector.line
|
128
|
-
dot.join(selector)
|
129
|
-
elsif selector
|
130
|
-
selector
|
131
|
-
elsif dot.line == send_node.loc.begin.line
|
132
|
-
# lambda.(args)
|
133
|
-
dot.join(send_node.loc.begin)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def correct_indentation(node)
|
139
|
-
multiplier = kw_node_with_special_indentation(node) ? 2 : 1
|
140
|
-
configured_indentation_width * multiplier
|
141
|
-
end
|
142
|
-
|
143
|
-
def should_align?(node, given_style)
|
144
|
-
given_style == :aligned && (kw_node_with_special_indentation(node) ||
|
145
|
-
assignment_rhs?(node))
|
146
|
-
end
|
147
|
-
|
148
|
-
def kw_node_with_special_indentation(node)
|
149
|
-
node.each_ancestor.find do |a|
|
150
|
-
next unless a.loc.respond_to?(:keyword)
|
151
|
-
|
152
|
-
case a.type
|
153
|
-
when :if, :while, :until then condition, = *a
|
154
|
-
when :for then _, collection, = *a
|
155
|
-
end
|
156
|
-
|
157
|
-
if condition || collection
|
158
|
-
within_node?(node, condition || collection)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def assignment_rhs?(node)
|
164
|
-
node.ancestors.unshift(node).each_cons(2).any? do |child, parent|
|
165
|
-
return true if parent.asgn_rhs.equal?(child)
|
166
|
-
grandparent = parent.parent
|
167
|
-
return true if grandparent && grandparent.masgn_type? &&
|
168
|
-
grandparent.asgn_rhs.equal?(parent)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def not_for_this_cop?(node)
|
173
|
-
node.each_ancestor.any? do |ancestor|
|
174
|
-
grouped_expression?(ancestor) ||
|
175
|
-
inside_arg_list_parentheses?(node, ancestor)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def grouped_expression?(node)
|
180
|
-
node.type == :begin && node.loc.respond_to?(:begin) && node.loc.begin
|
181
|
-
end
|
182
|
-
|
183
|
-
def inside_arg_list_parentheses?(node, ancestor)
|
184
|
-
a = ancestor.loc
|
185
|
-
return false unless ancestor.type == :send && a.begin &&
|
186
|
-
a.begin.is?('(')
|
187
|
-
n = node.loc.expression
|
188
|
-
n.begin_pos > a.begin.begin_pos && n.end_pos < a.end.end_pos
|
189
|
-
end
|
190
80
|
end
|
191
81
|
end
|
192
82
|
end
|