File tree Expand file tree Collapse file tree 6 files changed +63
-2
lines changed Expand file tree Collapse file tree 6 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 28
28
* New cop ` LiteralInCondition ` tracks uses of literals in the conditions of ` if/while/until ` .
29
29
* New cop ` BeginBlock ` tracks uses of ` BEGIN ` blocks.
30
30
* New cop ` EndBlock ` tracks uses of ` END ` blocks.
31
+ * New cop ` DotPosition ` tracks the dot position in multi-line method calls.
31
32
* Add support for auto-correction of some offences with ` -a ` /` --auto-correct ` .
32
33
33
34
### Changes
Original file line number Diff line number Diff line change @@ -388,6 +388,10 @@ EndInMethod:
388
388
LiteralInCondition :
389
389
Enabled : true
390
390
391
+ # Checks the position of the dot in multi-line method calls.
392
+ DotPosition :
393
+ Enabled : true
394
+
391
395
# # Rails
392
396
393
397
# Use sexy validations.
Original file line number Diff line number Diff line change 49
49
require 'rubocop/cop/style/constant_name'
50
50
require 'rubocop/cop/style/def_parentheses'
51
51
require 'rubocop/cop/style/documentation'
52
+ require 'rubocop/cop/style/dot_position'
52
53
require 'rubocop/cop/style/empty_line_between_defs'
53
54
require 'rubocop/cop/style/empty_lines'
54
55
require '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
47
47
Config . should_receive ( :configuration_file_for ) . once . with ( 'dir/' +
48
48
'subdir' )
49
49
# 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' )
52
52
53
53
ConfigStore . for ( 'dir/file2' )
54
54
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' ,
77DB
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