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

False negative for Rails/FormattedS with safe navigation operator #719

Closed
mishina2228 opened this issue Jun 17, 2022 · 2 comments · Fixed by #720
Closed

False negative for Rails/FormattedS with safe navigation operator #719

mishina2228 opened this issue Jun 17, 2022 · 2 comments · Fixed by #720
Labels
bug Something isn't working

Comments

@mishina2228
Copy link

Expected behavior

I expect that Rails/FormattedS would be detected even if with safe navigation operator (&.), but it was not.

time&.to_formatted_s(:db)

(Without safe navigation operator, it is detected as expected.)

time.to_formatted_s(:db)
$ bundle exec rubocop sample.rb
Inspecting 1 file
C

Offenses:

sample.rb:3:6: C: [Correctable] Rails/ToFormattedS: Use to_fs instead.
time.to_formatted_s(:db)
     ^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

Actual behavior

No offenses detected.

$ bundle exec rubocop sample.rb --debug

For /tmp/rubocop: configuration from /tmp/rubocop/.rubocop.yml
configuration from /home/owner/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-rails-2.15.0/config/default.yml
configuration from /home/owner/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-rails-2.15.0/config/default.yml
Default configuration from /home/owner/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /home/owner/.cache/rubocop_cache/a8028efa7f49baac73c195c81afc43217df5d03d/6d7a3b621ca1730e04accd938619e4bdab66cfb1/50422055d11f0b6e1bbb1428bde968fcac54940d
Inspecting 1 file
Scanning /tmp/rubocop/sample.rb
Loading cache from /home/owner/.cache/rubocop_cache/a8028efa7f49baac73c195c81afc43217df5d03d/6d7a3b621ca1730e04accd938619e4bdab66cfb1/50422055d11f0b6e1bbb1428bde968fcac54940d
.

1 file inspected, no offenses detected
Finished in 0.3139251169995987 seconds

Steps to reproduce the problem

Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rails', '~> 7.0.3'
gem 'rubocop', '~> 1.30.1'
gem 'rubocop-rails', '~> 2.15.0'

.rubocop.yml

require:
  - rubocop-rails

AllCops:
  NewCops: enable

sample.rb

# frozen_string_literal: true

time&.to_formatted_s(:db)
$ bundle exec rubocop sample.rb

Inspecting 1 file
.

1 file inspected, no offenses detected

RuboCop version

$ bundle exec rubocop -V
1.30.1 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.1.0 x86_64-linux)
  - rubocop-rails 2.15.0
@koic koic added the bug Something isn't working label Jun 17, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Jun 17, 2022
Fixes rubocop#719.

This PR fixes a false negative for `Rails/FormattedS`
when using safe navigation operator.
@koic koic closed this as completed in #720 Jun 19, 2022
koic added a commit that referenced this issue Jun 19, 2022
…ormatted_s

[Fix #719] Fix a false negative for `Rails/FormattedS`
@mishina2228
Copy link
Author

Thanks!

@koic
Copy link
Member

koic commented Jun 20, 2022

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants