Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test multi-offenses for Layout/DotPosition cop #8794

Merged
merged 3 commits into from Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/rubocop/cop/layout/dot_position.rb
Expand Up @@ -29,17 +29,14 @@ class DotPosition < Base
def on_send(node)
return unless node.dot? || ampersand_dot?(node)

if proper_dot_position?(node)
correct_style_detected
else
return unless opposite_style_detected
return correct_style_detected if proper_dot_position?(node)

dot = node.loc.dot
message = message(dot)
opposite_style_detected
dot = node.loc.dot
message = message(dot)

add_offense(dot, message: message) do |corrector|
autocorrect(corrector, dot, node)
end
add_offense(dot, message: message) do |corrector|
autocorrect(corrector, dot, node)
end
end
alias on_csend on_send
Expand Down
22 changes: 22 additions & 0 deletions spec/rubocop/cop/layout/dot_position_spec.rb
Expand Up @@ -107,6 +107,28 @@
RUBY
end
end

context 'with multiple offenses' do
it 'registers all of them' do
expect_offense(<<~RUBY)
@objects = @objects.where(type: :a)

@objects = @objects.
^ Place the . on the next line, together with the method name.
with_relation.
^ Place the . on the next line, together with the method name.
paginate
RUBY

expect_correction(<<~RUBY)
@objects = @objects.where(type: :a)

@objects = @objects
.with_relation
.paginate
RUBY
end
end
end

context 'Trailing dots style' do
Expand Down