rubocop 0.15.0 → 0.16.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.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -10
- data/.travis.yml +2 -1
- data/CHANGELOG.md +55 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/config/default.yml +99 -16
- data/config/enabled.yml +28 -16
- data/lib/rubocop.rb +16 -2
- data/lib/rubocop/cli.rb +10 -91
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/config_loader.rb +18 -10
- data/lib/rubocop/config_store.rb +3 -2
- data/lib/rubocop/cop/check_assignment.rb +43 -0
- data/lib/rubocop/cop/check_methods.rb +18 -0
- data/lib/rubocop/cop/commissioner.rb +15 -3
- data/lib/rubocop/cop/cop.rb +51 -43
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +7 -7
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +56 -19
- data/lib/rubocop/cop/lint/end_in_method.rb +4 -10
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -16
- data/lib/rubocop/cop/lint/void.rb +5 -5
- data/lib/rubocop/cop/rails/default_scope.rb +33 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -4
- data/lib/rubocop/cop/rails/output.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +31 -16
- data/lib/rubocop/cop/style/accessor_method_name.rb +53 -0
- data/lib/rubocop/cop/style/alias.rb +14 -2
- data/lib/rubocop/cop/style/align_hash.rb +15 -16
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/array_syntax.rb +22 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -3
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +13 -12
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +5 -1
- data/lib/rubocop/cop/style/blocks.rb +4 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +48 -22
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +25 -6
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_length.rb +7 -19
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/code_length.rb +35 -0
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +51 -0
- data/lib/rubocop/cop/style/configurable_max.rb +17 -0
- data/lib/rubocop/cop/style/configurable_naming.rb +4 -10
- data/lib/rubocop/cop/style/constant_name.rb +5 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +8 -13
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -43
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +6 -2
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +5 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +28 -13
- data/lib/rubocop/cop/style/empty_literal.rb +3 -3
- data/lib/rubocop/cop/style/encoding.rb +5 -5
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +8 -6
- data/lib/rubocop/cop/style/even_odd.rb +6 -6
- data/lib/rubocop/cop/style/favor_join.rb +1 -1
- data/lib/rubocop/cop/style/favor_modifier.rb +20 -34
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +1 -1
- data/lib/rubocop/cop/style/flip_flop.rb +20 -0
- data/lib/rubocop/cop/style/for.rb +34 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/hash_methods.rb +3 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +8 -11
- data/lib/rubocop/cop/style/if_node.rb +25 -0
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +77 -43
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +4 -12
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +9 -5
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +52 -0
- data/lib/rubocop/cop/style/method_length.rb +9 -22
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +11 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +54 -0
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -10
- data/lib/rubocop/cop/style/redundant_begin.rb +5 -15
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -19
- data/lib/rubocop/cop/style/redundant_self.rb +8 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +4 -3
- data/lib/rubocop/cop/style/rescue_modifier.rb +9 -17
- data/lib/rubocop/cop/style/semicolon.rb +20 -22
- data/lib/rubocop/cop/style/signal_exception.rb +10 -17
- data/lib/rubocop/cop/style/single_line_block_params.rb +62 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +5 -15
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +4 -12
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_braces.rb +105 -94
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/style/space_around_operators.rb +38 -123
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_inside.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +5 -5
- data/lib/rubocop/cop/style/space_inside_parens.rb +0 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_help.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -11
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +3 -10
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +4 -14
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +3 -1
- data/lib/rubocop/cop/style/while_until_do.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +4 -10
- data/lib/rubocop/cop/util.rb +85 -12
- data/lib/rubocop/cop/variable_inspector.rb +4 -2
- data/lib/rubocop/file_inspector.rb +98 -0
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +10 -2
- data/lib/rubocop/rake_task.rb +5 -1
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +12 -0
- data/rubocop.gemspec +1 -1
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/rubocop/cli_spec.rb +120 -27
- data/spec/rubocop/config_loader_spec.rb +25 -11
- data/spec/rubocop/config_spec.rb +25 -9
- data/spec/rubocop/config_store_spec.rb +1 -1
- data/spec/rubocop/cop/cop_spec.rb +22 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +4 -4
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +79 -47
- data/spec/rubocop/cop/lint/syntax_spec.rb +4 -3
- data/spec/rubocop/cop/rails/default_scope_spec.rb +31 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +37 -2
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +10 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +3 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +83 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +227 -71
- data/spec/rubocop/cop/style/class_length_spec.rb +2 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +6 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +1 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +12 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +10 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +22 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +6 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -0
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +15 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +96 -18
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +8 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +185 -20
- data/spec/rubocop/cop/style/line_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +72 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +16 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +34 -3
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +15 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +5 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +16 -16
- data/spec/rubocop/cop/style/{reduce_arguments_spec.rb → single_line_block_params_spec.rb} +12 -4
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +58 -8
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +71 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +18 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +2 -2
- data/spec/rubocop/processed_source_spec.rb +7 -3
- data/spec/rubocop/token_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/isolated_environment.rb +7 -0
- data/spec/support/shared_context.rb +5 -1
- metadata +35 -12
- data/lib/rubocop/cop/style/reduce_arguments.rb +0 -34
- data/lib/rubocop/cop/style/symbol_name.rb +0 -45
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +0 -33
- data/spec/rubocop/cop/style/symbol_name_spec.rb +0 -138
| @@ -7,6 +7,8 @@ module Rubocop | |
| 7 7 | 
             
                  # Modifiers should be indented as deeps are method definitions and
         | 
| 8 8 | 
             
                  # surrounded by blank lines.
         | 
| 9 9 | 
             
                  class AccessModifierIndentation < Cop
         | 
| 10 | 
            +
                    include ConfigurableEnforcedStyle
         | 
| 11 | 
            +
             | 
| 10 12 | 
             
                    MSG = '%s access modifiers like %s.'
         | 
| 11 13 |  | 
| 12 14 | 
             
                    PRIVATE_NODE = s(:send, nil, :private)
         | 
| @@ -27,24 +29,39 @@ module Rubocop | |
| 27 29 | 
             
                        # except other class/module nodes
         | 
| 28 30 | 
             
                        class_node.children.compact.each do |node|
         | 
| 29 31 | 
             
                          on_node(:send, node, [:class, :module, :sclass]) do |send_node|
         | 
| 30 | 
            -
                            if modifier_node?(send_node)
         | 
| 31 | 
            -
                               | 
| 32 | 
            -
             | 
| 33 | 
            -
                              if send_start_col != class_start_col + expected_indent_offset
         | 
| 34 | 
            -
                                convention(send_node, :expression)
         | 
| 35 | 
            -
                              end
         | 
| 32 | 
            +
                            if self.class.modifier_node?(send_node)
         | 
| 33 | 
            +
                              check(send_node, class_start_col)
         | 
| 36 34 | 
             
                            end
         | 
| 37 35 | 
             
                          end
         | 
| 38 36 | 
             
                        end
         | 
| 39 37 | 
             
                      end
         | 
| 40 38 | 
             
                    end
         | 
| 41 39 |  | 
| 40 | 
            +
                    def self.modifier_node?(node)
         | 
| 41 | 
            +
                      [PRIVATE_NODE, PROTECTED_NODE, PUBLIC_NODE].include?(node)
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 42 44 | 
             
                    private
         | 
| 43 45 |  | 
| 46 | 
            +
                    def check(send_node, class_start_col)
         | 
| 47 | 
            +
                      access_modifier_start_col = send_node.loc.expression.column
         | 
| 48 | 
            +
                      offset = access_modifier_start_col - class_start_col
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                      if offset == expected_indent_offset
         | 
| 51 | 
            +
                        correct_style_detected
         | 
| 52 | 
            +
                      else
         | 
| 53 | 
            +
                        add_offence(send_node, :expression) do
         | 
| 54 | 
            +
                          if offset == unexpected_indent_offset
         | 
| 55 | 
            +
                            opposite_style_detected
         | 
| 56 | 
            +
                          else
         | 
| 57 | 
            +
                            unrecognized_style_detected
         | 
| 58 | 
            +
                          end
         | 
| 59 | 
            +
                        end
         | 
| 60 | 
            +
                      end
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 44 63 | 
             
                    def message(node)
         | 
| 45 | 
            -
                      format(MSG,
         | 
| 46 | 
            -
                             cop_config['EnforcedStyle'].capitalize,
         | 
| 47 | 
            -
                             node.loc.selector.source)
         | 
| 64 | 
            +
                      format(MSG, style.capitalize, node.loc.selector.source)
         | 
| 48 65 | 
             
                    end
         | 
| 49 66 |  | 
| 50 67 | 
             
                    def class_constructor?(block_node)
         | 
| @@ -55,15 +72,13 @@ module Rubocop | |
| 55 72 | 
             
                    end
         | 
| 56 73 |  | 
| 57 74 | 
             
                    def expected_indent_offset
         | 
| 58 | 
            -
                       | 
| 59 | 
            -
                      when 'outdent' then 0
         | 
| 60 | 
            -
                      when 'indent' then 2
         | 
| 61 | 
            -
                      else fail 'Unknown EnforcedStyle specified'
         | 
| 62 | 
            -
                      end
         | 
| 75 | 
            +
                      style == :outdent ? 0 : IndentationWidth::CORRECT_INDENTATION
         | 
| 63 76 | 
             
                    end
         | 
| 64 77 |  | 
| 65 | 
            -
                     | 
| 66 | 
            -
             | 
| 78 | 
            +
                    # An offset that is not expected, but correct if the configuration is
         | 
| 79 | 
            +
                    # changed.
         | 
| 80 | 
            +
                    def unexpected_indent_offset
         | 
| 81 | 
            +
                      IndentationWidth::CORRECT_INDENTATION - expected_indent_offset
         | 
| 67 82 | 
             
                    end
         | 
| 68 83 | 
             
                  end
         | 
| 69 84 | 
             
                end
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Rubocop
         | 
| 4 | 
            +
              module Cop
         | 
| 5 | 
            +
                module Style
         | 
| 6 | 
            +
                  # This cop makes sure that accessor methods are named properly.
         | 
| 7 | 
            +
                  #
         | 
| 8 | 
            +
                  # @example
         | 
| 9 | 
            +
                  #   # bad
         | 
| 10 | 
            +
                  #   def set_attribute(value) ...
         | 
| 11 | 
            +
                  #
         | 
| 12 | 
            +
                  #   # good
         | 
| 13 | 
            +
                  #   def attribute=(value)
         | 
| 14 | 
            +
                  #
         | 
| 15 | 
            +
                  #   # bad
         | 
| 16 | 
            +
                  #   def get_attribute ...
         | 
| 17 | 
            +
                  #
         | 
| 18 | 
            +
                  #   # good
         | 
| 19 | 
            +
                  #   def attribute ...
         | 
| 20 | 
            +
                  class AccessorMethodName < Cop
         | 
| 21 | 
            +
                    def on_def(node)
         | 
| 22 | 
            +
                      method_name, args, _body = *node
         | 
| 23 | 
            +
                      check(node, method_name.to_s, args)
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    def on_defs(node)
         | 
| 27 | 
            +
                      _scope, method_name, args, _body = *node
         | 
| 28 | 
            +
                      check(node, method_name.to_s, args)
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def check(node, method_name, args)
         | 
| 34 | 
            +
                      if bad_reader_name?(method_name, args)
         | 
| 35 | 
            +
                        add_offence(node, :name,
         | 
| 36 | 
            +
                                    'Do not prefix reader method names with get_.')
         | 
| 37 | 
            +
                      elsif bad_writer_name?(method_name, args)
         | 
| 38 | 
            +
                        add_offence(node, :name,
         | 
| 39 | 
            +
                                    'Do not prefix writer method names with set_.')
         | 
| 40 | 
            +
                      end
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    def bad_reader_name?(method_name, args)
         | 
| 44 | 
            +
                      method_name.start_with?('get_') && args.to_a.empty?
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    def bad_writer_name?(method_name, args)
         | 
| 48 | 
            +
                      method_name.start_with?('set_') && args.to_a.one?
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| @@ -10,7 +10,6 @@ module Rubocop | |
| 10 10 |  | 
| 11 11 | 
             
                    def on_block(node)
         | 
| 12 12 | 
             
                      method, _args, body = *node
         | 
| 13 | 
            -
             | 
| 14 13 | 
             
                      _receiver, method_name = *method
         | 
| 15 14 |  | 
| 16 15 | 
             
                      # using alias is the only option in certain scenarios
         | 
| @@ -28,7 +27,20 @@ module Rubocop | |
| 28 27 |  | 
| 29 28 | 
             
                      return if new.type == :gvar && old.type == :gvar
         | 
| 30 29 |  | 
| 31 | 
            -
                       | 
| 30 | 
            +
                      add_offence(node, :keyword)
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def autocorrect(node)
         | 
| 34 | 
            +
                      @corrections << lambda do |corrector|
         | 
| 35 | 
            +
                        # replace alias with alias_method
         | 
| 36 | 
            +
                        corrector.replace(node.loc.keyword, 'alias_method')
         | 
| 37 | 
            +
                        # insert a comma
         | 
| 38 | 
            +
                        new, old = *node
         | 
| 39 | 
            +
                        corrector.insert_after(new.loc.expression, ',')
         | 
| 40 | 
            +
                        # convert bareword arguments to symbols
         | 
| 41 | 
            +
                        corrector.replace(new.loc.expression, ":#{new.children.first}")
         | 
| 42 | 
            +
                        corrector.replace(old.loc.expression, ":#{old.children.first}")
         | 
| 43 | 
            +
                      end
         | 
| 32 44 | 
             
                    end
         | 
| 33 45 | 
             
                  end
         | 
| 34 46 | 
             
                end
         | 
| @@ -46,6 +46,14 @@ module Rubocop | |
| 46 46 |  | 
| 47 47 | 
             
                      private
         | 
| 48 48 |  | 
| 49 | 
            +
                      def separator_delta(first_pair, current_separator, key_delta)
         | 
| 50 | 
            +
                        if current_separator.is?(':')
         | 
| 51 | 
            +
                          0 # Colon follows directly after key
         | 
| 52 | 
            +
                        else
         | 
| 53 | 
            +
                          hash_rocket_delta(first_pair, current_separator) - key_delta
         | 
| 54 | 
            +
                        end
         | 
| 55 | 
            +
                      end
         | 
| 56 | 
            +
             | 
| 49 57 | 
             
                      def any_pairs_on_the_same_line?(node)
         | 
| 50 58 | 
             
                        lines_of_the_children = node.children.map do |pair|
         | 
| 51 59 | 
             
                          key, _value = *pair
         | 
| @@ -87,13 +95,9 @@ module Rubocop | |
| 87 95 | 
             
                        first_pair.loc.column - current_pair.loc.column
         | 
| 88 96 | 
             
                      end
         | 
| 89 97 |  | 
| 90 | 
            -
                      def  | 
| 91 | 
            -
                         | 
| 92 | 
            -
                           | 
| 93 | 
            -
                        else
         | 
| 94 | 
            -
                          first_pair.loc.column + @max_key_width + 1 -
         | 
| 95 | 
            -
                            current_separator.column - key_delta
         | 
| 96 | 
            -
                        end
         | 
| 98 | 
            +
                      def hash_rocket_delta(first_pair, current_separator)
         | 
| 99 | 
            +
                        first_pair.loc.column + @max_key_width + 1 -
         | 
| 100 | 
            +
                          current_separator.column
         | 
| 97 101 | 
             
                      end
         | 
| 98 102 |  | 
| 99 103 | 
             
                      def value_delta(first_pair, current_pair)
         | 
| @@ -126,13 +130,8 @@ module Rubocop | |
| 126 130 | 
             
                        key.loc.column + key.loc.expression.source.length
         | 
| 127 131 | 
             
                      end
         | 
| 128 132 |  | 
| 129 | 
            -
                      def  | 
| 130 | 
            -
                         | 
| 131 | 
            -
                          0 # Colon follows directly after key
         | 
| 132 | 
            -
                        else
         | 
| 133 | 
            -
                          first_pair.loc.operator.column - current_separator.column -
         | 
| 134 | 
            -
                            key_delta
         | 
| 135 | 
            -
                        end
         | 
| 133 | 
            +
                      def hash_rocket_delta(first_pair, current_separator)
         | 
| 134 | 
            +
                        first_pair.loc.operator.column - current_separator.column
         | 
| 136 135 | 
             
                      end
         | 
| 137 136 |  | 
| 138 137 | 
             
                      def value_delta(first_pair, current_pair)
         | 
| @@ -161,12 +160,12 @@ module Rubocop | |
| 161 160 |  | 
| 162 161 | 
             
                      @column_deltas = alignment_for(first_pair)
         | 
| 163 162 | 
             
                        .deltas_for_first_pair(first_pair, node)
         | 
| 164 | 
            -
                       | 
| 163 | 
            +
                      add_offence(first_pair, :expression) unless good_alignment?
         | 
| 165 164 |  | 
| 166 165 | 
             
                      node.children.each_cons(2) do |prev, current|
         | 
| 167 166 | 
             
                        @column_deltas = alignment_for(current).deltas(first_pair, prev,
         | 
| 168 167 | 
             
                                                                       current)
         | 
| 169 | 
            -
                         | 
| 168 | 
            +
                        add_offence(current, :expression) unless good_alignment?
         | 
| 170 169 | 
             
                      end
         | 
| 171 170 | 
             
                    end
         | 
| 172 171 |  | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Rubocop
         | 
| 4 | 
            +
              module Cop
         | 
| 5 | 
            +
                module Style
         | 
| 6 | 
            +
                  # Common code for ordinary arrays with [] that can be written with %
         | 
| 7 | 
            +
                  # syntax.
         | 
| 8 | 
            +
                  module ArraySyntax
         | 
| 9 | 
            +
                    def array_of?(element_type, node)
         | 
| 10 | 
            +
                      return false unless node.loc.begin && node.loc.begin.is?('[')
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      array_elems = node.children
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      # no need to check empty arrays
         | 
| 15 | 
            +
                      return false unless array_elems && array_elems.size > 1
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                      array_elems.all? { |e| e.type == element_type }
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -1,7 +1,5 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 | 
            -
            # rubocop:disable SymbolName
         | 
| 4 | 
            -
             | 
| 5 3 | 
             
            module Rubocop
         | 
| 6 4 | 
             
              module Cop
         | 
| 7 5 | 
             
                module Style
         | 
| @@ -12,7 +10,7 @@ module Rubocop | |
| 12 10 | 
             
                    def investigate(processed_source)
         | 
| 13 11 | 
             
                      processed_source.tokens.each do |t|
         | 
| 14 12 | 
             
                        if t.type == :tIDENTIFIER && !t.text.ascii_only?
         | 
| 15 | 
            -
                           | 
| 13 | 
            +
                          add_offence(nil, t.pos)
         | 
| 16 14 | 
             
                        end
         | 
| 17 15 | 
             
                      end
         | 
| 18 16 | 
             
                    end
         | 
| @@ -11,7 +11,7 @@ module Rubocop | |
| 11 11 | 
             
                      items.each_cons(2) do |prev, current|
         | 
| 12 12 | 
             
                        if current.loc.line > prev.loc.line && start_of_line?(current.loc)
         | 
| 13 13 | 
             
                          @column_delta = items.first.loc.column - current.loc.column
         | 
| 14 | 
            -
                           | 
| 14 | 
            +
                          add_offence(current, :expression) if @column_delta != 0
         | 
| 15 15 | 
             
                        end
         | 
| 16 16 | 
             
                      end
         | 
| 17 17 | 
             
                    end
         | 
| @@ -30,17 +30,7 @@ module Rubocop | |
| 30 30 | 
             
                      @corrections << lambda do |corrector|
         | 
| 31 31 | 
             
                        expr = node.loc.expression
         | 
| 32 32 | 
             
                        each_line(expr) do |line_begin_pos, line|
         | 
| 33 | 
            -
                           | 
| 34 | 
            -
                            expr.source_buffer.source[line_begin_pos] =~ / /
         | 
| 35 | 
            -
                          pos_to_remove = if column_delta > 0 || starts_with_space
         | 
| 36 | 
            -
                                            line_begin_pos
         | 
| 37 | 
            -
                                          else
         | 
| 38 | 
            -
                                            line_begin_pos - column_delta.abs
         | 
| 39 | 
            -
                                          end
         | 
| 40 | 
            -
                          range = Parser::Source::Range.new(expr.source_buffer,
         | 
| 41 | 
            -
                                                            pos_to_remove,
         | 
| 42 | 
            -
                                                            pos_to_remove +
         | 
| 43 | 
            -
                                                            column_delta.abs)
         | 
| 33 | 
            +
                          range = calculate_range(expr, line_begin_pos, column_delta)
         | 
| 44 34 | 
             
                          if column_delta > 0
         | 
| 45 35 | 
             
                            corrector.insert_before(range, ' ' * column_delta)
         | 
| 46 36 | 
             
                          else
         | 
| @@ -50,6 +40,17 @@ module Rubocop | |
| 50 40 | 
             
                      end
         | 
| 51 41 | 
             
                    end
         | 
| 52 42 |  | 
| 43 | 
            +
                    def calculate_range(expr, line_begin_pos, column_delta)
         | 
| 44 | 
            +
                      starts_with_space = expr.source_buffer.source[line_begin_pos] =~ / /
         | 
| 45 | 
            +
                      pos_to_remove = if column_delta > 0 || starts_with_space
         | 
| 46 | 
            +
                                        line_begin_pos
         | 
| 47 | 
            +
                                      else
         | 
| 48 | 
            +
                                        line_begin_pos - column_delta.abs
         | 
| 49 | 
            +
                                      end
         | 
| 50 | 
            +
                      Parser::Source::Range.new(expr.source_buffer, pos_to_remove,
         | 
| 51 | 
            +
                                                pos_to_remove + column_delta.abs)
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
             | 
| 53 54 | 
             
                    def remove(range, corrector)
         | 
| 54 55 | 
             
                      original_stderr = $stderr
         | 
| 55 56 | 
             
                      $stderr = StringIO.new # Avoid error messages on console
         | 
| @@ -9,6 +9,8 @@ module Rubocop | |
| 9 9 | 
             
                  #
         | 
| 10 10 | 
             
                  # The maximum level of nesting allowed is configurable.
         | 
| 11 11 | 
             
                  class BlockNesting < Cop
         | 
| 12 | 
            +
                    include ConfigurableMax
         | 
| 13 | 
            +
             | 
| 12 14 | 
             
                    NESTING_BLOCKS = [:case, :if, :while, :while_post, :until, :until_post,
         | 
| 13 15 | 
             
                                      :for, :resbody]
         | 
| 14 16 |  | 
| @@ -27,7 +29,9 @@ module Rubocop | |
| 27 29 | 
             
                          current_level += 1
         | 
| 28 30 | 
             
                        end
         | 
| 29 31 | 
             
                        if current_level == max + 1
         | 
| 30 | 
            -
                           | 
| 32 | 
            +
                          add_offence(node, :expression, message(max)) do
         | 
| 33 | 
            +
                            self.max = current_level
         | 
| 34 | 
            +
                          end
         | 
| 31 35 | 
             
                          return
         | 
| 32 36 | 
             
                        end
         | 
| 33 37 | 
             
                      end
         | 
| @@ -13,7 +13,7 @@ module Rubocop | |
| 13 13 | 
             
                      _receiver, method_name, *args = *node
         | 
| 14 14 | 
             
                      if args.any?
         | 
| 15 15 | 
             
                        block = get_block(args.last)
         | 
| 16 | 
            -
                        if block && ! | 
| 16 | 
            +
                        if block && !parentheses?(node) && !operator?(method_name)
         | 
| 17 17 | 
             
                          # If there are no parentheses around the arguments, then braces
         | 
| 18 18 | 
             
                          # and do-end have different meaning due to how they bind, so we
         | 
| 19 19 | 
             
                          # allow either.
         | 
| @@ -29,9 +29,9 @@ module Rubocop | |
| 29 29 | 
             
                      block_begin = node.loc.begin.source
         | 
| 30 30 |  | 
| 31 31 | 
             
                      if block_length > 0 && block_begin == '{'
         | 
| 32 | 
            -
                         | 
| 32 | 
            +
                        add_offence(node, :begin, MULTI_LINE_MSG)
         | 
| 33 33 | 
             
                      elsif block_length == 0 && block_begin != '{'
         | 
| 34 | 
            -
                         | 
| 34 | 
            +
                        add_offence(node, :begin, SINGLE_LINE_MSG)
         | 
| 35 35 | 
             
                      end
         | 
| 36 36 | 
             
                    end
         | 
| 37 37 |  | 
| @@ -65,7 +65,7 @@ module Rubocop | |
| 65 65 | 
             
                      end
         | 
| 66 66 | 
             
                    end
         | 
| 67 67 |  | 
| 68 | 
            -
                    def  | 
| 68 | 
            +
                    def parentheses?(send_node)
         | 
| 69 69 | 
             
                      send_node.loc.begin
         | 
| 70 70 | 
             
                    end
         | 
| 71 71 |  | 
| @@ -5,41 +5,67 @@ module Rubocop | |
| 5 5 | 
             
                module Style
         | 
| 6 6 | 
             
                  # This cop checks for braces in method calls with hash parameters.
         | 
| 7 7 | 
             
                  class BracesAroundHashParameters < Cop
         | 
| 8 | 
            +
                    include ConfigurableEnforcedStyle
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
                    def on_send(node)
         | 
| 9 11 | 
             
                      _receiver, method_name, *args = *node
         | 
| 10 12 |  | 
| 11 | 
            -
                      #  | 
| 13 | 
            +
                      # Discard attr writer methods.
         | 
| 12 14 | 
             
                      return if method_name.to_s.end_with?('=')
         | 
| 13 | 
            -
                      #  | 
| 15 | 
            +
                      # Discard operator methods.
         | 
| 14 16 | 
             
                      return if OPERATOR_METHODS.include?(method_name)
         | 
| 15 17 |  | 
| 16 | 
            -
                      #  | 
| 18 | 
            +
                      # We care only for the last argument.
         | 
| 17 19 | 
             
                      arg = args.last
         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                      has_braces = !arg.loc.begin.nil?
         | 
| 21 | 
            -
                      all_hashes = args.length > 1 && args.all? { |a| a.type == :hash }
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                      if style == :no_braces && has_braces && !all_hashes
         | 
| 24 | 
            -
                        convention(arg,
         | 
| 25 | 
            -
                                   :expression,
         | 
| 26 | 
            -
                                   'Redundant curly braces around a hash parameter.')
         | 
| 27 | 
            -
                      elsif style == :braces && !has_braces
         | 
| 28 | 
            -
                        convention(arg,
         | 
| 29 | 
            -
                                   :expression,
         | 
| 30 | 
            -
                                   'Missing curly braces around a hash parameter.')
         | 
| 31 | 
            -
                      end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                      check(arg, args) if non_empty_hash?(arg)
         | 
| 32 22 | 
             
                    end
         | 
| 33 23 |  | 
| 34 24 | 
             
                    private
         | 
| 35 25 |  | 
| 36 | 
            -
                    def  | 
| 37 | 
            -
                       | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 26 | 
            +
                    def check(arg, args)
         | 
| 27 | 
            +
                      if style == :no_braces
         | 
| 28 | 
            +
                        if !braces?(arg) || all_hashes?(args)
         | 
| 29 | 
            +
                          correct_style_detected
         | 
| 30 | 
            +
                        else
         | 
| 31 | 
            +
                          add_offence(arg, :expression,
         | 
| 32 | 
            +
                                      'Redundant curly braces around a hash parameter.') do
         | 
| 33 | 
            +
                            opposite_style_detected
         | 
| 34 | 
            +
                          end
         | 
| 35 | 
            +
                        end
         | 
| 36 | 
            +
                      elsif braces?(arg)
         | 
| 37 | 
            +
                        correct_style_detected
         | 
| 38 | 
            +
                      else
         | 
| 39 | 
            +
                        add_offence(arg, :expression,
         | 
| 40 | 
            +
                                    'Missing curly braces around a hash parameter.') do
         | 
| 41 | 
            +
                          opposite_style_detected
         | 
| 42 | 
            +
                        end
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    def autocorrect(node)
         | 
| 47 | 
            +
                      @corrections << lambda do |corrector|
         | 
| 48 | 
            +
                        if style == :no_braces
         | 
| 49 | 
            +
                          corrector.remove(node.loc.begin)
         | 
| 50 | 
            +
                          corrector.remove(node.loc.end)
         | 
| 51 | 
            +
                        elsif style == :braces
         | 
| 52 | 
            +
                          corrector.insert_before(node.loc.expression, '{')
         | 
| 53 | 
            +
                          corrector.insert_after(node.loc.expression, '}')
         | 
| 54 | 
            +
                        end
         | 
| 41 55 | 
             
                      end
         | 
| 42 56 | 
             
                    end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    def non_empty_hash?(arg)
         | 
| 59 | 
            +
                      arg && arg.type == :hash && arg.children.any?
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    def braces?(arg)
         | 
| 63 | 
            +
                      !arg.loc.begin.nil?
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    def all_hashes?(args)
         | 
| 67 | 
            +
                      args.length > 1 && args.all? { |a| a.type == :hash }
         | 
| 68 | 
            +
                    end
         | 
| 43 69 | 
             
                  end
         | 
| 44 70 | 
             
                end
         | 
| 45 71 | 
             
              end
         |