rubocop 1.11.0 → 1.12.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 +2 -2
 - data/config/default.yml +16 -1
 - data/lib/rubocop.rb +1 -0
 - data/lib/rubocop/cli/command/suggest_extensions.rb +3 -2
 - data/lib/rubocop/comment_config.rb +43 -94
 - data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
 - data/lib/rubocop/cop/layout/access_modifier_indentation.rb +11 -8
 - data/lib/rubocop/cop/layout/argument_alignment.rb +6 -5
 - data/lib/rubocop/cop/layout/array_alignment.rb +7 -6
 - data/lib/rubocop/cop/layout/assignment_indentation.rb +6 -3
 - data/lib/rubocop/cop/layout/block_end_newline.rb +4 -8
 - data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +14 -15
 - data/lib/rubocop/cop/layout/comment_indentation.rb +16 -16
 - data/lib/rubocop/cop/layout/else_alignment.rb +9 -6
 - data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -5
 - data/lib/rubocop/cop/layout/first_array_element_indentation.rb +9 -6
 - data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +22 -15
 - data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -5
 - data/lib/rubocop/cop/layout/indentation_consistency.rb +9 -6
 - data/lib/rubocop/cop/layout/indentation_style.rb +27 -30
 - data/lib/rubocop/cop/layout/indentation_width.rb +19 -9
 - data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -5
 - data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -5
 - data/lib/rubocop/cop/layout/parameter_alignment.rb +6 -5
 - data/lib/rubocop/cop/lint/number_conversion.rb +7 -0
 - data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -2
 - data/lib/rubocop/cop/lint/suppressed_exception.rb +44 -1
 - data/lib/rubocop/cop/lint/symbol_conversion.rb +89 -2
 - data/lib/rubocop/cop/mixin/alignment.rb +10 -3
 - data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
 - data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
 - data/lib/rubocop/cop/mixin/line_length_help.rb +11 -6
 - data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
 - data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
 - data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
 - data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -6
 - data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +4 -0
 - data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -0
 - data/lib/rubocop/cop/registry.rb +9 -0
 - data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
 - data/lib/rubocop/cop/style/bisected_attr_accessor.rb +59 -71
 - data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +62 -0
 - data/lib/rubocop/cop/style/case_like_if.rb +15 -4
 - data/lib/rubocop/cop/style/class_equality_comparison.rb +2 -0
 - data/lib/rubocop/cop/style/command_literal.rb +1 -1
 - data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
 - data/lib/rubocop/cop/style/documentation.rb +25 -3
 - data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
 - data/lib/rubocop/cop/style/hash_syntax.rb +16 -15
 - data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +40 -0
 - data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +20 -2
 - data/lib/rubocop/cop/style/negated_if_else_condition.rb +15 -2
 - data/lib/rubocop/cop/style/redundant_begin.rb +26 -3
 - data/lib/rubocop/cop/style/redundant_return.rb +4 -0
 - data/lib/rubocop/cop/style/redundant_self.rb +7 -3
 - data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
 - data/lib/rubocop/cop/style/rescue_modifier.rb +17 -14
 - data/lib/rubocop/cop/style/sole_nested_conditional.rb +16 -0
 - data/lib/rubocop/cop/style/string_chars.rb +38 -0
 - data/lib/rubocop/cop/style/struct_inheritance.rb +2 -0
 - data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +5 -1
 - data/lib/rubocop/cop/style/unless_logical_operators.rb +8 -2
 - data/lib/rubocop/directive_comment.rb +64 -9
 - data/lib/rubocop/ext/regexp_parser.rb +3 -6
 - data/lib/rubocop/magic_comment.rb +1 -1
 - data/lib/rubocop/target_finder.rb +1 -0
 - data/lib/rubocop/version.rb +1 -1
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c4f019dc65a23e4fdd32592747afcbee2cf60dff91484b26714f587b9f70a178
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 85f0e9d193e2165646764047f5422cb7942c87a147c96ff8e4a05b186eaea3c5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5064fb48121769e10df9fe4dd7295151f15c2a3ae5f67fbb2869302a7ad268dfd3ed20e7a3242bf59ef68c1c6cf4e92452fedab08971702d29dba06516250de8
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3b01830b9394f8336bdc415d90e2805f2817eb9fa9686a11392ef8009c4a58dd4b04e40c4a8005e90204774e85b38a6885c315581d55c56bf4a847c71c570447
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -51,10 +51,10 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi 
     | 
|
| 
       51 
51 
     | 
    
         
             
            in your `Gemfile`:
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
            ```rb
         
     | 
| 
       54 
     | 
    
         
            -
            gem 'rubocop', '~> 1. 
     | 
| 
      
 54 
     | 
    
         
            +
            gem 'rubocop', '~> 1.12', require: false
         
     | 
| 
       55 
55 
     | 
    
         
             
            ```
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
            See [versioning](https://docs.rubocop.org/rubocop/ 
     | 
| 
      
 57 
     | 
    
         
            +
            See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
59 
     | 
    
         
             
            ## Quickstart
         
     | 
| 
       60 
60 
     | 
    
         | 
    
        data/config/default.yml
    CHANGED
    
    | 
         @@ -2055,13 +2055,18 @@ Lint/SuppressedException: 
     | 
|
| 
       2055 
2055 
     | 
    
         
             
              StyleGuide: '#dont-hide-exceptions'
         
     | 
| 
       2056 
2056 
     | 
    
         
             
              Enabled: true
         
     | 
| 
       2057 
2057 
     | 
    
         
             
              AllowComments: true
         
     | 
| 
      
 2058 
     | 
    
         
            +
              AllowNil: true
         
     | 
| 
       2058 
2059 
     | 
    
         
             
              VersionAdded: '0.9'
         
     | 
| 
       2059 
     | 
    
         
            -
              VersionChanged: ' 
     | 
| 
      
 2060 
     | 
    
         
            +
              VersionChanged: '1.12'
         
     | 
| 
       2060 
2061 
     | 
    
         | 
| 
       2061 
2062 
     | 
    
         
             
            Lint/SymbolConversion:
         
     | 
| 
       2062 
2063 
     | 
    
         
             
              Description: 'Checks for unnecessary symbol conversions.'
         
     | 
| 
       2063 
2064 
     | 
    
         
             
              Enabled: pending
         
     | 
| 
       2064 
2065 
     | 
    
         
             
              VersionAdded: '1.9'
         
     | 
| 
      
 2066 
     | 
    
         
            +
              EnforcedStyle: strict
         
     | 
| 
      
 2067 
     | 
    
         
            +
              SupportedStyles:
         
     | 
| 
      
 2068 
     | 
    
         
            +
                - strict
         
     | 
| 
      
 2069 
     | 
    
         
            +
                - consistent
         
     | 
| 
       2065 
2070 
     | 
    
         | 
| 
       2066 
2071 
     | 
    
         
             
            Lint/Syntax:
         
     | 
| 
       2067 
2072 
     | 
    
         
             
              Description: 'Checks for syntax errors.'
         
     | 
| 
         @@ -2489,6 +2494,7 @@ Naming/MemoizedInstanceVariableName: 
     | 
|
| 
       2489 
2494 
     | 
    
         
             
                - disallowed
         
     | 
| 
       2490 
2495 
     | 
    
         
             
                - required
         
     | 
| 
       2491 
2496 
     | 
    
         
             
                - optional
         
     | 
| 
      
 2497 
     | 
    
         
            +
              Safe: false
         
     | 
| 
       2492 
2498 
     | 
    
         | 
| 
       2493 
2499 
     | 
    
         
             
            Naming/MethodName:
         
     | 
| 
       2494 
2500 
     | 
    
         
             
              Description: 'Use the configured style when naming methods.'
         
     | 
| 
         @@ -3174,6 +3180,7 @@ Style/Documentation: 
     | 
|
| 
       3174 
3180 
     | 
    
         
             
              Description: 'Document classes and non-namespace modules.'
         
     | 
| 
       3175 
3181 
     | 
    
         
             
              Enabled: true
         
     | 
| 
       3176 
3182 
     | 
    
         
             
              VersionAdded: '0.9'
         
     | 
| 
      
 3183 
     | 
    
         
            +
              AllowedConstants: []
         
     | 
| 
       3177 
3184 
     | 
    
         
             
              Exclude:
         
     | 
| 
       3178 
3185 
     | 
    
         
             
                - 'spec/**/*'
         
     | 
| 
       3179 
3186 
     | 
    
         
             
                - 'test/**/*'
         
     | 
| 
         @@ -3672,6 +3679,7 @@ Style/MethodCallWithArgsParentheses: 
     | 
|
| 
       3672 
3679 
     | 
    
         
             
              AllowParenthesesInMultilineCall: false
         
     | 
| 
       3673 
3680 
     | 
    
         
             
              AllowParenthesesInChaining: false
         
     | 
| 
       3674 
3681 
     | 
    
         
             
              AllowParenthesesInCamelCaseMethod: false
         
     | 
| 
      
 3682 
     | 
    
         
            +
              AllowParenthesesInStringInterpolation: false
         
     | 
| 
       3675 
3683 
     | 
    
         
             
              EnforcedStyle: require_parentheses
         
     | 
| 
       3676 
3684 
     | 
    
         
             
              SupportedStyles:
         
     | 
| 
       3677 
3685 
     | 
    
         
             
                - require_parentheses
         
     | 
| 
         @@ -4491,6 +4499,13 @@ Style/StderrPuts: 
     | 
|
| 
       4491 
4499 
     | 
    
         
             
              Enabled: true
         
     | 
| 
       4492 
4500 
     | 
    
         
             
              VersionAdded: '0.51'
         
     | 
| 
       4493 
4501 
     | 
    
         | 
| 
      
 4502 
     | 
    
         
            +
            Style/StringChars:
         
     | 
| 
      
 4503 
     | 
    
         
            +
              Description: 'Checks for uses of `String#split` with empty string or regexp literal argument.'
         
     | 
| 
      
 4504 
     | 
    
         
            +
              StyleGuide: '#string-chars'
         
     | 
| 
      
 4505 
     | 
    
         
            +
              Enabled: pending
         
     | 
| 
      
 4506 
     | 
    
         
            +
              Safe: false
         
     | 
| 
      
 4507 
     | 
    
         
            +
              VersionAdded: '1.12'
         
     | 
| 
      
 4508 
     | 
    
         
            +
             
     | 
| 
       4494 
4509 
     | 
    
         
             
            Style/StringConcatenation:
         
     | 
| 
       4495 
4510 
     | 
    
         
             
              Description: 'Checks for places where string concatenation can be replaced with string interpolation.'
         
     | 
| 
       4496 
4511 
     | 
    
         
             
              StyleGuide: '#string-interpolation'
         
     | 
    
        data/lib/rubocop.rb
    CHANGED
    
    | 
         @@ -582,6 +582,7 @@ require_relative 'rubocop/cop/style/slicing_with_range' 
     | 
|
| 
       582 
582 
     | 
    
         
             
            require_relative 'rubocop/cop/style/special_global_vars'
         
     | 
| 
       583 
583 
     | 
    
         
             
            require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
         
     | 
| 
       584 
584 
     | 
    
         
             
            require_relative 'rubocop/cop/style/stderr_puts'
         
     | 
| 
      
 585 
     | 
    
         
            +
            require_relative 'rubocop/cop/style/string_chars'
         
     | 
| 
       585 
586 
     | 
    
         
             
            require_relative 'rubocop/cop/style/string_concatenation'
         
     | 
| 
       586 
587 
     | 
    
         
             
            require_relative 'rubocop/cop/style/string_hash_keys'
         
     | 
| 
       587 
588 
     | 
    
         
             
            require_relative 'rubocop/cop/style/string_literals'
         
     | 
| 
         @@ -22,7 +22,7 @@ module RuboCop 
     | 
|
| 
       22 
22 
     | 
    
         
             
                        'RuboCop extension libraries might be helpful:'
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                      extensions.sort.each do |extension|
         
     | 
| 
       25 
     | 
    
         
            -
                        puts "  * #{extension} ( 
     | 
| 
      
 25 
     | 
    
         
            +
                        puts "  * #{extension} (https://github.com/rubocop/#{extension})"
         
     | 
| 
       26 
26 
     | 
    
         
             
                      end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                      puts
         
     | 
| 
         @@ -43,7 +43,8 @@ module RuboCop 
     | 
|
| 
       43 
43 
     | 
    
         
             
                      # 2. When given RuboCop options that it doesn't make sense for
         
     | 
| 
       44 
44 
     | 
    
         
             
                      # 3. For all formatters except specified in `INCLUDED_FORMATTERS'`
         
     | 
| 
       45 
45 
     | 
    
         
             
                      ENV['CI'] ||
         
     | 
| 
       46 
     | 
    
         
            -
                        @options[:only] || @options[:debug] || @options[:list_target_files] || 
     | 
| 
      
 46 
     | 
    
         
            +
                        @options[:only] || @options[:debug] || @options[:list_target_files] ||
         
     | 
| 
      
 47 
     | 
    
         
            +
                        @options[:out] || @options[:stdin] ||
         
     | 
| 
       47 
48 
     | 
    
         
             
                        !INCLUDED_FORMATTERS.include?(current_formatter)
         
     | 
| 
       48 
49 
     | 
    
         
             
                    end
         
     | 
| 
       49 
50 
     | 
    
         | 
| 
         @@ -4,22 +4,6 @@ module RuboCop 
     | 
|
| 
       4 
4 
     | 
    
         
             
              # This class parses the special `rubocop:disable` comments in a source
         
     | 
| 
       5 
5 
     | 
    
         
             
              # and provides a way to check if each cop is enabled at arbitrary line.
         
     | 
| 
       6 
6 
     | 
    
         
             
              class CommentConfig
         
     | 
| 
       7 
     | 
    
         
            -
                # @api private
         
     | 
| 
       8 
     | 
    
         
            -
                REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                # @api private
         
     | 
| 
       11 
     | 
    
         
            -
                COP_NAME_PATTERN = '([A-Z]\w+/)*(?:[A-Z]\w+)'
         
     | 
| 
       12 
     | 
    
         
            -
                # @api private
         
     | 
| 
       13 
     | 
    
         
            -
                COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
         
     | 
| 
       14 
     | 
    
         
            -
                # @api private
         
     | 
| 
       15 
     | 
    
         
            -
                COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                # @api private
         
     | 
| 
       18 
     | 
    
         
            -
                COMMENT_DIRECTIVE_REGEXP = Regexp.new(
         
     | 
| 
       19 
     | 
    
         
            -
                  "# rubocop : ((?:disable|enable|todo))\\b #{COPS_PATTERN}"
         
     | 
| 
       20 
     | 
    
         
            -
                    .gsub(' ', '\s*')
         
     | 
| 
       21 
     | 
    
         
            -
                )
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
7 
     | 
    
         
             
                CopAnalysis = Struct.new(:line_ranges, :start_line_number)
         
     | 
| 
       24 
8 
     | 
    
         | 
| 
       25 
9 
     | 
    
         
             
                attr_reader :processed_source
         
     | 
| 
         @@ -56,13 +40,13 @@ module RuboCop 
     | 
|
| 
       56 
40 
     | 
    
         
             
                private
         
     | 
| 
       57 
41 
     | 
    
         | 
| 
       58 
42 
     | 
    
         
             
                def extra_enabled_comments_with_names(extras:, names:)
         
     | 
| 
       59 
     | 
    
         
            -
                  each_directive do | 
     | 
| 
       60 
     | 
    
         
            -
                    next unless comment_only_line?( 
     | 
| 
      
 43 
     | 
    
         
            +
                  each_directive do |directive|
         
     | 
| 
      
 44 
     | 
    
         
            +
                    next unless comment_only_line?(directive.line_number)
         
     | 
| 
       61 
45 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                    if  
     | 
| 
       63 
     | 
    
         
            -
                      handle_enable_all(names, extras 
     | 
| 
      
 46 
     | 
    
         
            +
                    if directive.enabled_all?
         
     | 
| 
      
 47 
     | 
    
         
            +
                      handle_enable_all(directive, names, extras)
         
     | 
| 
       64 
48 
     | 
    
         
             
                    else
         
     | 
| 
       65 
     | 
    
         
            -
                      handle_switch( 
     | 
| 
      
 49 
     | 
    
         
            +
                      handle_switch(directive, names, extras)
         
     | 
| 
       66 
50 
     | 
    
         
             
                    end
         
     | 
| 
       67 
51 
     | 
    
         
             
                  end
         
     | 
| 
       68 
52 
     | 
    
         | 
| 
         @@ -72,9 +56,11 @@ module RuboCop 
     | 
|
| 
       72 
56 
     | 
    
         
             
                def analyze # rubocop:todo Metrics/AbcSize
         
     | 
| 
       73 
57 
     | 
    
         
             
                  analyses = Hash.new { |hash, key| hash[key] = CopAnalysis.new([], nil) }
         
     | 
| 
       74 
58 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
       76 
     | 
    
         
            -
                     
     | 
| 
       77 
     | 
    
         
            -
                       
     | 
| 
      
 59 
     | 
    
         
            +
                  each_directive do |directive|
         
     | 
| 
      
 60 
     | 
    
         
            +
                    directive.cop_names.each do |cop_name|
         
     | 
| 
      
 61 
     | 
    
         
            +
                      cop_name = qualified_cop_name(cop_name)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      analyses[cop_name] = analyze_cop(analyses[cop_name], directive)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
       78 
64 
     | 
    
         
             
                  end
         
     | 
| 
       79 
65 
     | 
    
         | 
| 
       80 
66 
     | 
    
         
             
                  analyses.each_with_object({}) do |element, hash|
         
     | 
| 
         @@ -83,37 +69,42 @@ module RuboCop 
     | 
|
| 
       83 
69 
     | 
    
         
             
                  end
         
     | 
| 
       84 
70 
     | 
    
         
             
                end
         
     | 
| 
       85 
71 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
                def analyze_cop(analysis,  
     | 
| 
       87 
     | 
    
         
            -
                   
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
                def analyze_cop(analysis, directive)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  # Disabling cops after comments like `#=SomeDslDirective` does not related to single line
         
     | 
| 
      
 74 
     | 
    
         
            +
                  if !comment_only_line?(directive.line_number) || directive.single_line?
         
     | 
| 
      
 75 
     | 
    
         
            +
                    analyze_single_line(analysis, directive)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  elsif directive.disabled?
         
     | 
| 
      
 77 
     | 
    
         
            +
                    analyze_disabled(analysis, directive)
         
     | 
| 
       91 
78 
     | 
    
         
             
                  else
         
     | 
| 
       92 
     | 
    
         
            -
                    analyze_rest(analysis,  
     | 
| 
      
 79 
     | 
    
         
            +
                    analyze_rest(analysis, directive)
         
     | 
| 
       93 
80 
     | 
    
         
             
                  end
         
     | 
| 
       94 
81 
     | 
    
         
             
                end
         
     | 
| 
       95 
82 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
                def analyze_single_line(analysis,  
     | 
| 
       97 
     | 
    
         
            -
                  return analysis unless disabled
         
     | 
| 
      
 83 
     | 
    
         
            +
                def analyze_single_line(analysis, directive)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  return analysis unless directive.disabled?
         
     | 
| 
       98 
85 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
                  line = directive.line_number
         
     | 
| 
      
 87 
     | 
    
         
            +
                  start_line = analysis.start_line_number
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  CopAnalysis.new(analysis.line_ranges + [(line..line)], start_line)
         
     | 
| 
       101 
90 
     | 
    
         
             
                end
         
     | 
| 
       102 
91 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
                def analyze_disabled(analysis,  
     | 
| 
       104 
     | 
    
         
            -
                   
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                   
     | 
| 
      
 92 
     | 
    
         
            +
                def analyze_disabled(analysis, directive)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  line = directive.line_number
         
     | 
| 
      
 94 
     | 
    
         
            +
                  start_line = analysis.start_line_number
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  # Cop already disabled on this line, so we end the current disabled
         
     | 
| 
      
 97 
     | 
    
         
            +
                  # range before we start a new range.
         
     | 
| 
      
 98 
     | 
    
         
            +
                  return CopAnalysis.new(analysis.line_ranges + [start_line..line], line) if start_line
         
     | 
| 
       109 
99 
     | 
    
         | 
| 
       110 
100 
     | 
    
         
             
                  CopAnalysis.new(analysis.line_ranges, line)
         
     | 
| 
       111 
101 
     | 
    
         
             
                end
         
     | 
| 
       112 
102 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
                def analyze_rest(analysis,  
     | 
| 
       114 
     | 
    
         
            -
                   
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
      
 103 
     | 
    
         
            +
                def analyze_rest(analysis, directive)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  line = directive.line_number
         
     | 
| 
      
 105 
     | 
    
         
            +
                  start_line = analysis.start_line_number
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  return CopAnalysis.new(analysis.line_ranges + [start_line..line], nil) if start_line
         
     | 
| 
       117 
108 
     | 
    
         | 
| 
       118 
109 
     | 
    
         
             
                  CopAnalysis.new(analysis.line_ranges, nil)
         
     | 
| 
       119 
110 
     | 
    
         
             
                end
         
     | 
| 
         @@ -124,54 +115,17 @@ module RuboCop 
     | 
|
| 
       124 
115 
     | 
    
         
             
                  analysis.line_ranges + [(analysis.start_line_number..Float::INFINITY)]
         
     | 
| 
       125 
116 
     | 
    
         
             
                end
         
     | 
| 
       126 
117 
     | 
    
         | 
| 
       127 
     | 
    
         
            -
                def each_mentioned_cop
         
     | 
| 
       128 
     | 
    
         
            -
                  each_directive do |comment, cop_names, disabled|
         
     | 
| 
       129 
     | 
    
         
            -
                    comment_line_number = comment.loc.expression.line
         
     | 
| 
       130 
     | 
    
         
            -
                    single_line = !comment_only_line?(comment_line_number) ||
         
     | 
| 
       131 
     | 
    
         
            -
                                  directive_on_comment_line?(comment)
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                    cop_names.each do |cop_name|
         
     | 
| 
       134 
     | 
    
         
            -
                      yield qualified_cop_name(cop_name), disabled, comment_line_number,
         
     | 
| 
       135 
     | 
    
         
            -
                            single_line
         
     | 
| 
       136 
     | 
    
         
            -
                    end
         
     | 
| 
       137 
     | 
    
         
            -
                  end
         
     | 
| 
       138 
     | 
    
         
            -
                end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
                def directive_on_comment_line?(comment)
         
     | 
| 
       141 
     | 
    
         
            -
                  comment.text[1..-1].match?(COMMENT_DIRECTIVE_REGEXP)
         
     | 
| 
       142 
     | 
    
         
            -
                end
         
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
118 
     | 
    
         
             
                def each_directive
         
     | 
| 
       145 
119 
     | 
    
         
             
                  processed_source.comments.each do |comment|
         
     | 
| 
       146 
     | 
    
         
            -
                    directive =  
     | 
| 
       147 
     | 
    
         
            -
                     
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
                    yield comment, *directive
         
     | 
| 
      
 120 
     | 
    
         
            +
                    directive = DirectiveComment.new(comment)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    yield directive if directive.cop_names
         
     | 
| 
       150 
122 
     | 
    
         
             
                  end
         
     | 
| 
       151 
123 
     | 
    
         
             
                end
         
     | 
| 
       152 
124 
     | 
    
         | 
| 
       153 
     | 
    
         
            -
                def directive_parts(comment)
         
     | 
| 
       154 
     | 
    
         
            -
                  match = comment.text.match(COMMENT_DIRECTIVE_REGEXP)
         
     | 
| 
       155 
     | 
    
         
            -
                  return unless match
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
                  switch, cops_string = match.captures
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
                  cop_names =
         
     | 
| 
       160 
     | 
    
         
            -
                    cops_string == 'all' ? all_cop_names : cops_string.split(/,\s*/)
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
                  disabled = %w[disable todo].include?(switch)
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
                  [cop_names, disabled]
         
     | 
| 
       165 
     | 
    
         
            -
                end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
125 
     | 
    
         
             
                def qualified_cop_name(cop_name)
         
     | 
| 
       168 
126 
     | 
    
         
             
                  Cop::Registry.qualified_cop_name(cop_name.strip, processed_source.file_path)
         
     | 
| 
       169 
127 
     | 
    
         
             
                end
         
     | 
| 
       170 
128 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                def all_cop_names
         
     | 
| 
       172 
     | 
    
         
            -
                  @all_cop_names ||= Cop::Registry.global.names - [REDUNDANT_DISABLE]
         
     | 
| 
       173 
     | 
    
         
            -
                end
         
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
129 
     | 
    
         
             
                def non_comment_token_line_numbers
         
     | 
| 
       176 
130 
     | 
    
         
             
                  @non_comment_token_line_numbers ||= begin
         
     | 
| 
       177 
131 
     | 
    
         
             
                    non_comment_tokens = processed_source.tokens.reject(&:comment?)
         
     | 
| 
         @@ -179,12 +133,7 @@ module RuboCop 
     | 
|
| 
       179 
133 
     | 
    
         
             
                  end
         
     | 
| 
       180 
134 
     | 
    
         
             
                end
         
     | 
| 
       181 
135 
     | 
    
         | 
| 
       182 
     | 
    
         
            -
                def  
     | 
| 
       183 
     | 
    
         
            -
                  _, cops = comment.text.match(COMMENT_DIRECTIVE_REGEXP).captures
         
     | 
| 
       184 
     | 
    
         
            -
                  cops == 'all'
         
     | 
| 
       185 
     | 
    
         
            -
                end
         
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
                def handle_enable_all(names, extras, comment)
         
     | 
| 
      
 136 
     | 
    
         
            +
                def handle_enable_all(directive, names, extras)
         
     | 
| 
       188 
137 
     | 
    
         
             
                  enabled_cops = 0
         
     | 
| 
       189 
138 
     | 
    
         
             
                  names.each do |name, counter|
         
     | 
| 
       190 
139 
     | 
    
         
             
                    next unless counter.positive?
         
     | 
| 
         @@ -193,19 +142,19 @@ module RuboCop 
     | 
|
| 
       193 
142 
     | 
    
         
             
                    enabled_cops += 1
         
     | 
| 
       194 
143 
     | 
    
         
             
                  end
         
     | 
| 
       195 
144 
     | 
    
         | 
| 
       196 
     | 
    
         
            -
                  extras[comment] << 'all' if enabled_cops.zero?
         
     | 
| 
      
 145 
     | 
    
         
            +
                  extras[directive.comment] << 'all' if enabled_cops.zero?
         
     | 
| 
       197 
146 
     | 
    
         
             
                end
         
     | 
| 
       198 
147 
     | 
    
         | 
| 
       199 
148 
     | 
    
         
             
                # Collect cops that have been disabled or enabled by name in a directive comment
         
     | 
| 
       200 
149 
     | 
    
         
             
                # so that `Lint/RedundantCopEnableDirective` can register offenses correctly.
         
     | 
| 
       201 
     | 
    
         
            -
                def handle_switch( 
     | 
| 
       202 
     | 
    
         
            -
                  cop_names.each do |name|
         
     | 
| 
       203 
     | 
    
         
            -
                    if disabled
         
     | 
| 
      
 150 
     | 
    
         
            +
                def handle_switch(directive, names, extras)
         
     | 
| 
      
 151 
     | 
    
         
            +
                  directive.cop_names.each do |name|
         
     | 
| 
      
 152 
     | 
    
         
            +
                    if directive.disabled?
         
     | 
| 
       204 
153 
     | 
    
         
             
                      names[name] += 1
         
     | 
| 
       205 
154 
     | 
    
         
             
                    elsif (names[name]).positive?
         
     | 
| 
       206 
155 
     | 
    
         
             
                      names[name] -= 1
         
     | 
| 
       207 
156 
     | 
    
         
             
                    else
         
     | 
| 
       208 
     | 
    
         
            -
                      extras[comment] << name
         
     | 
| 
      
 157 
     | 
    
         
            +
                      extras[directive.comment] << name
         
     | 
| 
       209 
158 
     | 
    
         
             
                    end
         
     | 
| 
       210 
159 
     | 
    
         
             
                  end
         
     | 
| 
       211 
160 
     | 
    
         
             
                end
         
     | 
| 
         @@ -12,7 +12,7 @@ module RuboCop 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  class << self
         
     | 
| 
       13 
13 
     | 
    
         
             
                    attr_reader :processed_source
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                    def correct(processed_source, node, column_delta)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    def correct(corrector, processed_source, node, column_delta)
         
     | 
| 
       16 
16 
     | 
    
         
             
                      return unless node
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                      @processed_source = processed_source
         
     | 
| 
         @@ -21,11 +21,8 @@ module RuboCop 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                      taboo_ranges = inside_string_ranges(node)
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                       
     | 
| 
       25 
     | 
    
         
            -
                         
     | 
| 
       26 
     | 
    
         
            -
                          autocorrect_line(corrector, line_begin_pos, expr, column_delta,
         
     | 
| 
       27 
     | 
    
         
            -
                                           taboo_ranges)
         
     | 
| 
       28 
     | 
    
         
            -
                        end
         
     | 
| 
      
 24 
     | 
    
         
            +
                      each_line(expr) do |line_begin_pos|
         
     | 
| 
      
 25 
     | 
    
         
            +
                        autocorrect_line(corrector, line_begin_pos, expr, column_delta, taboo_ranges)
         
     | 
| 
       29 
26 
     | 
    
         
             
                      end
         
     | 
| 
       30 
27 
     | 
    
         
             
                    end
         
     | 
| 
       31 
28 
     | 
    
         | 
| 
         @@ -32,10 +32,11 @@ module RuboCop 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  #   private
         
     | 
| 
       33 
33 
     | 
    
         
             
                  #     def smooth; end
         
     | 
| 
       34 
34 
     | 
    
         
             
                  #   end
         
     | 
| 
       35 
     | 
    
         
            -
                  class AccessModifierIndentation <  
     | 
| 
      
 35 
     | 
    
         
            +
                  class AccessModifierIndentation < Base
         
     | 
| 
       36 
36 
     | 
    
         
             
                    include Alignment
         
     | 
| 
       37 
37 
     | 
    
         
             
                    include ConfigurableEnforcedStyle
         
     | 
| 
       38 
38 
     | 
    
         
             
                    include RangeHelp
         
     | 
| 
      
 39 
     | 
    
         
            +
                    extend AutoCorrector
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
       40 
41 
     | 
    
         
             
                    MSG = '%<style>s access modifiers like `%<node>s`.'
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
         @@ -48,12 +49,12 @@ module RuboCop 
     | 
|
| 
       48 
49 
     | 
    
         
             
                    alias on_module on_class
         
     | 
| 
       49 
50 
     | 
    
         
             
                    alias on_block  on_class
         
     | 
| 
       50 
51 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                    def autocorrect(node)
         
     | 
| 
       52 
     | 
    
         
            -
                      AlignmentCorrector.correct(processed_source, node, @column_delta)
         
     | 
| 
       53 
     | 
    
         
            -
                    end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
52 
     | 
    
         
             
                    private
         
     | 
| 
       56 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
                    def autocorrect(corrector, node)
         
     | 
| 
      
 55 
     | 
    
         
            +
                      AlignmentCorrector.correct(corrector, processed_source, node, @column_delta)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       57 
58 
     | 
    
         
             
                    def check_body(body, node)
         
     | 
| 
       58 
59 
     | 
    
         
             
                      modifiers = body.each_child_node(:send)
         
     | 
| 
       59 
60 
     | 
    
         
             
                                      .select(&:bare_access_modifier?)
         
     | 
| 
         @@ -69,18 +70,20 @@ module RuboCop 
     | 
|
| 
       69 
70 
     | 
    
         
             
                      if @column_delta.zero?
         
     | 
| 
       70 
71 
     | 
    
         
             
                        correct_style_detected
         
     | 
| 
       71 
72 
     | 
    
         
             
                      else
         
     | 
| 
       72 
     | 
    
         
            -
                        add_offense(send_node) do
         
     | 
| 
      
 73 
     | 
    
         
            +
                        add_offense(send_node) do |corrector|
         
     | 
| 
       73 
74 
     | 
    
         
             
                          if offset == unexpected_indent_offset
         
     | 
| 
       74 
75 
     | 
    
         
             
                            opposite_style_detected
         
     | 
| 
       75 
76 
     | 
    
         
             
                          else
         
     | 
| 
       76 
77 
     | 
    
         
             
                            unrecognized_style_detected
         
     | 
| 
       77 
78 
     | 
    
         
             
                          end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                          autocorrect(corrector, send_node)
         
     | 
| 
       78 
81 
     | 
    
         
             
                        end
         
     | 
| 
       79 
82 
     | 
    
         
             
                      end
         
     | 
| 
       80 
83 
     | 
    
         
             
                    end
         
     | 
| 
       81 
84 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
                    def message( 
     | 
| 
       83 
     | 
    
         
            -
                      format(MSG, style: style.capitalize, node:  
     | 
| 
      
 85 
     | 
    
         
            +
                    def message(range)
         
     | 
| 
      
 86 
     | 
    
         
            +
                      format(MSG, style: style.capitalize, node: range.source)
         
     | 
| 
       84 
87 
     | 
    
         
             
                    end
         
     | 
| 
       85 
88 
     | 
    
         | 
| 
       86 
89 
     | 
    
         
             
                    def expected_indent_offset
         
     | 
| 
         @@ -37,8 +37,9 @@ module RuboCop 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  #
         
     | 
| 
       38 
38 
     | 
    
         
             
                  #   foo :bar,
         
     | 
| 
       39 
39 
     | 
    
         
             
                  #       :baz
         
     | 
| 
       40 
     | 
    
         
            -
                  class ArgumentAlignment <  
     | 
| 
      
 40 
     | 
    
         
            +
                  class ArgumentAlignment < Base
         
     | 
| 
       41 
41 
     | 
    
         
             
                    include Alignment
         
     | 
| 
      
 42 
     | 
    
         
            +
                    extend AutoCorrector
         
     | 
| 
       42 
43 
     | 
    
         | 
| 
       43 
44 
     | 
    
         
             
                    ALIGN_PARAMS_MSG = 'Align the arguments of a method call if ' \
         
     | 
| 
       44 
45 
     | 
    
         
             
                      'they span more than one line.'
         
     | 
| 
         @@ -54,12 +55,12 @@ module RuboCop 
     | 
|
| 
       54 
55 
     | 
    
         
             
                    end
         
     | 
| 
       55 
56 
     | 
    
         
             
                    alias on_csend on_send
         
     | 
| 
       56 
57 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                    def autocorrect(node)
         
     | 
| 
       58 
     | 
    
         
            -
                      AlignmentCorrector.correct(processed_source, node, column_delta)
         
     | 
| 
       59 
     | 
    
         
            -
                    end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
58 
     | 
    
         
             
                    private
         
     | 
| 
       62 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
                    def autocorrect(corrector, node)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       63 
64 
     | 
    
         
             
                    def message(_node)
         
     | 
| 
       64 
65 
     | 
    
         
             
                      fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
         
     | 
| 
       65 
66 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -33,8 +33,9 @@ module RuboCop 
     | 
|
| 
       33 
33 
     | 
    
         
             
                  #
         
     | 
| 
       34 
34 
     | 
    
         
             
                  #   array = [1, 2, 3,
         
     | 
| 
       35 
35 
     | 
    
         
             
                  #            4, 5, 6]
         
     | 
| 
       36 
     | 
    
         
            -
                  class ArrayAlignment <  
     | 
| 
      
 36 
     | 
    
         
            +
                  class ArrayAlignment < Base
         
     | 
| 
       37 
37 
     | 
    
         
             
                    include Alignment
         
     | 
| 
      
 38 
     | 
    
         
            +
                    extend AutoCorrector
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
40 
     | 
    
         
             
                    ALIGN_ELEMENTS_MSG = 'Align the elements of an array literal ' \
         
     | 
| 
       40 
41 
     | 
    
         
             
                      'if they span more than one line.'
         
     | 
| 
         @@ -49,13 +50,13 @@ module RuboCop 
     | 
|
| 
       49 
50 
     | 
    
         
             
                      check_alignment(node.children, base_column(node, node.children))
         
     | 
| 
       50 
51 
     | 
    
         
             
                    end
         
     | 
| 
       51 
52 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                    def autocorrect(node)
         
     | 
| 
       53 
     | 
    
         
            -
                      AlignmentCorrector.correct(processed_source, node, column_delta)
         
     | 
| 
       54 
     | 
    
         
            -
                    end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
53 
     | 
    
         
             
                    private
         
     | 
| 
       57 
54 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                    def  
     | 
| 
      
 55 
     | 
    
         
            +
                    def autocorrect(corrector, node)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    def message(_range)
         
     | 
| 
       59 
60 
     | 
    
         
             
                      fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_ELEMENTS_MSG
         
     | 
| 
       60 
61 
     | 
    
         
             
                    end
         
     | 
| 
       61 
62 
     | 
    
         |