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

Fix false positives for Lint/LiteralAssignmentInCondition #12539

Commits on Dec 14, 2023

  1. Fix false positives for Lint/LiteralAssignmentInCondition

    This PR fixes the following false positive for `Lint/LiteralAssignmentInCondition`
    when a collection lireal contains non-literal elements:
    
    ```console
    $ echo 'x = 1; if test = [42, x]; end' | be rubocop --stdin test.rb --only Lint/LiteralAssignmentInCondition
    Inspecting 1 file
    W
    
    Offenses:
    
    test.rb:1:16: W: Lint/LiteralAssignmentInCondition: Don't use literal assignment = [42, x] in conditional,
    should be == or non-literal operand.
    x = 1; if test = [42, x]; end
                   ^^^^^^^^^
    
    1 file inspected, 1 offense detected
    ```
    
    In cases where non-literal elements are included in the collection, no warning will be displayed.
    
    ```console
    $ ruby -we 'x = 1; if test = [42, x]; end'
    ```
    koic committed Dec 14, 2023
    Configuration menu
    Copy the full SHA
    a8fdeb0 View commit details
    Browse the repository at this point in the history