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 positive for Rails/SkipsModelValidations on safe navigated String#insert #1278

Closed
brkn opened this issue May 14, 2024 · 0 comments · Fixed by #1279
Closed

False positive for Rails/SkipsModelValidations on safe navigated String#insert #1278

brkn opened this issue May 14, 2024 · 0 comments · Fixed by #1279

Comments

@brkn
Copy link

brkn commented May 14, 2024

Expected behavior

Rails/SkipsModelValidations to not match on String#insert when the object has safe navigation.

Actual behavior

Offenses:

title.rb:14:18: C: Rails/SkipsModelValidations: Avoid using insert because it skips validations.
@title_str&.insert(0, 'Prefixed')

Steps to reproduce the problem

class Title
  def initialize(title_str)
    @title_str = title_str
  end

  def prefixed_title
    @title_str.insert(0, 'Prefixed')
  end

  def safe_nav_gated_prefixed_title
    @title_str&.insert(0, 'Prefixed')
  end
end

RuboCop version

❯ be rubocop -V
1.63.5 (using Parser 3.3.1.0, rubocop-ast 1.31.3, running on ruby 3.2.2) [arm64-darwin22]
  - rubocop-factory_bot 2.25.1
  - rubocop-rails 2.24.1
  - rubocop-rspec 2.29.2
  - rubocop-rspec_rails 2.28.3
tldn0718 pushed a commit to tldn0718/rubocop-rails that referenced this issue May 16, 2024
tldn0718 pushed a commit to tldn0718/rubocop-rails that referenced this issue May 16, 2024
tldn0718 added a commit to tldn0718/rubocop-rails that referenced this issue May 16, 2024
koic added a commit that referenced this issue May 17, 2024
…-navigator

[Fix #1278] Fix a false positivie for Rails/SkipsModelValidations
fwolfst pushed a commit to fwolfst/rubocop-rails that referenced this issue Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant