Skip to content

Commit 3b89b2e

Browse files
hoshinotsuyoshikoic
authored andcommitted
Make Rails/Date aware of safe navigation operator
1 parent 529b3a3 commit 3b89b2e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/rubocop/cop/rails/date.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def on_send(node)
7979
add_offense(node, location: :selector,
8080
message: format(MSG_SEND, method: node.method_name))
8181
end
82+
alias on_csend on_send
8283

8384
private
8485

spec/rubocop/cop/rails/date_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
expect(cop.offenses.size).to eq(1)
2929
end
3030

31+
context 'when using safe navigation operator', :ruby23 do
32+
it "registers an offense for ##{method}" do
33+
inspect_source("date&.#{method}")
34+
expect(cop.offenses.size).to eq(1)
35+
end
36+
end
37+
3138
it "accepts variable named #{method}" do
3239
expect_no_offenses("#{method} = 1")
3340
end

0 commit comments

Comments
 (0)