diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index acbcd95faa..098642cde0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-12-13 20:32:15 UTC using RuboCop version 1.69.2. +# on 2025-01-22 15:33:45 UTC using RuboCop version 1.70.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -22,27 +22,31 @@ InternalAffairs/NodeDestructuring: - 'lib/rubocop/cop/rails/relative_date_constant.rb' - 'lib/rubocop/cop/rails/time_zone.rb' +# Offense count: 84 +InternalAffairs/OnSendWithoutOnCSend: + Enabled: false + # Offense count: 10 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 163 + Max: 179 # Offense count: 41 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 14 -# Offense count: 178 +# Offense count: 183 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: Enabled: false -# Offense count: 1035 +# Offense count: 1091 # Configuration parameters: CountAsOne. RSpec/ExampleLength: Max: 108 -# Offense count: 688 +# Offense count: 733 RSpec/MultipleExpectations: Max: 5 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed798e23f..7ea73d5e87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,17 @@ ## master (unreleased) +## 2.29.1 (2025-01-25) + +### Bug fixes + +* [#1423](https://github.com/rubocop/rubocop-rails/issues/1423): Fix an error for `Rails/StrongParametersExpect` when using `permit` with no arguments. ([@koic][]) +* [#1417](https://github.com/rubocop/rubocop-rails/issues/1417): Fix an incorrect autocorrect for `Rails/StrongParametersExpect` when using a leading dot multiline call to `require` with `permit`. ([@koic][]) +* [#1356](https://github.com/rubocop/rubocop-rails/issues/1356): Enhance `Rails/DuplicateAssociation` to handle alias. ([@ydakuka][]) +* [#1389](https://github.com/rubocop/rubocop-rails/issues/1389): Handle `TypeError` caused by passing array literals as arguments to `File` methods in `Rails/FilePath` cop. ([@ydakuka][]) +* [#1389](https://github.com/rubocop/rubocop-rails/issues/1389): Handle `TypeError` caused by passing array literals as arguments to `File` methods in `Rails/RootPathnameMethods` cop. ([@ydakuka][]) +* [#1228](https://github.com/rubocop/rubocop-rails/issues/1228): Enhance `Rails/SaveBang` to properly handle instance variables. ([@ydakuka][]) + ## 2.29.0 (2025-01-18) ### New features @@ -1207,3 +1218,4 @@ [@viralpraxis]: https://github.com/viralpraxis [@mterada1228]: https://github.com/mterada1228 [@franzliedke]: https://github.com/franzliedke +[@ydakuka]: https://github.com/ydakuka diff --git a/lib/rubocop/cop/rails/duplicate_association.rb b/lib/rubocop/cop/rails/duplicate_association.rb index 0373fa4530..19b5d567fb 100644 --- a/lib/rubocop/cop/rails/duplicate_association.rb +++ b/lib/rubocop/cop/rails/duplicate_association.rb @@ -63,11 +63,15 @@ def on_class(class_node) private def register_offense(name, nodes, message_template) - nodes.each do |node| - add_offense(node, message: format(message_template, name: name)) do |corrector| - next if same_line?(nodes.last, node) + last_node = nodes.last - corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true)) + nodes.each_with_index do |node, index| + add_offense(node, message: format(message_template, name: name)) do |corrector| + if index.zero? + corrector.replace(node, last_node.source) + else + corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true)) + end end end end diff --git a/lib/rubocop/cop/rails/file_path.rb b/lib/rubocop/cop/rails/file_path.rb index 9c19c5e525..375f43e7b0 100644 --- a/lib/rubocop/cop/rails/file_path.rb +++ b/lib/rubocop/cop/rails/file_path.rb @@ -173,7 +173,17 @@ def autocorrect_extension_after_rails_root_join_in_dstr(corrector, node, rails_r end def autocorrect_file_join(corrector, node) + replace_receiver_with_rails_root(corrector, node) + remove_first_argument_with_comma(corrector, node) + process_arguments(corrector, node.arguments) + append_to_string_conversion(corrector, node) + end + + def replace_receiver_with_rails_root(corrector, node) corrector.replace(node.receiver, 'Rails.root') + end + + def remove_first_argument_with_comma(corrector, node) corrector.remove( range_with_surrounding_space( range_with_surrounding_comma( @@ -183,9 +193,19 @@ def autocorrect_file_join(corrector, node) side: :right ) ) - node.arguments.filter(&:str_type?).each do |argument| - corrector.replace(argument, argument.value.delete_prefix('/').inspect) + end + + def process_arguments(corrector, arguments) + arguments.each do |argument| + if argument.str_type? + corrector.replace(argument, argument.value.delete_prefix('/').inspect) + elsif argument.array_type? + corrector.replace(argument, "*#{argument.source}") + end end + end + + def append_to_string_conversion(corrector, node) corrector.insert_after(node, '.to_s') end diff --git a/lib/rubocop/cop/rails/root_pathname_methods.rb b/lib/rubocop/cop/rails/root_pathname_methods.rb index 5898d0b421..1678d51c47 100644 --- a/lib/rubocop/cop/rails/root_pathname_methods.rb +++ b/lib/rubocop/cop/rails/root_pathname_methods.rb @@ -237,7 +237,12 @@ def build_path_replacement(path, method, args) end replacement = "#{path_replacement}.#{method}" - replacement += "(#{args.map(&:source).join(', ')})" unless args.empty? + + if args.any? + formatted_args = args.map { |arg| arg.array_type? ? "*#{arg.source}" : arg.source } + replacement += "(#{formatted_args.join(', ')})" + end + replacement end diff --git a/lib/rubocop/cop/rails/save_bang.rb b/lib/rubocop/cop/rails/save_bang.rb index 2d3ab932f1..fae2e90bc3 100644 --- a/lib/rubocop/cop/rails/save_bang.rb +++ b/lib/rubocop/cop/rails/save_bang.rb @@ -328,8 +328,9 @@ def explicit_return?(node) end def return_value_assigned?(node) - assignment = assignable_node(node).parent - assignment&.lvasgn_type? + return false unless (assignment = assignable_node(node).parent) + + assignment.assignment? end def persist_method?(node, methods = RESTRICT_ON_SEND) diff --git a/lib/rubocop/cop/rails/strong_parameters_expect.rb b/lib/rubocop/cop/rails/strong_parameters_expect.rb index 842523f629..921c13940c 100644 --- a/lib/rubocop/cop/rails/strong_parameters_expect.rb +++ b/lib/rubocop/cop/rails/strong_parameters_expect.rb @@ -32,7 +32,7 @@ class StrongParametersExpect < Base def_node_matcher :params_require_permit, <<~PATTERN $(call $(call - (send nil? :params) :require _) :permit ...) + (send nil? :params) :require _) :permit _+) PATTERN def_node_matcher :params_permit_require, <<~PATTERN @@ -59,7 +59,7 @@ def on_send(node) end add_offense(range, message: format(MSG, prefer: prefer)) do |corrector| - corrector.remove(require_method.loc.dot.join(require_method.source_range.end)) + corrector.remove(require_method.receiver.source_range.end.join(require_method.source_range.end)) corrector.replace(permit_method.loc.selector, 'expect') if replace_argument corrector.insert_before(permit_method.first_argument, "#{require_key(require_method)}[") diff --git a/lib/rubocop/rails/version.rb b/lib/rubocop/rails/version.rb index 16caa42d21..981881947b 100644 --- a/lib/rubocop/rails/version.rb +++ b/lib/rubocop/rails/version.rb @@ -4,7 +4,7 @@ module RuboCop module Rails # This module holds the RuboCop Rails version information. module Version - STRING = '2.29.0' + STRING = '2.29.1' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v2.29.1.md b/relnotes/v2.29.1.md new file mode 100644 index 0000000000..bc4a60efd1 --- /dev/null +++ b/relnotes/v2.29.1.md @@ -0,0 +1,11 @@ +### Bug fixes + +* [#1423](https://github.com/rubocop/rubocop-rails/issues/1423): Fix an error for `Rails/StrongParametersExpect` when using `permit` with no arguments. ([@koic][]) +* [#1417](https://github.com/rubocop/rubocop-rails/issues/1417): Fix an incorrect autocorrect for `Rails/StrongParametersExpect` when using a leading dot multiline call to `require` with `permit`. ([@koic][]) +* [#1356](https://github.com/rubocop/rubocop-rails/issues/1356): Enhance `Rails/DuplicateAssociation` to handle alias. ([@ydakuka][]) +* [#1389](https://github.com/rubocop/rubocop-rails/issues/1389): Handle `TypeError` caused by passing array literals as arguments to `File` methods in `Rails/FilePath` cop. ([@ydakuka][]) +* [#1389](https://github.com/rubocop/rubocop-rails/issues/1389): Handle `TypeError` caused by passing array literals as arguments to `File` methods in `Rails/RootPathnameMethods` cop. ([@ydakuka][]) +* [#1228](https://github.com/rubocop/rubocop-rails/issues/1228): Enhance `Rails/SaveBang` to properly handle instance variables. ([@ydakuka][]) + +[@koic]: https://github.com/koic +[@ydakuka]: https://github.com/ydakuka diff --git a/spec/rubocop/cop/rails/duplicate_association_spec.rb b/spec/rubocop/cop/rails/duplicate_association_spec.rb index 3fbe151ce2..72b6315c89 100644 --- a/spec/rubocop/cop/rails/duplicate_association_spec.rb +++ b/spec/rubocop/cop/rails/duplicate_association_spec.rb @@ -16,8 +16,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - belongs_to :bar belongs_to :foo + belongs_to :bar belongs_to :blah end RUBY @@ -37,8 +37,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - belongs_to :bar belongs_to :foo, -> { active } + belongs_to :bar belongs_to :blah end RUBY @@ -60,8 +60,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_many :bars has_many :foos + has_many :bars has_many :blahs end RUBY @@ -81,12 +81,31 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_many :bars has_many 'foos', -> { active } + has_many :bars has_many :blahs end RUBY end + + it 'registers an offense with alias' do + expect_offense(<<~RUBY) + class Post < ApplicationRecord + belongs_to :foos, -> { active } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Association `foos` is defined multiple times. Don't repeat associations. + alias bars foos + belongs_to :foos + ^^^^^^^^^^^^^^^^ Association `foos` is defined multiple times. Don't repeat associations. + end + RUBY + + expect_correction(<<~RUBY) + class Post < ApplicationRecord + belongs_to :foos + alias bars foos + end + RUBY + end end describe 'has_one' do @@ -104,8 +123,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_one :bar has_one :foo + has_one :bar has_one :blah end RUBY @@ -125,8 +144,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_one :bar has_one :foo, -> { active } + has_one :bar has_one :blah end RUBY @@ -148,8 +167,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_and_belongs_to_many :bars has_and_belongs_to_many :foos + has_and_belongs_to_many :bars has_and_belongs_to_many :blahs end RUBY @@ -169,8 +188,8 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_and_belongs_to_many :bars has_and_belongs_to_many :foos, -> { active } + has_and_belongs_to_many :bars has_and_belongs_to_many :blahs end RUBY @@ -200,12 +219,12 @@ class Post < ApplicationRecord expect_correction(<<~RUBY) class Post < ApplicationRecord - has_and_belongs_to_many :bars has_and_belongs_to_many :foos, -> { active } + has_and_belongs_to_many :bars has_and_belongs_to_many :blahs - has_one :top_comment, -> { order(likes: :desc) }, class_name: 'Comment' belongs_to :author + has_one :top_comment, -> { order(likes: :desc) }, class_name: 'Comment' end RUBY end diff --git a/spec/rubocop/cop/rails/file_path_spec.rb b/spec/rubocop/cop/rails/file_path_spec.rb index 04d4cfd4e9..6bcdd88dea 100644 --- a/spec/rubocop/cop/rails/file_path_spec.rb +++ b/spec/rubocop/cop/rails/file_path_spec.rb @@ -244,6 +244,84 @@ RUBY end end + + context 'when using only [] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, ['app', 'models']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*['app', 'models']).to_s + RUBY + end + end + + context 'with a leading string and an array using [] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", ["models", "goober"]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *["models", "goober"]).to_s + RUBY + end + end + + context 'with an array using [] syntax and a trailing string' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, ["app", "models"], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*["app", "models"], "goober").to_s + RUBY + end + end + + context 'when using only %w[] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models]).to_s + RUBY + end + end + + context 'with a leading string and an array using %w[] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", %w[models goober]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *%w[models goober]).to_s + RUBY + end + end + + context 'with an array using %w[] syntax and a trailing string' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models], "goober").to_s + RUBY + end + end end context 'when EnforcedStyle is `arguments`' do @@ -436,5 +514,83 @@ RUBY end end + + context 'when using only [] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, ['app', 'models']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*['app', 'models']).to_s + RUBY + end + end + + context 'with a leading string and an array using [] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", ["models", "goober"]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *["models", "goober"]).to_s + RUBY + end + end + + context 'with an array using [] syntax and a trailing string' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, ["app", "models"], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*["app", "models"], "goober").to_s + RUBY + end + end + + context 'when using only %w[] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models]).to_s + RUBY + end + end + + context 'with a leading string and an array using %w[] syntax' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", %w[models goober]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *%w[models goober]).to_s + RUBY + end + end + + context 'with an array using %w[] syntax and a trailing string' do + it 'registers an offense once' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models], "goober").to_s + RUBY + end + end end end diff --git a/spec/rubocop/cop/rails/root_pathname_methods_spec.rb b/spec/rubocop/cop/rails/root_pathname_methods_spec.rb index 82f00ea5da..77cb1b1218 100644 --- a/spec/rubocop/cop/rails/root_pathname_methods_spec.rb +++ b/spec/rubocop/cop/rails/root_pathname_methods_spec.rb @@ -210,4 +210,70 @@ file = Rails.root.join('docs', 'invoice.pdf').open RUBY end + + it 'registers an offense when using only [] syntax' do + expect_offense(<<~RUBY) + File.join(Rails.root, ['app', 'models']) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join(*['app', 'models'])`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*['app', 'models']) + RUBY + end + + it 'registers an offense when using a leading string and an array using [] syntax' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", ["models", "goober"]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join("app", *["models", "goober"])`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *["models", "goober"]) + RUBY + end + + it 'registers an offense when using an array using [] syntax and a trailing string' do + expect_offense(<<~RUBY) + File.join(Rails.root, ["app", "models"], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join(*["app", "models"], "goober")`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*["app", "models"], "goober") + RUBY + end + + it 'registers an offense when using only %w[] syntax' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join(*%w[app models])`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models]) + RUBY + end + + it 'registers an offense when using a leading string and an array using %w[] syntax' do + expect_offense(<<~RUBY) + File.join(Rails.root, "app", %w[models goober]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join("app", *%w[models goober])`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join("app", *%w[models goober]) + RUBY + end + + it 'registers an offense when using an array using %w[] syntax and a trailing string' do + expect_offense(<<~RUBY) + File.join(Rails.root, %w[app models], "goober") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join(*%w[app models], "goober")`. + RUBY + + expect_correction(<<~RUBY) + Rails.root.join(*%w[app models], "goober") + RUBY + end end diff --git a/spec/rubocop/cop/rails/save_bang_spec.rb b/spec/rubocop/cop/rails/save_bang_spec.rb index 383ba34570..dfa9ca071f 100644 --- a/spec/rubocop/cop/rails/save_bang_spec.rb +++ b/spec/rubocop/cop/rails/save_bang_spec.rb @@ -668,6 +668,56 @@ def whatever RUBY end + it "does not register an offense when using persisted? after #{method} to a local variable" do + expect_no_offenses(<<~RUBY) + user = User.#{method} + + if user.persisted? + foo + end + RUBY + end + + it "does not register an offense when using persisted? after #{method} to an instance variable" do + expect_no_offenses(<<~RUBY) + @user = User.#{method} + + if @user.persisted? + foo + end + RUBY + end + + it "does not register an offense when using persisted? after #{method} to a global variable" do + expect_no_offenses(<<~RUBY) + $user = User.#{method} + + if $user.persisted? + foo + end + RUBY + end + + it "does not register an offense when using persisted? after #{method} for multiple assignments" do + expect_no_offenses(<<~RUBY) + a, b = User.#{method}, User.new + + if a.persisted? + foo + end + RUBY + end + + it "does not register an offense when using persisted? after #{method} for conditional assignments" do + expect_no_offenses(<<~RUBY) + user ||= User.#{method} + + if user.persisted? + foo + end + RUBY + end + it "when using #{method} with `||`" do expect_no_offenses(<<~RUBY) def find_or_create(**opts) diff --git a/spec/rubocop/cop/rails/strong_parameters_expect_spec.rb b/spec/rubocop/cop/rails/strong_parameters_expect_spec.rb index 036822f9ea..0a0bc30d24 100644 --- a/spec/rubocop/cop/rails/strong_parameters_expect_spec.rb +++ b/spec/rubocop/cop/rails/strong_parameters_expect_spec.rb @@ -98,6 +98,20 @@ RUBY end + it 'registers an offense when using a leading dot multiline call to `params.require(:user).permit(:name, :age)`' do + expect_offense(<<~RUBY) + params + .require(:user) + ^^^^^^^^^^^^^^ Use `expect(user: [:name, :age])` instead. + .permit(:name, :age) + RUBY + + expect_correction(<<~RUBY) + params + .expect(user: [:name, :age]) + RUBY + end + it 'does not register an offense when using `params.expect(user: [:name, :age])`' do expect_no_offenses(<<~RUBY) params.expect(user: [:name, :age]) @@ -122,6 +136,12 @@ RUBY end + it 'does not register an offense when using `params.require(:target).permit`' do + expect_no_offenses(<<~RUBY) + params.require(:target).permit + RUBY + end + it 'does not register an offense when using `params[:name]`' do expect_no_offenses(<<~RUBY) params[:name]
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: