{"record":{"id":"4d3ffc5fee68afc0","repo":"teamcapybara/capybara","slug":"unused-parameters-passed-to-self-class-name","errorCode":null,"errorMessage":"Unused parameters passed to #{self.class.name} : #{args}","messagePattern":"Unused parameters passed to #(.+?) : #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/capybara/queries/selector_query.rb","lineNumber":52,"sourceCode":"        end\n\n        super(@options)\n        self.session_options = session_options\n\n        @selector = Selector.new(\n          find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]),\n          config: {\n            enable_aria_label: enable_aria_label,\n            enable_aria_role: enable_aria_role,\n            test_id: test_id\n          },\n          format: selector_format\n        )\n\n        @locator = args.shift\n        @filter_block = filter_block\n\n        raise ArgumentError, \"Unused parameters passed to #{self.class.name} : #{args}\" unless args.empty?\n\n        @expression = selector.call(@locator, **@options)\n\n        warn_exact_usage\n\n        assert_valid_keys\n      end\n\n      def name; selector.name; end\n      def label; selector.label || selector.name; end\n\n      def description(only_applied = false) # rubocop:disable Style/OptionalBooleanParameter\n        desc = +''\n        show_for = show_for_stage(only_applied)\n\n        if show_for[:any]\n          desc << 'visible ' if visible == :visible\n          desc << 'non-visible ' if visible == :hidden","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/queries/selector_query.rb#L34-L70","documentation":"SelectorQuery#initialize consumes the optional selector name (symbol), then the locator, and raises ArgumentError 'Unused parameters passed ...' if any positional arguments remain. It fires at query construction, before searching, and is the library's guard against calling find/all with more positionals than the (selector, locator) shape allows — extra constraints must be keyword options, not extra strings.","triggerScenarios":"find('div', 'some text') where the second string should be text: 'some text'; find(:css, 'li', 'extra') after splatting a mis-built array (find(*['css', 'li', 'oops'])); passing two locators hoping for OR semantics; helper methods doing find(*args) where args contains leftovers; using :xpath with multiple path strings.","commonSituations":"Forgetting the keyword form for filters, dynamic locator arrays with unexpected extra entries, migrating from other libraries where extra positionals are allowed, Ruby 3 kwargs separation turning a trailing hash into a positional in some call shapes (then the hash itself is reported as unused).","solutions":["Convert extra positionals to keyword options: find('div', text: 'some text')","If building args dynamically, keep it to [kind, locator] and pass the rest as **options","Read the message: it prints the exact leftover args (#{args}) so you can see which call site produced them","For multiple alternatives use assert_any_of_selectors or a joined XPath/CSS, not extra parameters"],"exampleFix":"# before\nfind('div', 'Welcome')\n\n# after\nfind('div', text: 'Welcome')","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'pass filters as keywords' unless args.last.is_a?(Hash) || args.size <= 2\nfind(*args.take(2), **opts)","typeGuard":"def valid_find_args?(args)\n  args.size <= 2 && args.first.nil? || args.first.is_a?(Symbol) || args.size <= 2\nend","tryCatchPattern":"begin\n  find(*args)\nrescue ArgumentError => e\n  raise unless e.message.start_with?('Unused parameters')\n  find(args[0], args[1], **opts) # leftover positionals were meant as filters\nend","preventionTips":["Always pass filters as keywords: text:, visible:, id: — not extra positionals","Keep dynamic arg arrays to [kind, locator] and splat options separately","Read the echoed leftover args in the message to find the bad call site"],"tags":["capybara","argumenterror","arity","positional-args","selector"],"backgroundTag":"unexpected-positional-argument","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}