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

Rails/StrongParametersExpect correction is a syntax error when original is across multiple lines #1417

Closed
JasonBarnabe opened this issue Jan 18, 2025 · 0 comments · Fixed by #1420
Labels
bug Something isn't working

Comments

@JasonBarnabe
Copy link

Before running the cop:

  def discussion_params
    attrs = [:rating, :title, :discussion_category_id, :report_id, { comments_attributes: [:text, :text_markup, { attachments: [] }] }]
    attrs += [:report_id] if current_user&.moderator?
    params
      .require(:discussion)
      .permit(attrs)
  end

Cop output:

app/controllers/discussions_controller.rb:313:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
app/controllers/discussions_controller.rb:313:8: C: [Corrected] Rails/StrongParametersExpect: Use expect(discussion: [attrs]) instead.
      .require(:discussion) ...
       ^^^^^^^^^^^^^^^^^^^^
app/controllers/discussions_controller.rb:314:7: F: Lint/Syntax: unexpected token tDOT
(Using Ruby 3.4 parser; configure using TargetRubyVersion parameter, under AllCops)
      .expect(discussion: [attrs])
      ^

After the cop:

  def discussion_params
    attrs = [:rating, :title, :discussion_category_id, :report_id, { comments_attributes: [:text, :text_markup, { attachments: [] }] }]
    attrs += [:report_id] if current_user&.moderator?
    params

      .expect(discussion: [attrs])
  end

RuboCop version

1.70.0 (using Parser 3.3.7.0, rubocop-ast 1.37.0, analyzing as Ruby 3.4, running on ruby 3.4.1) +server [x86_64-linux]
  - rubocop-capybara 2.21.0
  - rubocop-minitest 0.36.0
  - rubocop-performance 1.23.1
  - rubocop-rails 2.29.0
@JasonBarnabe JasonBarnabe changed the title Rails/StrongParametersExpect breaks code when original is across multiple lines Rails/StrongParametersExpect correction is a syntax error when original is across multiple lines Jan 18, 2025
@koic koic added the bug Something isn't working label Jan 18, 2025
koic added a commit to koic/rubocop-rails that referenced this issue Jan 18, 2025

Verified

This commit was signed with the committer’s verified signature.
drazisil-codecov Joe Becher
…metersExpect`

Fixes rubocop#1417.

This PR fixes an incorrect autocorrect for `Rails/StrongParametersExpect`
when using a leading dot multiline call to `params.require(:user).permit(:name, :age)`.
koic added a commit to koic/rubocop-rails that referenced this issue Jan 18, 2025
koic added a commit to koic/rubocop-rails that referenced this issue Jan 18, 2025
@koic koic closed this as completed in efc6dc2 Jan 19, 2025
koic added a commit that referenced this issue Jan 19, 2025
…ails_strong_parameters_expect

[Fix #1417] Fix an incorrect autocorrect for `Rails/StrongParametersExpect`
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