File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828* New cop ` LiteralInCondition ` tracks uses of literals in the conditions of ` if/while/until ` .
2929* New cop ` BeginBlock ` tracks uses of ` BEGIN ` blocks.
3030* New cop ` EndBlock ` tracks uses of ` END ` blocks.
31+ * New cop ` DotPosition ` tracks the dot position in multi-line method calls.
3132* Add support for auto-correction of some offences with ` -a ` /` --auto-correct ` .
3233
3334### Changes
Original file line number Diff line number Diff line change @@ -388,6 +388,10 @@ EndInMethod:
388388LiteralInCondition :
389389 Enabled : true
390390
391+ # Checks the position of the dot in multi-line method calls.
392+ DotPosition :
393+ Enabled : true
394+
391395# # Rails
392396
393397# Use sexy validations.
Original file line number Diff line number Diff line change 4949require 'rubocop/cop/style/constant_name'
5050require 'rubocop/cop/style/def_parentheses'
5151require 'rubocop/cop/style/documentation'
52+ require 'rubocop/cop/style/dot_position'
5253require 'rubocop/cop/style/empty_line_between_defs'
5354require 'rubocop/cop/style/empty_lines'
5455require 'rubocop/cop/style/empty_literal'
Original file line number Diff line number Diff line change 1+ # encoding: utf-8
2+
3+ module Rubocop
4+ module Cop
5+ module Style
6+ # This cop checks the . position in multi-line method calls.
7+ class DotPosition < Cop
8+ MSG = 'Place the . on the next line, together with the method name.'
9+
10+ def on_send ( node )
11+ return unless node . loc . dot
12+
13+ dot_line = node . loc . dot . line
14+ selector_line = node . loc . selector . line
15+
16+ if dot_line != selector_line
17+ add_offence ( :convention , node . loc . dot , MSG )
18+ end
19+
20+ super
21+ end
22+ end
23+ end
24+ end
25+ end
Original file line number Diff line number Diff line change @@ -47,8 +47,8 @@ module Rubocop
4747 Config . should_receive ( :configuration_file_for ) . once . with ( 'dir/' +
4848 'subdir' )
4949 # The stub returns the same config path for dir and dir/subdir.
50- Config . should_receive ( :configuration_from_file ) . once .
51- with ( 'dir/.rubocop.yml' )
50+ Config . should_receive ( :configuration_from_file ) . once
51+ . with ( 'dir/.rubocop.yml' )
5252
5353 ConfigStore . for ( 'dir/file2' )
5454 ConfigStore . for ( 'dir/file2' )
Original file line number Diff line number Diff line change 1+ # encoding: utf-8
2+
3+ require 'spec_helper'
4+
5+ module Rubocop
6+ module Cop
7+ module Style
8+ describe DotPosition do
9+ let ( :cop ) { DotPosition . new }
10+
11+ it 'registers an offence for trailing dot in multi-line method call' do
12+ inspect_source ( cop , [ 'something.' ,
13+ ' method_name' ] )
14+ expect ( cop . offences . size ) . to eq ( 1 )
15+ end
16+
17+ it 'accepts leading do in multi-line method call' do
18+ inspect_source ( cop , [ 'something' ,
19+ ' .method_name' ] )
20+ expect ( cop . offences ) . to be_empty
21+ end
22+
23+ it 'does not err on method call with no dots' do
24+ inspect_source ( cop , [ 'puts something' ] )
25+ expect ( cop . offences ) . to be_empty
26+ end
27+ end
28+ end
29+ end
30+ end
You can’t perform that action at this time.
0 commit comments