rubocop 0.49.1 → 0.50.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/README.md +5 -3
 - data/bin/rubocop +1 -1
 - data/config/default.yml +160 -99
 - data/config/disabled.yml +4 -5
 - data/config/enabled.yml +149 -47
 - data/lib/rubocop.rb +41 -14
 - data/lib/rubocop/ast/builder.rb +4 -1
 - data/lib/rubocop/ast/node.rb +36 -42
 - data/lib/rubocop/ast/node/args_node.rb +1 -13
 - data/lib/rubocop/ast/node/array_node.rb +9 -0
 - data/lib/rubocop/ast/node/block_node.rb +9 -0
 - data/lib/rubocop/ast/node/def_node.rb +71 -0
 - data/lib/rubocop/ast/node/for_node.rb +8 -0
 - data/lib/rubocop/ast/node/if_node.rb +10 -2
 - data/lib/rubocop/ast/node/mixin/collection_node.rb +15 -0
 - data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +174 -0
 - data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +89 -0
 - data/lib/rubocop/ast/node/mixin/parameterized_node.rb +18 -31
 - data/lib/rubocop/ast/node/regexp_node.rb +35 -0
 - data/lib/rubocop/ast/node/send_node.rb +1 -154
 - data/lib/rubocop/ast/node/super_node.rb +3 -24
 - data/lib/rubocop/ast/node/yield_node.rb +21 -0
 - data/lib/rubocop/ast/traversal.rb +6 -6
 - data/lib/rubocop/cli.rb +7 -3
 - data/lib/rubocop/config.rb +45 -8
 - data/lib/rubocop/config_loader.rb +7 -5
 - data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
 - data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +64 -0
 - data/lib/rubocop/cop/bundler/ordered_gems.rb +12 -12
 - data/lib/rubocop/cop/commissioner.rb +8 -2
 - data/lib/rubocop/cop/cop.rb +3 -1
 - data/lib/rubocop/cop/generator.rb +94 -21
 - data/lib/rubocop/cop/internal_affairs.rb +3 -0
 - data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +14 -3
 - data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +43 -0
 - data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +46 -0
 - data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +49 -0
 - data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -1
 - data/lib/rubocop/cop/layout/access_modifier_indentation.rb +2 -3
 - data/lib/rubocop/cop/layout/align_array.rb +2 -2
 - data/lib/rubocop/cop/layout/align_hash.rb +2 -2
 - data/lib/rubocop/cop/layout/align_parameters.rb +5 -11
 - data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
 - data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
 - data/lib/rubocop/cop/layout/dot_position.rb +9 -0
 - data/lib/rubocop/cop/layout/else_alignment.rb +30 -13
 - data/lib/rubocop/cop/layout/empty_line_between_defs.rb +4 -0
 - data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +20 -4
 - data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +3 -3
 - data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -3
 - data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +3 -3
 - data/lib/rubocop/cop/layout/first_parameter_indentation.rb +5 -2
 - data/lib/rubocop/cop/layout/indent_heredoc.rb +19 -24
 - data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -2
 - data/lib/rubocop/cop/layout/indentation_width.rb +12 -8
 - data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -18
 - data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +20 -17
 - data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +3 -3
 - data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -0
 - data/lib/rubocop/cop/layout/space_after_colon.rb +7 -0
 - data/lib/rubocop/cop/layout/space_after_comma.rb +10 -0
 - data/lib/rubocop/cop/layout/space_after_method_name.rb +5 -3
 - data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
 - data/lib/rubocop/cop/layout/space_around_block_parameters.rb +13 -4
 - data/lib/rubocop/cop/layout/space_around_keyword.rb +9 -5
 - data/lib/rubocop/cop/layout/space_before_block_braces.rb +54 -5
 - data/lib/rubocop/cop/layout/space_before_comment.rb +7 -0
 - data/lib/rubocop/cop/layout/space_before_semicolon.rb +7 -0
 - data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
 - data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
 - data/lib/rubocop/cop/layout/space_inside_range_literal.rb +1 -1
 - data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +8 -4
 - data/lib/rubocop/cop/layout/tab.rb +1 -1
 - data/lib/rubocop/cop/lint/ambiguous_block_association.rb +4 -2
 - data/lib/rubocop/cop/lint/assignment_in_condition.rb +15 -1
 - data/lib/rubocop/cop/lint/block_alignment.rb +15 -6
 - data/lib/rubocop/cop/lint/boolean_symbol.rb +38 -0
 - data/lib/rubocop/cop/lint/condition_position.rb +5 -1
 - data/lib/rubocop/cop/lint/debugger.rb +16 -9
 - data/lib/rubocop/cop/lint/def_end_alignment.rb +4 -4
 - data/lib/rubocop/cop/lint/duplicate_case_condition.rb +3 -3
 - data/lib/rubocop/cop/lint/duplicate_methods.rb +73 -5
 - data/lib/rubocop/cop/lint/duplicated_key.rb +1 -1
 - data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
 - data/lib/rubocop/cop/lint/else_layout.rb +1 -1
 - data/lib/rubocop/cop/lint/empty_expression.rb +1 -1
 - data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
 - data/lib/rubocop/cop/lint/empty_when.rb +1 -1
 - data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
 - data/lib/rubocop/cop/lint/float_out_of_range.rb +5 -5
 - data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +35 -40
 - data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
 - data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +18 -13
 - data/lib/rubocop/cop/lint/inherit_exception.rb +8 -7
 - data/lib/rubocop/cop/lint/interpolation_check.rb +36 -0
 - data/lib/rubocop/cop/lint/literal_in_condition.rb +3 -3
 - data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
 - data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
 - data/lib/rubocop/cop/lint/nested_method_definition.rb +5 -7
 - data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
 - data/lib/rubocop/cop/lint/percent_string_array.rb +3 -12
 - data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
 - data/lib/rubocop/cop/lint/rand_one.rb +7 -1
 - data/lib/rubocop/cop/lint/redundant_with_index.rb +77 -0
 - data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
 - data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
 - data/lib/rubocop/cop/lint/rescue_type.rb +13 -6
 - data/lib/rubocop/cop/lint/rescue_without_error_class.rb +38 -0
 - data/lib/rubocop/cop/lint/return_in_void_context.rb +63 -0
 - data/lib/rubocop/cop/lint/script_permission.rb +6 -0
 - data/lib/rubocop/cop/lint/syntax.rb +17 -20
 - data/lib/rubocop/cop/lint/unified_integer.rb +3 -2
 - data/lib/rubocop/cop/lint/unneeded_disable.rb +1 -1
 - data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
 - data/lib/rubocop/cop/lint/unreachable_code.rb +53 -8
 - data/lib/rubocop/cop/lint/uri_escape_unescape.rb +74 -0
 - data/lib/rubocop/cop/lint/uri_regexp.rb +73 -0
 - data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -8
 - data/lib/rubocop/cop/lint/useless_setter_call.rb +10 -11
 - data/lib/rubocop/cop/lint/void.rb +29 -23
 - data/lib/rubocop/cop/metrics/line_length.rb +2 -2
 - data/lib/rubocop/cop/metrics/method_length.rb +8 -3
 - data/lib/rubocop/cop/metrics/parameter_lists.rb +5 -2
 - data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
 - data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -2
 - data/lib/rubocop/cop/mixin/first_element_line_break.rb +12 -3
 - data/lib/rubocop/cop/mixin/heredoc.rb +28 -0
 - data/lib/rubocop/cop/mixin/method_complexity.rb +9 -6
 - data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +68 -31
 - data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +18 -0
 - data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
 - data/lib/rubocop/cop/mixin/percent_array.rb +52 -0
 - data/lib/rubocop/cop/mixin/string_help.rb +1 -1
 - data/lib/rubocop/cop/{style → naming}/accessor_method_name.rb +11 -12
 - data/lib/rubocop/cop/{style → naming}/ascii_identifiers.rb +1 -1
 - data/lib/rubocop/cop/{style/op_method.rb → naming/binary_operator_parameter_name.rb} +2 -2
 - data/lib/rubocop/cop/{style → naming}/class_and_module_camel_case.rb +1 -1
 - data/lib/rubocop/cop/{style → naming}/constant_name.rb +1 -1
 - data/lib/rubocop/cop/{style → naming}/file_name.rb +8 -4
 - data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +68 -0
 - data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +58 -0
 - data/lib/rubocop/cop/{style → naming}/method_name.rb +1 -1
 - data/lib/rubocop/cop/{style → naming}/predicate_name.rb +6 -7
 - data/lib/rubocop/cop/{style → naming}/variable_name.rb +11 -15
 - data/lib/rubocop/cop/{style → naming}/variable_number.rb +1 -1
 - data/lib/rubocop/cop/performance/caller.rb +39 -11
 - data/lib/rubocop/cop/performance/casecmp.rb +4 -4
 - data/lib/rubocop/cop/performance/compare_with_block.rb +4 -4
 - data/lib/rubocop/cop/performance/double_start_end_with.rb +4 -4
 - data/lib/rubocop/cop/performance/end_with.rb +3 -3
 - data/lib/rubocop/cop/performance/fixed_size.rb +1 -1
 - data/lib/rubocop/cop/performance/hash_each_methods.rb +66 -25
 - data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -2
 - data/lib/rubocop/cop/performance/range_include.rb +2 -2
 - data/lib/rubocop/cop/performance/redundant_block_call.rb +6 -6
 - data/lib/rubocop/cop/performance/redundant_match.rb +5 -5
 - data/lib/rubocop/cop/performance/redundant_merge.rb +39 -23
 - data/lib/rubocop/cop/performance/redundant_sort_by.rb +2 -2
 - data/lib/rubocop/cop/performance/regexp_match.rb +13 -5
 - data/lib/rubocop/cop/performance/size.rb +1 -1
 - data/lib/rubocop/cop/performance/start_with.rb +3 -3
 - data/lib/rubocop/cop/performance/times_map.rb +23 -12
 - data/lib/rubocop/cop/performance/unfreeze_string.rb +50 -0
 - data/lib/rubocop/cop/performance/uri_default_parser.rb +47 -0
 - data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
 - data/lib/rubocop/cop/rails/delegate.rb +36 -7
 - data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
 - data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -2
 - data/lib/rubocop/cop/rails/file_path.rb +3 -4
 - data/lib/rubocop/cop/rails/find_each.rb +1 -1
 - data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +48 -0
 - data/lib/rubocop/cop/rails/http_positional_arguments.rb +5 -5
 - data/lib/rubocop/cop/rails/not_null_column.rb +1 -1
 - data/lib/rubocop/cop/rails/pluralization_grammar.rb +2 -2
 - data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
 - data/lib/rubocop/cop/rails/request_referer.rb +2 -2
 - data/lib/rubocop/cop/rails/reversible_migration.rb +12 -12
 - data/lib/rubocop/cop/rails/save_bang.rb +8 -6
 - data/lib/rubocop/cop/rails/scope_args.rb +1 -1
 - data/lib/rubocop/cop/security/eval.rb +2 -2
 - data/lib/rubocop/cop/security/json_load.rb +2 -2
 - data/lib/rubocop/cop/security/marshal_load.rb +2 -2
 - data/lib/rubocop/cop/security/yaml_load.rb +2 -2
 - data/lib/rubocop/cop/style/alias.rb +44 -20
 - data/lib/rubocop/cop/style/and_or.rb +48 -34
 - data/lib/rubocop/cop/style/auto_resource_cleanup.rb +1 -1
 - data/lib/rubocop/cop/style/block_comments.rb +3 -1
 - data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
 - data/lib/rubocop/cop/style/command_literal.rb +20 -9
 - data/lib/rubocop/cop/style/conditional_assignment.rb +30 -28
 - data/lib/rubocop/cop/style/copyright.rb +10 -10
 - data/lib/rubocop/cop/style/def_with_parentheses.rb +6 -5
 - data/lib/rubocop/cop/style/dir.rb +52 -0
 - data/lib/rubocop/cop/style/documentation_method.rb +2 -6
 - data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
 - data/lib/rubocop/cop/style/empty_else.rb +3 -2
 - data/lib/rubocop/cop/style/empty_literal.rb +1 -2
 - data/lib/rubocop/cop/style/empty_method.rb +27 -17
 - data/lib/rubocop/cop/style/flip_flop.rb +2 -2
 - data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
 - data/lib/rubocop/cop/style/guard_clause.rb +4 -2
 - data/lib/rubocop/cop/style/hash_syntax.rb +10 -10
 - data/lib/rubocop/cop/style/identical_conditional_branches.rb +5 -1
 - data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
 - data/lib/rubocop/cop/style/implicit_runtime_error.rb +4 -3
 - data/lib/rubocop/cop/style/inline_comment.rb +1 -1
 - data/lib/rubocop/cop/style/inverse_methods.rb +20 -8
 - data/lib/rubocop/cop/style/lambda.rb +19 -9
 - data/lib/rubocop/cop/style/lambda_call.rb +22 -1
 - data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +4 -20
 - data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -4
 - data/lib/rubocop/cop/style/method_def_parentheses.rb +18 -26
 - data/lib/rubocop/cop/style/method_missing.rb +5 -18
 - data/lib/rubocop/cop/style/min_max.rb +67 -0
 - data/lib/rubocop/cop/style/missing_else.rb +16 -3
 - data/lib/rubocop/cop/style/mixin_grouping.rb +2 -2
 - data/lib/rubocop/cop/style/module_function.rb +8 -4
 - data/lib/rubocop/cop/style/multiline_if_modifier.rb +5 -1
 - data/lib/rubocop/cop/style/multiline_memoization.rb +25 -3
 - data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
 - data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
 - data/lib/rubocop/cop/style/mutable_constant.rb +2 -6
 - data/lib/rubocop/cop/style/negated_if.rb +8 -4
 - data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +8 -8
 - data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
 - data/lib/rubocop/cop/style/non_nil_check.rb +14 -14
 - data/lib/rubocop/cop/style/numeric_literal_prefix.rb +6 -2
 - data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
 - data/lib/rubocop/cop/style/numeric_predicate.rb +8 -4
 - data/lib/rubocop/cop/style/one_line_conditional.rb +8 -3
 - data/lib/rubocop/cop/style/option_hash.rb +1 -1
 - data/lib/rubocop/cop/style/optional_arguments.rb +1 -2
 - data/lib/rubocop/cop/style/or_assignment.rb +88 -0
 - data/lib/rubocop/cop/style/parallel_assignment.rb +2 -2
 - data/lib/rubocop/cop/style/parentheses_around_condition.rb +12 -11
 - data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
 - data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
 - data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
 - data/lib/rubocop/cop/style/proc.rb +1 -1
 - data/lib/rubocop/cop/style/raise_args.rb +16 -17
 - data/lib/rubocop/cop/style/redundant_begin.rb +6 -5
 - data/lib/rubocop/cop/style/redundant_conditional.rb +95 -0
 - data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
 - data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -11
 - data/lib/rubocop/cop/style/redundant_return.rb +23 -11
 - data/lib/rubocop/cop/style/redundant_self.rb +18 -9
 - data/lib/rubocop/cop/style/regexp_literal.rb +12 -4
 - data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
 - data/lib/rubocop/cop/style/return_nil.rb +98 -0
 - data/lib/rubocop/cop/style/safe_navigation.rb +80 -43
 - data/lib/rubocop/cop/style/single_line_block_params.rb +14 -13
 - data/lib/rubocop/cop/style/single_line_methods.rb +9 -13
 - data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
 - data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +17 -39
 - data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +22 -1
 - data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
 - data/lib/rubocop/cop/style/symbol_array.rb +5 -25
 - data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
 - data/lib/rubocop/cop/style/symbol_proc.rb +3 -18
 - data/lib/rubocop/cop/style/ternary_parentheses.rb +14 -10
 - data/lib/rubocop/cop/style/trailing_underscore_variable.rb +28 -9
 - data/lib/rubocop/cop/style/trivial_accessors.rb +39 -56
 - data/lib/rubocop/cop/style/unless_else.rb +1 -1
 - data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
 - data/lib/rubocop/cop/style/unneeded_interpolation.rb +1 -1
 - data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
 - data/lib/rubocop/cop/style/variable_interpolation.rb +8 -3
 - data/lib/rubocop/cop/style/word_array.rb +7 -24
 - data/lib/rubocop/cop/style/yoda_condition.rb +49 -14
 - data/lib/rubocop/cop/style/zero_length_predicate.rb +25 -18
 - data/lib/rubocop/cop/team.rb +16 -8
 - data/lib/rubocop/cop/util.rb +11 -0
 - data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
 - data/lib/rubocop/formatter/formatter_set.rb +2 -1
 - data/lib/rubocop/formatter/offense_count_formatter.rb +2 -0
 - data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
 - data/lib/rubocop/formatter/tap_formatter.rb +71 -0
 - data/lib/rubocop/formatter/worst_offenders_formatter.rb +2 -0
 - data/lib/rubocop/node_pattern.rb +44 -26
 - data/lib/rubocop/options.rb +1 -0
 - data/lib/rubocop/processed_source.rb +3 -1
 - data/lib/rubocop/remote_config.rb +5 -1
 - data/lib/rubocop/result_cache.rb +1 -0
 - data/lib/rubocop/rspec/cop_helper.rb +10 -10
 - data/lib/rubocop/rspec/expect_offense.rb +6 -8
 - data/lib/rubocop/rspec/shared_examples.rb +8 -8
 - data/lib/rubocop/string_util.rb +2 -0
 - data/lib/rubocop/version.rb +1 -1
 - metadata +51 -18
 - data/lib/rubocop/cop/mixin/access_modifier_node.rb +0 -41
 - data/lib/rubocop/cop/mixin/on_method_def.rb +0 -44
 
| 
         @@ -3,60 +3,72 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module RuboCop
         
     | 
| 
       4 
4 
     | 
    
         
             
              module Cop
         
     | 
| 
       5 
5 
     | 
    
         
             
                module Style
         
     | 
| 
       6 
     | 
    
         
            -
                  # This cop checks for uses of  
     | 
| 
      
 6 
     | 
    
         
            +
                  # This cop checks for uses of `and` and `or`, and suggests using `&&` and
         
     | 
| 
      
 7 
     | 
    
         
            +
                  # `|| instead`. It can be configured to check only in conditions, or in
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # all contexts.
         
     | 
| 
      
 9 
     | 
    
         
            +
                  #
         
     | 
| 
      
 10 
     | 
    
         
            +
                  # @example
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #
         
     | 
| 
      
 12 
     | 
    
         
            +
                  #   # EnforcedStyle: always (default)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #
         
     | 
| 
      
 14 
     | 
    
         
            +
                  #   # good
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #   foo.save && return
         
     | 
| 
      
 16 
     | 
    
         
            +
                  #   if foo && bar
         
     | 
| 
      
 17 
     | 
    
         
            +
                  #
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #   # bad
         
     | 
| 
      
 19 
     | 
    
         
            +
                  #   foo.save and return
         
     | 
| 
      
 20 
     | 
    
         
            +
                  #   if foo and bar
         
     | 
| 
      
 21 
     | 
    
         
            +
                  #
         
     | 
| 
      
 22 
     | 
    
         
            +
                  # @example
         
     | 
| 
      
 23 
     | 
    
         
            +
                  #
         
     | 
| 
      
 24 
     | 
    
         
            +
                  #   # EnforcedStyle: conditionals
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #   # good
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #   foo.save && return
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #   foo.save and return
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #   if foo && bar
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #   # bad
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #   if foo and bar
         
     | 
| 
       7 
33 
     | 
    
         
             
                  class AndOr < Cop
         
     | 
| 
       8 
34 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       9 
35 
     | 
    
         | 
| 
       10 
36 
     | 
    
         
             
                    MSG = 'Use `%s` instead of `%s`.'.freeze
         
     | 
| 
       11 
37 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                    OPS = { 'and' => '&&', 'or' => '||' }.freeze
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
38 
     | 
    
         
             
                    def on_and(node)
         
     | 
| 
       15 
     | 
    
         
            -
                       
     | 
| 
       16 
     | 
    
         
            -
                    end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                    def on_or(node)
         
     | 
| 
       19 
     | 
    
         
            -
                      process_logical_op(node) if style == :always
         
     | 
| 
      
 39 
     | 
    
         
            +
                      process_logical_operator(node) if style == :always
         
     | 
| 
       20 
40 
     | 
    
         
             
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                    alias on_or on_and
         
     | 
| 
       21 
42 
     | 
    
         | 
| 
       22 
43 
     | 
    
         
             
                    def on_if(node)
         
     | 
| 
       23 
44 
     | 
    
         
             
                      on_conditionals(node) if style == :conditionals
         
     | 
| 
       24 
45 
     | 
    
         
             
                    end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                     
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                     
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                    def on_while_post(node)
         
     | 
| 
       31 
     | 
    
         
            -
                      on_conditionals(node) if style == :conditionals
         
     | 
| 
       32 
     | 
    
         
            -
                    end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                    def on_until(node)
         
     | 
| 
       35 
     | 
    
         
            -
                      on_conditionals(node) if style == :conditionals
         
     | 
| 
       36 
     | 
    
         
            -
                    end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                    def on_until_post(node)
         
     | 
| 
       39 
     | 
    
         
            -
                      on_conditionals(node) if style == :conditionals
         
     | 
| 
       40 
     | 
    
         
            -
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
                    alias on_while      on_if
         
     | 
| 
      
 47 
     | 
    
         
            +
                    alias on_while_post on_if
         
     | 
| 
      
 48 
     | 
    
         
            +
                    alias on_until      on_if
         
     | 
| 
      
 49 
     | 
    
         
            +
                    alias on_until_post on_if
         
     | 
| 
       41 
50 
     | 
    
         | 
| 
       42 
51 
     | 
    
         
             
                    private
         
     | 
| 
       43 
52 
     | 
    
         | 
| 
       44 
53 
     | 
    
         
             
                    def on_conditionals(node)
         
     | 
| 
       45 
54 
     | 
    
         
             
                      node.condition.each_node(*LOGICAL_OPERATOR_NODES) do |logical_node|
         
     | 
| 
       46 
     | 
    
         
            -
                         
     | 
| 
      
 55 
     | 
    
         
            +
                        process_logical_operator(logical_node)
         
     | 
| 
       47 
56 
     | 
    
         
             
                      end
         
     | 
| 
       48 
57 
     | 
    
         
             
                    end
         
     | 
| 
       49 
58 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                    def  
     | 
| 
      
 59 
     | 
    
         
            +
                    def process_logical_operator(node)
         
     | 
| 
       51 
60 
     | 
    
         
             
                      return if node.logical_operator?
         
     | 
| 
       52 
61 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                      add_offense(node, :operator 
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
                      add_offense(node, :operator)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                    def message(node)
         
     | 
| 
      
 66 
     | 
    
         
            +
                      format(MSG, node.alternate_operator, node.operator)
         
     | 
| 
       55 
67 
     | 
    
         
             
                    end
         
     | 
| 
       56 
68 
     | 
    
         | 
| 
       57 
69 
     | 
    
         
             
                    def autocorrect(node)
         
     | 
| 
       58 
70 
     | 
    
         
             
                      lambda do |corrector|
         
     | 
| 
       59 
     | 
    
         
            -
                         
     | 
| 
      
 71 
     | 
    
         
            +
                        node.each_child_node do |expr|
         
     | 
| 
       60 
72 
     | 
    
         
             
                          if expr.send_type?
         
     | 
| 
       61 
73 
     | 
    
         
             
                            correct_send(expr, corrector)
         
     | 
| 
       62 
74 
     | 
    
         
             
                          elsif expr.return_type?
         
     | 
| 
         @@ -73,15 +85,17 @@ module RuboCop 
     | 
|
| 
       73 
85 
     | 
    
         
             
                    def correct_send(node, corrector)
         
     | 
| 
       74 
86 
     | 
    
         
             
                      return correct_not(node, node.receiver, corrector) if node.method?(:!)
         
     | 
| 
       75 
87 
     | 
    
         
             
                      return correct_setter(node, corrector) if node.setter_method?
         
     | 
| 
      
 88 
     | 
    
         
            +
                      return correct_other(node, corrector) if node.comparison_method?
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
       76 
90 
     | 
    
         
             
                      return unless correctable_send?(node)
         
     | 
| 
       77 
91 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
                      corrector.replace(whitespace_before_arg(node), '(' 
     | 
| 
       79 
     | 
    
         
            -
                      corrector.insert_after(node.last_argument.source_range, ')' 
     | 
| 
      
 92 
     | 
    
         
            +
                      corrector.replace(whitespace_before_arg(node), '(')
         
     | 
| 
      
 93 
     | 
    
         
            +
                      corrector.insert_after(node.last_argument.source_range, ')')
         
     | 
| 
       80 
94 
     | 
    
         
             
                    end
         
     | 
| 
       81 
95 
     | 
    
         | 
| 
       82 
96 
     | 
    
         
             
                    def correct_setter(node, corrector)
         
     | 
| 
       83 
     | 
    
         
            -
                      corrector.insert_before(node.receiver.source_range, '(' 
     | 
| 
       84 
     | 
    
         
            -
                      corrector.insert_after(node.last_argument.source_range, ')' 
     | 
| 
      
 97 
     | 
    
         
            +
                      corrector.insert_before(node.receiver.source_range, '(')
         
     | 
| 
      
 98 
     | 
    
         
            +
                      corrector.insert_after(node.last_argument.source_range, ')')
         
     | 
| 
       85 
99 
     | 
    
         
             
                    end
         
     | 
| 
       86 
100 
     | 
    
         | 
| 
       87 
101 
     | 
    
         
             
                    # ! is a special case:
         
     | 
| 
         @@ -108,7 +122,7 @@ module RuboCop 
     | 
|
| 
       108 
122 
     | 
    
         
             
                    end
         
     | 
| 
       109 
123 
     | 
    
         | 
| 
       110 
124 
     | 
    
         
             
                    def correctable_send?(node)
         
     | 
| 
       111 
     | 
    
         
            -
                      !node.parenthesized? && !node.method?(:[]) 
     | 
| 
      
 125 
     | 
    
         
            +
                      !node.parenthesized? && node.arguments? && !node.method?(:[])
         
     | 
| 
       112 
126 
     | 
    
         
             
                    end
         
     | 
| 
       113 
127 
     | 
    
         | 
| 
       114 
128 
     | 
    
         
             
                    def whitespace_before_arg(node)
         
     | 
| 
         @@ -111,6 +111,7 @@ module RuboCop 
     | 
|
| 
       111 
111 
     | 
    
         
             
                      range.source_buffer.source[range.begin_pos + length, 1] =~ /\s/
         
     | 
| 
       112 
112 
     | 
    
         
             
                    end
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
      
 114 
     | 
    
         
            +
                    # rubocop:disable Metrics/CyclomaticComplexity
         
     | 
| 
       114 
115 
     | 
    
         
             
                    def get_blocks(node, &block)
         
     | 
| 
       115 
116 
     | 
    
         
             
                      case node.type
         
     | 
| 
       116 
117 
     | 
    
         
             
                      when :block
         
     | 
| 
         @@ -126,8 +127,8 @@ module RuboCop 
     | 
|
| 
       126 
127 
     | 
    
         
             
                      when :pair
         
     | 
| 
       127 
128 
     | 
    
         
             
                        node.each_child_node { |child| get_blocks(child, &block) }
         
     | 
| 
       128 
129 
     | 
    
         
             
                      end
         
     | 
| 
       129 
     | 
    
         
            -
                      nil
         
     | 
| 
       130 
130 
     | 
    
         
             
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    # rubocop:enable Metrics/CyclimaticComplexity
         
     | 
| 
       131 
132 
     | 
    
         | 
| 
       132 
133 
     | 
    
         
             
                    def proper_block_style?(node)
         
     | 
| 
       133 
134 
     | 
    
         
             
                      return true if ignored_method?(node.method_name)
         
     | 
| 
         @@ -47,26 +47,37 @@ module RuboCop 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    def check_backtick_literal(node)
         
     | 
| 
       48 
48 
     | 
    
         
             
                      return if allowed_backtick_literal?(node)
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                      add_offense(node 
     | 
| 
      
 50 
     | 
    
         
            +
                      add_offense(node)
         
     | 
| 
       51 
51 
     | 
    
         
             
                    end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
                    def check_percent_x_literal(node)
         
     | 
| 
       54 
54 
     | 
    
         
             
                      return if allowed_percent_x_literal?(node)
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
                      add_offense(node 
     | 
| 
      
 56 
     | 
    
         
            +
                      add_offense(node)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    def message(node)
         
     | 
| 
      
 60 
     | 
    
         
            +
                      backtick_literal?(node) ? MSG_USE_PERCENT_X : MSG_USE_BACKTICKS
         
     | 
| 
       57 
61 
     | 
    
         
             
                    end
         
     | 
| 
       58 
62 
     | 
    
         | 
| 
       59 
63 
     | 
    
         
             
                    def allowed_backtick_literal?(node)
         
     | 
| 
       60 
     | 
    
         
            -
                      style 
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                      case style
         
     | 
| 
      
 65 
     | 
    
         
            +
                      when :backticks
         
     | 
| 
      
 66 
     | 
    
         
            +
                        !contains_disallowed_backtick?(node)
         
     | 
| 
      
 67 
     | 
    
         
            +
                      when :mixed
         
     | 
| 
      
 68 
     | 
    
         
            +
                        node.single_line? && !contains_disallowed_backtick?(node)
         
     | 
| 
      
 69 
     | 
    
         
            +
                      end
         
     | 
| 
       63 
70 
     | 
    
         
             
                    end
         
     | 
| 
       64 
71 
     | 
    
         | 
| 
       65 
72 
     | 
    
         
             
                    def allowed_percent_x_literal?(node)
         
     | 
| 
       66 
     | 
    
         
            -
                      style 
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 73 
     | 
    
         
            +
                      case style
         
     | 
| 
      
 74 
     | 
    
         
            +
                      when :backticks
         
     | 
| 
      
 75 
     | 
    
         
            +
                        contains_disallowed_backtick?(node)
         
     | 
| 
      
 76 
     | 
    
         
            +
                      when :mixed
         
     | 
| 
      
 77 
     | 
    
         
            +
                        node.multiline? || contains_disallowed_backtick?(node)
         
     | 
| 
      
 78 
     | 
    
         
            +
                      when :percent_x
         
     | 
| 
      
 79 
     | 
    
         
            +
                        true
         
     | 
| 
      
 80 
     | 
    
         
            +
                      end
         
     | 
| 
       70 
81 
     | 
    
         
             
                    end
         
     | 
| 
       71 
82 
     | 
    
         | 
| 
       72 
83 
     | 
    
         
             
                    def contains_disallowed_backtick?(node)
         
     | 
| 
         @@ -6,6 +6,8 @@ module RuboCop 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  # Helper module to provide common methods to classes needed for the
         
     | 
| 
       7 
7 
     | 
    
         
             
                  # ConditionalAssignment Cop.
         
     | 
| 
       8 
8 
     | 
    
         
             
                  module ConditionalAssignmentHelper
         
     | 
| 
      
 9 
     | 
    
         
            +
                    extend NodePattern::Macros
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       9 
11 
     | 
    
         
             
                    EQUAL = '='.freeze
         
     | 
| 
       10 
12 
     | 
    
         
             
                    END_ALIGNMENT = 'Lint/EndAlignment'.freeze
         
     | 
| 
       11 
13 
     | 
    
         
             
                    ALIGN_WITH = 'EnforcedStyleAlignWith'.freeze
         
     | 
| 
         @@ -31,6 +33,7 @@ module RuboCop 
     | 
|
| 
       31 
33 
     | 
    
         
             
                      branch.begin_type? ? [*branch].last : branch
         
     | 
| 
       32 
34 
     | 
    
         
             
                    end
         
     | 
| 
       33 
35 
     | 
    
         | 
| 
      
 36 
     | 
    
         
            +
                    # rubocop:disable Metrics/AbcSize
         
     | 
| 
       34 
37 
     | 
    
         
             
                    def lhs(node)
         
     | 
| 
       35 
38 
     | 
    
         
             
                      case node.type
         
     | 
| 
       36 
39 
     | 
    
         
             
                      when :send
         
     | 
| 
         @@ -47,6 +50,7 @@ module RuboCop 
     | 
|
| 
       47 
50 
     | 
    
         
             
                        node.source
         
     | 
| 
       48 
51 
     | 
    
         
             
                      end
         
     | 
| 
       49 
52 
     | 
    
         
             
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                    # rubocop:enable Metrics/AbcSize
         
     | 
| 
       50 
54 
     | 
    
         | 
| 
       51 
55 
     | 
    
         
             
                    def indent(cop, source)
         
     | 
| 
       52 
56 
     | 
    
         
             
                      conf = cop.config.for_cop(END_ALIGNMENT)
         
     | 
| 
         @@ -219,12 +223,12 @@ module RuboCop 
     | 
|
| 
       219 
223 
     | 
    
         | 
| 
       220 
224 
     | 
    
         
             
                    # The shovel operator `<<` does not have its own type. It is a `send`
         
     | 
| 
       221 
225 
     | 
    
         
             
                    # type.
         
     | 
| 
       222 
     | 
    
         
            -
                    def_node_matcher :assignment_type?, <<- 
     | 
| 
      
 226 
     | 
    
         
            +
                    def_node_matcher :assignment_type?, <<-PATTERN
         
     | 
| 
       223 
227 
     | 
    
         
             
                      {
         
     | 
| 
       224 
228 
     | 
    
         
             
                        #{ASSIGNMENT_TYPES.join(' ')}
         
     | 
| 
       225 
229 
     | 
    
         
             
                        (send _recv {:[]= :<< :=~ :!~ :<=> #end_with_eq?} ...)
         
     | 
| 
       226 
230 
     | 
    
         
             
                      }
         
     | 
| 
       227 
     | 
    
         
            -
                     
     | 
| 
      
 231 
     | 
    
         
            +
                    PATTERN
         
     | 
| 
       228 
232 
     | 
    
         | 
| 
       229 
233 
     | 
    
         
             
                    ASSIGNMENT_TYPES.each do |type|
         
     | 
| 
       230 
234 
     | 
    
         
             
                      define_method "on_#{type}" do |node|
         
     | 
| 
         @@ -267,21 +271,27 @@ module RuboCop 
     | 
|
| 
       267 
271 
     | 
    
         
             
                    private
         
     | 
| 
       268 
272 
     | 
    
         | 
| 
       269 
273 
     | 
    
         
             
                    def check_assignment_to_condition(node)
         
     | 
| 
       270 
     | 
    
         
            -
                      return unless  
     | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
      
 274 
     | 
    
         
            +
                      return unless candidate_node?(node)
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
       272 
276 
     | 
    
         
             
                      ignore_node(node)
         
     | 
| 
       273 
277 
     | 
    
         | 
| 
       274 
278 
     | 
    
         
             
                      assignment = assignment_node(node)
         
     | 
| 
       275 
     | 
    
         
            -
                      return unless  
     | 
| 
       276 
     | 
    
         
            -
                      return if allowed_ternary?(assignment)
         
     | 
| 
      
 279 
     | 
    
         
            +
                      return unless candidate_condition?(assignment)
         
     | 
| 
       277 
280 
     | 
    
         | 
| 
       278 
281 
     | 
    
         
             
                      _condition, *branches, else_branch = *assignment
         
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
                      return unless else_branch
         
     | 
| 
       280 
284 
     | 
    
         
             
                      return if allowed_single_line?([*branches, else_branch])
         
     | 
| 
       281 
285 
     | 
    
         | 
| 
       282 
286 
     | 
    
         
             
                      add_offense(node, :expression, ASSIGN_TO_CONDITION_MSG)
         
     | 
| 
       283 
287 
     | 
    
         
             
                    end
         
     | 
| 
       284 
288 
     | 
    
         | 
| 
      
 289 
     | 
    
         
            +
                    def candidate_node?(node)
         
     | 
| 
      
 290 
     | 
    
         
            +
                      style == :assign_inside_condition && assignment_rhs_exist?(node)
         
     | 
| 
      
 291 
     | 
    
         
            +
                    end
         
     | 
| 
      
 292 
     | 
    
         
            +
             
     | 
| 
      
 293 
     | 
    
         
            +
                    def_node_matcher :candidate_condition?, '[{if case} !#allowed_ternary?]'
         
     | 
| 
      
 294 
     | 
    
         
            +
             
     | 
| 
       285 
295 
     | 
    
         
             
                    def allowed_ternary?(assignment)
         
     | 
| 
       286 
296 
     | 
    
         
             
                      assignment.if_type? && assignment.ternary? && !include_ternary?
         
     | 
| 
       287 
297 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -356,7 +366,7 @@ module RuboCop 
     | 
|
| 
       356 
366 
     | 
    
         
             
                      return if allowed_single_line?(branches)
         
     | 
| 
       357 
367 
     | 
    
         
             
                      return if correction_exceeds_line_limit?(node, branches)
         
     | 
| 
       358 
368 
     | 
    
         | 
| 
       359 
     | 
    
         
            -
                      add_offense(node 
     | 
| 
      
 369 
     | 
    
         
            +
                      add_offense(node)
         
     | 
| 
       360 
370 
     | 
    
         
             
                    end
         
     | 
| 
       361 
371 
     | 
    
         | 
| 
       362 
372 
     | 
    
         
             
                    def allowed_statements?(branches)
         
     | 
| 
         @@ -380,36 +390,20 @@ module RuboCop 
     | 
|
| 
       380 
390 
     | 
    
         | 
| 
       381 
391 
     | 
    
         
             
                      assignment = lhs(tail(branches[0]))
         
     | 
| 
       382 
392 
     | 
    
         | 
| 
       383 
     | 
    
         
            -
                       
     | 
| 
       384 
     | 
    
         
            -
                        longest_line_exceeds_line_limit?(node, assignment)
         
     | 
| 
       385 
     | 
    
         
            -
                    end
         
     | 
| 
       386 
     | 
    
         
            -
             
     | 
| 
       387 
     | 
    
         
            -
                    def longest_rhs_exceeds_line_limit?(branches, assignment)
         
     | 
| 
       388 
     | 
    
         
            -
                      longest_rhs_full_length(branches, assignment) > max_line_length
         
     | 
| 
      
 393 
     | 
    
         
            +
                      longest_line_exceeds_line_limit?(node, assignment)
         
     | 
| 
       389 
394 
     | 
    
         
             
                    end
         
     | 
| 
       390 
395 
     | 
    
         | 
| 
       391 
396 
     | 
    
         
             
                    def longest_line_exceeds_line_limit?(node, assignment)
         
     | 
| 
       392 
397 
     | 
    
         
             
                      longest_line(node, assignment).length > max_line_length
         
     | 
| 
       393 
398 
     | 
    
         
             
                    end
         
     | 
| 
       394 
399 
     | 
    
         | 
| 
       395 
     | 
    
         
            -
                    def longest_rhs_full_length(branches, assignment)
         
     | 
| 
       396 
     | 
    
         
            -
                      longest_rhs(branches) + indentation_width + assignment.length
         
     | 
| 
       397 
     | 
    
         
            -
                    end
         
     | 
| 
       398 
     | 
    
         
            -
             
     | 
| 
       399 
400 
     | 
    
         
             
                    def longest_line(node, assignment)
         
     | 
| 
       400 
     | 
    
         
            -
                      assignment_regex =  
     | 
| 
      
 401 
     | 
    
         
            +
                      assignment_regex = /\s*#{Regexp.escape(assignment).gsub('\ ', '\s*')}/
         
     | 
| 
       401 
402 
     | 
    
         
             
                      lines = node.source.lines.map do |line|
         
     | 
| 
       402 
403 
     | 
    
         
             
                        line.chomp.sub(assignment_regex, '')
         
     | 
| 
       403 
404 
     | 
    
         
             
                      end
         
     | 
| 
       404 
405 
     | 
    
         
             
                      longest_line = lines.max_by(&:length)
         
     | 
| 
       405 
     | 
    
         
            -
                       
     | 
| 
       406 
     | 
    
         
            -
                    end
         
     | 
| 
       407 
     | 
    
         
            -
             
     | 
| 
       408 
     | 
    
         
            -
                    def longest_rhs(branches)
         
     | 
| 
       409 
     | 
    
         
            -
                      line_lengths = branches.flat_map do |branch|
         
     | 
| 
       410 
     | 
    
         
            -
                        branch.children.last.source.split("\n").map(&:length)
         
     | 
| 
       411 
     | 
    
         
            -
                      end
         
     | 
| 
       412 
     | 
    
         
            -
                      line_lengths.max
         
     | 
| 
      
 406 
     | 
    
         
            +
                      assignment + longest_line
         
     | 
| 
       413 
407 
     | 
    
         
             
                    end
         
     | 
| 
       414 
408 
     | 
    
         | 
| 
       415 
409 
     | 
    
         
             
                    def line_length_cop_enabled?
         
     | 
| 
         @@ -475,7 +469,15 @@ module RuboCop 
     | 
|
| 
       475 
469 
     | 
    
         | 
| 
       476 
470 
     | 
    
         
             
                    def replace_branch_assignment(corrector, branch)
         
     | 
| 
       477 
471 
     | 
    
         
             
                      _variable, *_operator, assignment = *branch
         
     | 
| 
       478 
     | 
    
         
            -
                       
     | 
| 
      
 472 
     | 
    
         
            +
                      source = assignment.source
         
     | 
| 
      
 473 
     | 
    
         
            +
             
     | 
| 
      
 474 
     | 
    
         
            +
                      replacement = if assignment.array_type? && !assignment.bracketed?
         
     | 
| 
      
 475 
     | 
    
         
            +
                                      "[#{source}]"
         
     | 
| 
      
 476 
     | 
    
         
            +
                                    else
         
     | 
| 
      
 477 
     | 
    
         
            +
                                      source
         
     | 
| 
      
 478 
     | 
    
         
            +
                                    end
         
     | 
| 
      
 479 
     | 
    
         
            +
             
     | 
| 
      
 480 
     | 
    
         
            +
                      corrector.replace(branch.source_range, replacement)
         
     | 
| 
       479 
481 
     | 
    
         
             
                    end
         
     | 
| 
       480 
482 
     | 
    
         | 
| 
       481 
483 
     | 
    
         
             
                    def correct_branches(corrector, branches)
         
     | 
| 
         @@ -16,14 +16,21 @@ module RuboCop 
     | 
|
| 
       16 
16 
     | 
    
         
             
                  # an offense is reported.
         
     | 
| 
       17 
17 
     | 
    
         
             
                  #
         
     | 
| 
       18 
18 
     | 
    
         
             
                  class Copyright < Cop
         
     | 
| 
      
 19 
     | 
    
         
            +
                    MSG = 'Include a copyright notice matching /%s/ before ' \
         
     | 
| 
      
 20 
     | 
    
         
            +
                          'any code.'.freeze
         
     | 
| 
       19 
21 
     | 
    
         
             
                    AUTOCORRECT_EMPTY_WARNING = 'An AutocorrectNotice must be defined in' \
         
     | 
| 
       20 
22 
     | 
    
         
             
                                                'your RuboCop config'.freeze
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                    def  
     | 
| 
       23 
     | 
    
         
            -
                       
     | 
| 
       24 
     | 
    
         
            -
                       
     | 
| 
      
 24 
     | 
    
         
            +
                    def investigate(processed_source)
         
     | 
| 
      
 25 
     | 
    
         
            +
                      return if notice.empty?
         
     | 
| 
      
 26 
     | 
    
         
            +
                      return if notice_found?(processed_source)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      range = source_range(processed_source.buffer, 1, 0)
         
     | 
| 
      
 28 
     | 
    
         
            +
                      add_offense(insert_notice_before(processed_source),
         
     | 
| 
      
 29 
     | 
    
         
            +
                                  range, MSG % notice)
         
     | 
| 
       25 
30 
     | 
    
         
             
                    end
         
     | 
| 
       26 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
                    private
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       27 
34 
     | 
    
         
             
                    def notice
         
     | 
| 
       28 
35 
     | 
    
         
             
                      cop_config['Notice']
         
     | 
| 
       29 
36 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -32,13 +39,6 @@ module RuboCop 
     | 
|
| 
       32 
39 
     | 
    
         
             
                      cop_config['AutocorrectNotice']
         
     | 
| 
       33 
40 
     | 
    
         
             
                    end
         
     | 
| 
       34 
41 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                    def investigate(processed_source)
         
     | 
| 
       36 
     | 
    
         
            -
                      return if notice.empty?
         
     | 
| 
       37 
     | 
    
         
            -
                      return if notice_found?(processed_source)
         
     | 
| 
       38 
     | 
    
         
            -
                      range = source_range(processed_source.buffer, 1, 0)
         
     | 
| 
       39 
     | 
    
         
            -
                      add_offense(insert_notice_before(processed_source), range, message)
         
     | 
| 
       40 
     | 
    
         
            -
                    end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
42 
     | 
    
         
             
                    def insert_notice_before(processed_source)
         
     | 
| 
       43 
43 
     | 
    
         
             
                      token_index = 0
         
     | 
| 
       44 
44 
     | 
    
         
             
                      token_index += 1 if shebang_token?(processed_source, token_index)
         
     | 
| 
         @@ -7,17 +7,18 @@ module RuboCop 
     | 
|
| 
       7 
7 
     | 
    
         
             
                  # that does not take any arguments. Both instance and
         
     | 
| 
       8 
8 
     | 
    
         
             
                  # class/singleton methods are checked.
         
     | 
| 
       9 
9 
     | 
    
         
             
                  class DefWithParentheses < Cop
         
     | 
| 
       10 
     | 
    
         
            -
                    include OnMethodDef
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
10 
     | 
    
         
             
                    MSG = "Omit the parentheses in defs when the method doesn't accept " \
         
     | 
| 
       13 
11 
     | 
    
         
             
                          'any arguments.'.freeze
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                    def  
     | 
| 
      
 13 
     | 
    
         
            +
                    def on_def(node)
         
     | 
| 
       16 
14 
     | 
    
         
             
                      return if node.single_line?
         
     | 
| 
       17 
     | 
    
         
            -
                      return unless  
     | 
| 
      
 15 
     | 
    
         
            +
                      return unless !node.arguments? && node.arguments.loc.begin
         
     | 
| 
       18 
16 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                      add_offense( 
     | 
| 
      
 17 
     | 
    
         
            +
                      add_offense(node.arguments, :begin)
         
     | 
| 
       20 
18 
     | 
    
         
             
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                    alias on_defs on_def
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    private
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
                    def autocorrect(node)
         
     | 
| 
       23 
24 
     | 
    
         
             
                      lambda do |corrector|
         
     | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module RuboCop
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Cop
         
     | 
| 
      
 5 
     | 
    
         
            +
                module Style
         
     | 
| 
      
 6 
     | 
    
         
            +
                  # This cop checks for places where the `#__dir__` method can replace more
         
     | 
| 
      
 7 
     | 
    
         
            +
                  # complex constructs to retrieve a canonicalized absolute path to the
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # current file.
         
     | 
| 
      
 9 
     | 
    
         
            +
                  #
         
     | 
| 
      
 10 
     | 
    
         
            +
                  # @example
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #   # bad
         
     | 
| 
      
 12 
     | 
    
         
            +
                  #   path = File.expand_path(File.dirname(__FILE__))
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #
         
     | 
| 
      
 14 
     | 
    
         
            +
                  #   # bad
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #   path = File.dirname(File.realpath(__FILE__))
         
     | 
| 
      
 16 
     | 
    
         
            +
                  #
         
     | 
| 
      
 17 
     | 
    
         
            +
                  #   # good
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #   path = __dir__
         
     | 
| 
      
 19 
     | 
    
         
            +
                  class Dir < Cop
         
     | 
| 
      
 20 
     | 
    
         
            +
                    extend TargetRubyVersion
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    MSG = 'Use `__dir__` to get an absolute path to the current ' \
         
     | 
| 
      
 23 
     | 
    
         
            +
                          "file's directory.".freeze
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    def_node_matcher :dir_replacement?, <<-PATTERN
         
     | 
| 
      
 26 
     | 
    
         
            +
                      {(send (const nil :File) :expand_path (send (const nil :File) :dirname  #file_keyword?))
         
     | 
| 
      
 27 
     | 
    
         
            +
                       (send (const nil :File) :dirname     (send (const nil :File) :realpath #file_keyword?))}
         
     | 
| 
      
 28 
     | 
    
         
            +
                    PATTERN
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    minimum_target_ruby_version 2.0
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                    def on_send(node)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      dir_replacement?(node) do
         
     | 
| 
      
 34 
     | 
    
         
            +
                        add_offense(node)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                    private
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                    def autocorrect(node)
         
     | 
| 
      
 41 
     | 
    
         
            +
                      lambda do |corrector|
         
     | 
| 
      
 42 
     | 
    
         
            +
                        corrector.replace(node.source_range, '__dir__')
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    def file_keyword?(node)
         
     | 
| 
      
 47 
     | 
    
         
            +
                      node.str_type? && node.source_range.is?('__FILE__')
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     |