KEMBAR78
Lint/SplatKeywordArguments false positives? · Issue #5887 · rubocop/rubocop · GitHub
Skip to content

Lint/SplatKeywordArguments false positives? #5887

@jlfaber

Description

@jlfaber

The new Lint/SplatKeywordArguments cop, added in 0.56.0 (#5871), warns in several cases that are seemingly outside the intent of the new Ruby 2.6.0 warning message it claims to emulate.

The pertinent test code in ruby core is located here:

https://github.com/ruby/ruby/blob/f28d6165f6e39c7723ad88bdf87708ddff5a145f/test/ruby/test_keyword.rb#L506

The only cases in which the new ruby 2.6 warning is expected are when a double-splat arg is passed to a method that has one or more positional args, but no double-splatted keyword arg.

Line 524, which calls a method defined with a single positional arg, and line 527, which calls a method defined with a single positional arg with a default value, are examples where the warning is expected.

Lines 530 and 533 which call methods defined with double-splatted and single-splatted arguments, respectively, are not expected to generate the warning.

It's not entirely clear that rubocop is able to replicate this warning correctly since it would need to examine both the calling arguments (to look for double-splatted hashes) AND the definition of the method being called (to determine whether that hash would be assigned to a positional method argument).


Expected behavior

options = { opt1: 1, opt2: 2 }
def method1(kw_args); end

def method2(**kw_args); end

method1(**options) # This will warn in ruby 2.6 and currently warns in rubocop.

method2(**options) # This does not warn in ruby 2.6 and should not warn in rubocop.

Actual behavior

Call to method2 warns.

RuboCop version

$ rubocop -V
0.56.0 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-darwin17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions