rubocop 0.14.1 → 0.15.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 +5 -3
 - data/CHANGELOG.md +245 -198
 - data/README.md +7 -0
 - data/Rakefile +5 -1
 - data/config/default.yml +27 -4
 - data/config/enabled.yml +18 -4
 - data/lib/rubocop.rb +13 -1
 - data/lib/rubocop/cli.rb +83 -23
 - data/lib/rubocop/config.rb +1 -1
 - data/lib/rubocop/cop/cop.rb +31 -6
 - data/lib/rubocop/cop/lint/block_alignment.rb +11 -8
 - data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +21 -14
 - data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
 - data/lib/rubocop/cop/rails/output.rb +35 -0
 - data/lib/rubocop/cop/style/{access_control.rb → access_modifier_indentation.rb} +18 -15
 - data/lib/rubocop/cop/style/alias.rb +14 -2
 - data/lib/rubocop/cop/style/align_hash.rb +174 -109
 - data/lib/rubocop/cop/style/autocorrect_alignment.rb +38 -18
 - data/lib/rubocop/cop/style/blocks.rb +4 -6
 - data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +3 -3
 - data/lib/rubocop/cop/style/cyclomatic_complexity.rb +46 -0
 - data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +48 -0
 - data/lib/rubocop/cop/style/empty_lines_around_body.rb +62 -0
 - data/lib/rubocop/cop/style/end_of_line.rb +6 -2
 - data/lib/rubocop/cop/style/favor_modifier.rb +11 -1
 - data/lib/rubocop/cop/style/final_newline.rb +10 -4
 - data/lib/rubocop/cop/style/hash_syntax.rb +32 -21
 - data/lib/rubocop/cop/style/leading_comment_space.rb +9 -0
 - data/lib/rubocop/cop/style/method_call_parentheses.rb +11 -1
 - data/lib/rubocop/cop/style/numeric_literals.rb +11 -15
 - data/lib/rubocop/cop/style/redundant_return.rb +7 -4
 - data/lib/rubocop/cop/style/redundant_self.rb +3 -3
 - data/lib/rubocop/cop/style/signal_exception.rb +4 -2
 - data/lib/rubocop/cop/style/space_after_comma_etc.rb +7 -1
 - data/lib/rubocop/cop/style/space_after_control_keyword.rb +6 -0
 - data/lib/rubocop/cop/style/space_after_method_name.rb +7 -1
 - data/lib/rubocop/cop/style/space_after_not.rb +6 -2
 - data/lib/rubocop/cop/style/space_around_block_braces.rb +149 -0
 - data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +33 -0
 - data/lib/rubocop/cop/style/space_around_operators.rb +169 -0
 - data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -0
 - data/lib/rubocop/cop/style/space_inside.rb +35 -0
 - data/lib/rubocop/cop/style/space_inside_brackets.rb +18 -0
 - data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +99 -0
 - data/lib/rubocop/cop/style/space_inside_parens.rb +18 -0
 - data/lib/rubocop/cop/style/special_global_vars.rb +52 -25
 - data/lib/rubocop/cop/style/string_literals.rb +1 -1
 - data/lib/rubocop/cop/style/surrounding_space.rb +1 -344
 - data/lib/rubocop/cop/style/trailing_blank_lines.rb +17 -5
 - data/lib/rubocop/cop/style/trailing_whitespace.rb +9 -5
 - data/lib/rubocop/cop/style/trivial_accessors.rb +1 -2
 - data/lib/rubocop/cop/style/word_array.rb +16 -1
 - data/lib/rubocop/cop/team.rb +5 -5
 - data/lib/rubocop/cop/util.rb +1 -0
 - data/lib/rubocop/formatter/offence_count_formatter.rb +0 -1
 - data/lib/rubocop/options.rb +76 -111
 - data/lib/rubocop/rake_task.rb +4 -2
 - data/lib/rubocop/target_finder.rb +3 -3
 - data/lib/rubocop/version.rb +1 -1
 - data/spec/rubocop/cli_spec.rb +123 -13
 - data/spec/rubocop/config_spec.rb +2 -2
 - data/spec/rubocop/cop/lint/rescue_exception_spec.rb +10 -0
 - data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +13 -0
 - data/spec/rubocop/cop/offence_spec.rb +2 -0
 - data/spec/rubocop/cop/rails/output_spec.rb +40 -0
 - data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +243 -0
 - data/spec/rubocop/cop/style/alias_spec.rb +8 -0
 - data/spec/rubocop/cop/style/align_array_spec.rb +12 -0
 - data/spec/rubocop/cop/style/align_hash_spec.rb +15 -0
 - data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +7 -4
 - data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +203 -0
 - data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +56 -0
 - data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +87 -0
 - data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -8
 - data/spec/rubocop/cop/style/favor_modifier_spec.rb +34 -0
 - data/spec/rubocop/cop/style/final_newline_spec.rb +5 -0
 - data/spec/rubocop/cop/style/hash_syntax_spec.rb +22 -2
 - data/spec/rubocop/cop/style/leading_comment_space_spec.rb +5 -0
 - data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +39 -4
 - data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -0
 - data/spec/rubocop/cop/style/signal_exception_spec.rb +11 -0
 - data/spec/rubocop/cop/style/space_after_colon_spec.rb +7 -0
 - data/spec/rubocop/cop/style/space_after_comma_spec.rb +5 -0
 - data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +29 -8
 - data/spec/rubocop/cop/style/space_after_method_name_spec.rb +15 -0
 - data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +5 -0
 - data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +68 -0
 - data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +5 -0
 - data/spec/rubocop/cop/style/space_around_operators_spec.rb +43 -0
 - data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +23 -0
 - data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +7 -0
 - data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +65 -23
 - data/spec/rubocop/cop/style/space_inside_parens_spec.rb +7 -0
 - data/spec/rubocop/cop/style/special_global_vars_spec.rb +12 -2
 - data/spec/rubocop/cop/style/string_literals_spec.rb +6 -0
 - data/spec/rubocop/cop/style/symbol_array_spec.rb +5 -7
 - data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +26 -1
 - data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -0
 - data/spec/rubocop/cop/style/trivial_accessors_spec.rb +8 -0
 - data/spec/rubocop/cop/style/word_array_spec.rb +33 -2
 - data/spec/rubocop/cop/team_spec.rb +4 -4
 - data/spec/rubocop/formatter/json_formatter_spec.rb +1 -1
 - data/spec/rubocop/options_spec.rb +5 -96
 - data/spec/rubocop/processed_source_spec.rb +3 -3
 - data/spec/spec_helper.rb +28 -23
 - data/spec/support/mri_syntax_checker.rb +20 -16
 - metadata +24 -5
 - data/spec/rubocop/cop/style/access_control_spec.rb +0 -164
 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Rubocop::Cop::Style::EmptyLinesAroundAccessModifier do
         
     | 
| 
      
 6 
     | 
    
         
            +
              subject(:cop) { described_class.new }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              %w(private protected public).each do |access_modifier|
         
     | 
| 
      
 9 
     | 
    
         
            +
                it "requires blank line before #{access_modifier}" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  inspect_source(cop,
         
     | 
| 
      
 11 
     | 
    
         
            +
                                 ['class Test',
         
     | 
| 
      
 12 
     | 
    
         
            +
                                  '  something',
         
     | 
| 
      
 13 
     | 
    
         
            +
                                  "  #{access_modifier}",
         
     | 
| 
      
 14 
     | 
    
         
            +
                                  '',
         
     | 
| 
      
 15 
     | 
    
         
            +
                                  '  def test; end',
         
     | 
| 
      
 16 
     | 
    
         
            +
                                  'end'])
         
     | 
| 
      
 17 
     | 
    
         
            +
                  expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  expect(cop.messages)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    .to eq(["Keep a blank line before and after #{access_modifier}."])
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                it 'requires blank line after #{access_modifier}' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  inspect_source(cop,
         
     | 
| 
      
 24 
     | 
    
         
            +
                                 ['class Test',
         
     | 
| 
      
 25 
     | 
    
         
            +
                                  '  something',
         
     | 
| 
      
 26 
     | 
    
         
            +
                                  '',
         
     | 
| 
      
 27 
     | 
    
         
            +
                                  "  #{access_modifier}",
         
     | 
| 
      
 28 
     | 
    
         
            +
                                  '  def test; end',
         
     | 
| 
      
 29 
     | 
    
         
            +
                                  'end'])
         
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(cop.messages)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    .to eq(["Keep a blank line before and after #{access_modifier}."])
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                it 'accepts missing blank line when at the beginning of class/module' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  inspect_source(cop,
         
     | 
| 
      
 37 
     | 
    
         
            +
                                 ['class Test',
         
     | 
| 
      
 38 
     | 
    
         
            +
                                  "  #{access_modifier}",
         
     | 
| 
      
 39 
     | 
    
         
            +
                                  '',
         
     | 
| 
      
 40 
     | 
    
         
            +
                                  '  def test; end',
         
     | 
| 
      
 41 
     | 
    
         
            +
                                  'end'])
         
     | 
| 
      
 42 
     | 
    
         
            +
                  expect(cop.offences).to be_empty
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                it 'recognizes blank lines with DOS style line endings' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                  inspect_source(cop,
         
     | 
| 
      
 47 
     | 
    
         
            +
                                 ["class Test\r",
         
     | 
| 
      
 48 
     | 
    
         
            +
                                  "\r",
         
     | 
| 
      
 49 
     | 
    
         
            +
                                  "  #{access_modifier}\r",
         
     | 
| 
      
 50 
     | 
    
         
            +
                                  "\r",
         
     | 
| 
      
 51 
     | 
    
         
            +
                                  "  def test; end\r",
         
     | 
| 
      
 52 
     | 
    
         
            +
                                  "end\r"])
         
     | 
| 
      
 53 
     | 
    
         
            +
                  expect(cop.offences.size).to eq(0)
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,87 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Rubocop::Cop::Style::EmptyLinesAroundBody do
         
     | 
| 
      
 6 
     | 
    
         
            +
              subject(:cop) { described_class.new }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              it 'registers an offence for method body starting with a blank' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 10 
     | 
    
         
            +
                               ['def some_method',
         
     | 
| 
      
 11 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 12 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 13 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 14 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              it 'registers an offence for class method body starting with a blank' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 19 
     | 
    
         
            +
                               ['def Test.some_method',
         
     | 
| 
      
 20 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 21 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 22 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it 'registers an offence for method body ending with a blank' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 28 
     | 
    
         
            +
                               ['def some_method',
         
     | 
| 
      
 29 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 30 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 31 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              it 'registers an offence for class method body ending with a blank' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 37 
     | 
    
         
            +
                               ['def Test.some_method',
         
     | 
| 
      
 38 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 39 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 40 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 41 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              it 'registers an offence for class body starting with a blank' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 46 
     | 
    
         
            +
                               ['class SomeClass',
         
     | 
| 
      
 47 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 48 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 49 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 50 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              it 'registers an offence for module body starting with a blank' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 55 
     | 
    
         
            +
                               ['module SomeModule',
         
     | 
| 
      
 56 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 57 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 58 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 59 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              it 'registers an offence for class body ending with a blank' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 64 
     | 
    
         
            +
                               ['class SomeClass',
         
     | 
| 
      
 65 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 66 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 67 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 68 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
              it 'registers an offence for module body ending with a blank' do
         
     | 
| 
      
 72 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 73 
     | 
    
         
            +
                               ['module SomeModule',
         
     | 
| 
      
 74 
     | 
    
         
            +
                                '  do_something',
         
     | 
| 
      
 75 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 76 
     | 
    
         
            +
                                'end'])
         
     | 
| 
      
 77 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
              it 'is not fooled by single line methods' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                inspect_source(cop,
         
     | 
| 
      
 82 
     | 
    
         
            +
                               ['def some_method; do_something; end',
         
     | 
| 
      
 83 
     | 
    
         
            +
                                '',
         
     | 
| 
      
 84 
     | 
    
         
            +
                                'something_else'])
         
     | 
| 
      
 85 
     | 
    
         
            +
                expect(cop.offences).to be_empty
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,21 +1,30 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tempfile'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            describe Rubocop::Cop::Style::EndOfLine do
         
     | 
| 
       6 
7 
     | 
    
         
             
              subject(:cop) { described_class.new }
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
              it 'registers an offence for CR+LF' do
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
                inspect_source_file(cop, ['x=0', '', "y=1\r"])
         
     | 
| 
      
 11 
     | 
    
         
            +
                expect(cop.messages).to eq(['Carriage return character detected.'])
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              it 'highlights the whole offendng line' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                inspect_source_file(cop, ['x=0', '', "y=1\r"])
         
     | 
| 
      
 16 
     | 
    
         
            +
                expect(cop.highlights).to eq(["y=1\r"])
         
     | 
| 
       13 
17 
     | 
    
         
             
              end
         
     | 
| 
       14 
18 
     | 
    
         | 
| 
       15 
19 
     | 
    
         
             
              it 'registers an offence for CR at end of file' do
         
     | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                inspect_source_file(cop, ["x=0\r"])
         
     | 
| 
      
 21 
     | 
    
         
            +
                expect(cop.messages).to eq(['Carriage return character detected.'])
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              context 'when there are many lines ending with CR+LF' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                it 'registers only one offence' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  inspect_source_file(cop, ['x=0', '', 'y=1'].join("\r\n"))
         
     | 
| 
      
 27 
     | 
    
         
            +
                  expect(cop.messages.size).to eq(1)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
       20 
29 
     | 
    
         
             
              end
         
     | 
| 
       21 
30 
     | 
    
         
             
            end
         
     | 
| 
         @@ -89,6 +89,40 @@ describe Rubocop::Cop::Style::IfUnlessModifier do 
     | 
|
| 
       89 
89 
     | 
    
         
             
                                     'end'])
         
     | 
| 
       90 
90 
     | 
    
         
             
                expect(cop.offences).to be_empty
         
     | 
| 
       91 
91 
     | 
    
         
             
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
              context 'with implicit match conditional' do
         
     | 
| 
      
 94 
     | 
    
         
            +
                let(:source) do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  [
         
     | 
| 
      
 96 
     | 
    
         
            +
                    "  if #{conditional}",
         
     | 
| 
      
 97 
     | 
    
         
            +
                    "    #{body}",
         
     | 
| 
      
 98 
     | 
    
         
            +
                    '  end'
         
     | 
| 
      
 99 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                let(:body) { 'b' * 35 }
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                context 'when a multiline if fits on one line' do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  let(:conditional) { "/#{'a' * 36}/" }
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  it 'registers an offence' do
         
     | 
| 
      
 108 
     | 
    
         
            +
                    expect("  #{body} if #{conditional}".length).to eq(79)
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                    inspect_source(cop, source)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                context "when a multiline if doesn't fit on one line" do
         
     | 
| 
      
 116 
     | 
    
         
            +
                  let(:conditional) { "/#{'a' * 37}/" }
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                  it 'accepts' do
         
     | 
| 
      
 119 
     | 
    
         
            +
                    expect("  #{body} if #{conditional}".length).to eq(80)
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                    inspect_source(cop, source)
         
     | 
| 
      
 122 
     | 
    
         
            +
                    expect(cop.offences).to be_empty
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
       92 
126 
     | 
    
         
             
            end
         
     | 
| 
       93 
127 
     | 
    
         | 
| 
       94 
128 
     | 
    
         
             
            describe Rubocop::Cop::Style::WhileUntilModifier do
         
     | 
| 
         @@ -22,4 +22,9 @@ describe Rubocop::Cop::Style::FinalNewline do 
     | 
|
| 
       22 
22 
     | 
    
         
             
                inspect_source(cop, source)
         
     | 
| 
       23 
23 
     | 
    
         
             
                expect(cop.offences).to be_empty
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it 'auto-corrects missing newline' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                new_source = autocorrect_source(cop, ['x = 0'])
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(new_source).to eq(['x = 0', ''].join("\n"))
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       25 
30 
     | 
    
         
             
            end
         
     | 
| 
         @@ -6,7 +6,10 @@ describe Rubocop::Cop::Style::HashSyntax, :config do 
     | 
|
| 
       6 
6 
     | 
    
         
             
              subject(:cop) { described_class.new(config) }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              context 'configured to enforce ruby19 style' do
         
     | 
| 
       9 
     | 
    
         
            -
                let(: 
     | 
| 
      
 9 
     | 
    
         
            +
                let(:config) do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  Rubocop::Config.new('HashSyntax' => { 'EnforcedStyle' => 'ruby19' },
         
     | 
| 
      
 11 
     | 
    
         
            +
                                      'SpaceAroundOperators' => { 'Enabled' => true })
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
       10 
13 
     | 
    
         | 
| 
       11 
14 
     | 
    
         
             
                it 'registers offence for hash rocket syntax when new is possible' do
         
     | 
| 
       12 
15 
     | 
    
         
             
                  inspect_source(cop, ['x = { :a => 0 }'])
         
     | 
| 
         @@ -62,9 +65,26 @@ describe Rubocop::Cop::Style::HashSyntax, :config do 
     | 
|
| 
       62 
65 
     | 
    
         
             
                  new_source = autocorrect_source(cop, '{ :a => 1, :b   =>  2}')
         
     | 
| 
       63 
66 
     | 
    
         
             
                  expect(new_source).to eq('{ a: 1, b: 2}')
         
     | 
| 
       64 
67 
     | 
    
         
             
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                it 'does not auto-correct if it interferes with SpaceAroundOperators' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  new_source = autocorrect_source(cop, '{ :a=>1, :b=>2 }')
         
     | 
| 
      
 71 
     | 
    
         
            +
                  expect(new_source).to eq('{ :a=>1, :b=>2 }')
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                context 'with SpaceAroundOperators disabled' do
         
     | 
| 
      
 75 
     | 
    
         
            +
                  let(:config) do
         
     | 
| 
      
 76 
     | 
    
         
            +
                    Rubocop::Config.new('HashSyntax' => { 'EnforcedStyle' => 'ruby19' },
         
     | 
| 
      
 77 
     | 
    
         
            +
                                        'SpaceAroundOperators' => { 'Enabled' => false })
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  it 'auto-corrects even if there is no space around =>' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                    new_source = autocorrect_source(cop, '{ :a=>1, :b=>2 }')
         
     | 
| 
      
 82 
     | 
    
         
            +
                    expect(new_source).to eq('{ a: 1, b: 2 }')
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
       65 
85 
     | 
    
         
             
              end
         
     | 
| 
       66 
86 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
              context 'configured to enforce  
     | 
| 
      
 87 
     | 
    
         
            +
              context 'configured to enforce hash rockets style' do
         
     | 
| 
       68 
88 
     | 
    
         
             
                let(:cop_config) { { 'EnforcedStyle' => 'hash_rockets' } }
         
     | 
| 
       69 
89 
     | 
    
         | 
| 
       70 
90 
     | 
    
         
             
                it 'registers offence for Ruby 1.9 style' do
         
     | 
| 
         @@ -2,23 +2,58 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            describe Rubocop::Cop::Style::MethodCallParentheses do
         
     | 
| 
       6 
     | 
    
         
            -
              subject(:cop) { described_class.new }
         
     | 
| 
      
 5 
     | 
    
         
            +
            describe Rubocop::Cop::Style::MethodCallParentheses, :config do
         
     | 
| 
      
 6 
     | 
    
         
            +
              subject(:cop) { described_class.new(config) }
         
     | 
| 
      
 7 
     | 
    
         
            +
              let(:config) do
         
     | 
| 
      
 8 
     | 
    
         
            +
                Rubocop::Config.new('EmptyLiteral' => { 'Enabled' => true })
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
       7 
10 
     | 
    
         | 
| 
       8 
11 
     | 
    
         
             
              it 'registers an offence for parens in method call without args' do
         
     | 
| 
       9 
12 
     | 
    
         
             
                inspect_source(cop, ['top.test()'])
         
     | 
| 
      
 13 
     | 
    
         
            +
                expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              it 'accepts parentheses for methods starting with an upcase letter' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                inspect_source(cop, ['Test()'])
         
     | 
| 
      
 18 
     | 
    
         
            +
                expect(cop.offences).to be_empty
         
     | 
| 
       10 
19 
     | 
    
         
             
              end
         
     | 
| 
       11 
20 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              it ' 
     | 
| 
      
 21 
     | 
    
         
            +
              it 'accepts no parens in method call without args' do
         
     | 
| 
       13 
22 
     | 
    
         
             
                inspect_source(cop, ['top.test'])
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(cop.offences).to be_empty
         
     | 
| 
       14 
24 
     | 
    
         
             
              end
         
     | 
| 
       15 
25 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              it ' 
     | 
| 
      
 26 
     | 
    
         
            +
              it 'accepts parens in method call with args' do
         
     | 
| 
       17 
27 
     | 
    
         
             
                inspect_source(cop, ['top.test(a)'])
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(cop.offences).to be_empty
         
     | 
| 
       18 
29 
     | 
    
         
             
              end
         
     | 
| 
       19 
30 
     | 
    
         | 
| 
       20 
31 
     | 
    
         
             
              it 'auto-corrects by removing unneeded braces' do
         
     | 
| 
       21 
32 
     | 
    
         
             
                new_source = autocorrect_source(cop, 'test()')
         
     | 
| 
       22 
33 
     | 
    
         
             
                expect(new_source).to eq('test')
         
     | 
| 
       23 
34 
     | 
    
         
             
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              it 'does not auto-correct calls that will be changed to empty literals' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                original = ['Hash.new()',
         
     | 
| 
      
 38 
     | 
    
         
            +
                            'Array.new()',
         
     | 
| 
      
 39 
     | 
    
         
            +
                            'String.new()']
         
     | 
| 
      
 40 
     | 
    
         
            +
                new_source = autocorrect_source(cop, original)
         
     | 
| 
      
 41 
     | 
    
         
            +
                expect(new_source).to eq(original.join("\n"))
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              context 'when EmptyLiteral is disabled' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                let(:config) do
         
     | 
| 
      
 46 
     | 
    
         
            +
                  Rubocop::Config.new('EmptyLiteral' => { 'Enabled' => false })
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                it 'auto-corrects calls that could be empty literals' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  original = ['Hash.new()',
         
     | 
| 
      
 51 
     | 
    
         
            +
                              'Array.new()',
         
     | 
| 
      
 52 
     | 
    
         
            +
                              'String.new()']
         
     | 
| 
      
 53 
     | 
    
         
            +
                  new_source = autocorrect_source(cop, original)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  expect(new_source).to eq(['Hash.new',
         
     | 
| 
      
 55 
     | 
    
         
            +
                                            'Array.new',
         
     | 
| 
      
 56 
     | 
    
         
            +
                                            'String.new'].join("\n"))
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
       24 
59 
     | 
    
         
             
            end
         
     | 
| 
         @@ -27,6 +27,11 @@ describe Rubocop::Cop::Style::NumericLiterals, :config do 
     | 
|
| 
       27 
27 
     | 
    
         
             
                expect(cop.messages).to be_empty
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
              it 'does not count a leading minus sign as a digit' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                inspect_source(cop, ['a = -1230'])
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(cop.messages).to be_empty
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       30 
35 
     | 
    
         
             
              it 'accepts short numbers without underscore' do
         
     | 
| 
       31 
36 
     | 
    
         
             
                inspect_source(cop, ['a = 123',
         
     | 
| 
       32 
37 
     | 
    
         
             
                                     'b = 123.456'])
         
     | 
| 
         @@ -66,6 +66,17 @@ describe Rubocop::Cop::Style::SignalException, :config do 
     | 
|
| 
       66 
66 
     | 
    
         
             
                    .to eq(['Use `raise` instead of `fail` to rethrow exceptions.'])
         
     | 
| 
       67 
67 
     | 
    
         
             
                end
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
      
 69 
     | 
    
         
            +
                it 'registers only offence for one raise that should be fail' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  # This is a special case that has caused double reporting.
         
     | 
| 
      
 71 
     | 
    
         
            +
                  inspect_source(cop,
         
     | 
| 
      
 72 
     | 
    
         
            +
                                 ['map do',
         
     | 
| 
      
 73 
     | 
    
         
            +
                                  "  raise 'I'",
         
     | 
| 
      
 74 
     | 
    
         
            +
                                  'end.flatten.compact'])
         
     | 
| 
      
 75 
     | 
    
         
            +
                  expect(cop.offences.size).to eq(1)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  expect(cop.messages)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    .to eq(['Use `fail` instead of `raise` to signal exceptions.'])
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       69 
80 
     | 
    
         
             
                it 'accepts raise in def rescue section' do
         
     | 
| 
       70 
81 
     | 
    
         
             
                  inspect_source(cop,
         
     | 
| 
       71 
82 
     | 
    
         
             
                                 ['def test',
         
     | 
| 
         @@ -6,6 +6,8 @@ describe Rubocop::Cop::Style::SpaceAfterColon do 
     | 
|
| 
       6 
6 
     | 
    
         
             
              subject(:cop) { described_class.new }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              it 'registers an offence for colon without space after it' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                # TODO: There is double reporting of the last colon (also from
         
     | 
| 
      
 10 
     | 
    
         
            +
                # SpaceAroundOperators).
         
     | 
| 
       9 
11 
     | 
    
         
             
                inspect_source(cop, ['x = w ? {a:3}:4'])
         
     | 
| 
       10 
12 
     | 
    
         
             
                expect(cop.messages).to eq(
         
     | 
| 
       11 
13 
     | 
    
         
             
                  ['Space missing after colon.'] * 2)
         
     | 
| 
         @@ -20,4 +22,9 @@ describe Rubocop::Cop::Style::SpaceAfterColon do 
     | 
|
| 
       20 
22 
     | 
    
         
             
                inspect_source(cop, ["str << ':'"])
         
     | 
| 
       21 
23 
     | 
    
         
             
                expect(cop.messages).to be_empty
         
     | 
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it 'auto-corrects missing space' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                new_source = autocorrect_source(cop, 'x = w ? {a:3}:4')
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(new_source).to eq('x = w ? {a: 3}: 4')
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       23 
30 
     | 
    
         
             
            end
         
     | 
| 
         @@ -22,4 +22,9 @@ describe Rubocop::Cop::Style::SpaceAfterComma do 
     | 
|
| 
       22 
22 
     | 
    
         
             
                expect(cop.messages).to eq(
         
     | 
| 
       23 
23 
     | 
    
         
             
                  ['Space missing after comma.'])
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it 'auto-corrects missing space' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                new_source = autocorrect_source(cop, 'each { |s,t| a(1,formats[0,1])}')
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(new_source).to eq('each { |s, t| a(1, formats[0, 1])}')
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       25 
30 
     | 
    
         
             
            end
         
     | 
| 
         @@ -45,14 +45,6 @@ describe Rubocop::Cop::Style::SpaceAfterControlKeyword do 
     | 
|
| 
       45 
45 
     | 
    
         
             
                expect(cop.offences.map(&:line)).to eq([1, 2])
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
              it 'registers an offence for case and when' do
         
     | 
| 
       49 
     | 
    
         
            -
                inspect_source(cop,
         
     | 
| 
       50 
     | 
    
         
            -
                               ['case(a)',
         
     | 
| 
       51 
     | 
    
         
            -
                                'when(0) then 1',
         
     | 
| 
       52 
     | 
    
         
            -
                                'end'])
         
     | 
| 
       53 
     | 
    
         
            -
                expect(cop.offences.map(&:line)).to eq([1, 2])
         
     | 
| 
       54 
     | 
    
         
            -
              end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
48 
     | 
    
         
             
              it 'registers an offence for while and until' do
         
     | 
| 
       57 
49 
     | 
    
         
             
                inspect_source(cop,
         
     | 
| 
       58 
50 
     | 
    
         
             
                               ['while(a)',
         
     | 
| 
         @@ -60,4 +52,33 @@ describe Rubocop::Cop::Style::SpaceAfterControlKeyword do 
     | 
|
| 
       60 
52 
     | 
    
         
             
                                'end'])
         
     | 
| 
       61 
53 
     | 
    
         
             
                expect(cop.offences.map(&:line)).to eq([1, 2])
         
     | 
| 
       62 
54 
     | 
    
         
             
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              it 'auto-corrects missing space' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                new_source = autocorrect_source(cop, ['if(test) then result end',
         
     | 
| 
      
 58 
     | 
    
         
            +
                                                      'action unless(test)',
         
     | 
| 
      
 59 
     | 
    
         
            +
                                                      'if(a)',
         
     | 
| 
      
 60 
     | 
    
         
            +
                                                      'elsif(b)',
         
     | 
| 
      
 61 
     | 
    
         
            +
                                                      '  unless(c)',
         
     | 
| 
      
 62 
     | 
    
         
            +
                                                      '  end',
         
     | 
| 
      
 63 
     | 
    
         
            +
                                                      'end',
         
     | 
| 
      
 64 
     | 
    
         
            +
                                                      'case(a)',
         
     | 
| 
      
 65 
     | 
    
         
            +
                                                      'when(0) then 1',
         
     | 
| 
      
 66 
     | 
    
         
            +
                                                      'end',
         
     | 
| 
      
 67 
     | 
    
         
            +
                                                      'while(a)',
         
     | 
| 
      
 68 
     | 
    
         
            +
                                                      '  b until(c)',
         
     | 
| 
      
 69 
     | 
    
         
            +
                                                      'end'])
         
     | 
| 
      
 70 
     | 
    
         
            +
                expect(new_source).to eq(['if (test) then result end',
         
     | 
| 
      
 71 
     | 
    
         
            +
                                          'action unless (test)',
         
     | 
| 
      
 72 
     | 
    
         
            +
                                          'if (a)',
         
     | 
| 
      
 73 
     | 
    
         
            +
                                          'elsif (b)',
         
     | 
| 
      
 74 
     | 
    
         
            +
                                          '  unless (c)',
         
     | 
| 
      
 75 
     | 
    
         
            +
                                          '  end',
         
     | 
| 
      
 76 
     | 
    
         
            +
                                          'end',
         
     | 
| 
      
 77 
     | 
    
         
            +
                                          'case (a)',
         
     | 
| 
      
 78 
     | 
    
         
            +
                                          'when (0) then 1',
         
     | 
| 
      
 79 
     | 
    
         
            +
                                          'end',
         
     | 
| 
      
 80 
     | 
    
         
            +
                                          'while (a)',
         
     | 
| 
      
 81 
     | 
    
         
            +
                                          '  b until (c)',
         
     | 
| 
      
 82 
     | 
    
         
            +
                                          'end'].join("\n"))
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
       63 
84 
     | 
    
         
             
            end
         
     |