Skip to content

Conflicting lintr rules with alist and explicitly missing arguments #540

Closed

Description

@richfitz

This is pretty niche but shows up a conflicting pair of rules:

> lintr::lint("alist(a =)\n")
<text>:1:9: style: Put spaces around all infix operators.
alist(a =)
        ^~
> lintr::lint("alist(a = )\n")
<text>:1:10: style: Do not place spaces around code in parentheses or square brackets.
alist(a = )
         ^
> lintr::lint("alist(a =, b = NULL)\n")
<text>:1:9: style: Put spaces around all infix operators.
alist(a =, b = NULL)
        ^~
> lintr::lint("alist(a = , b = NULL)\n")
<text>:1:11: style: Commas should never have a space before.
alist(a = , b = NULL)

So for arguments that are "explicitly missing" there is no way of satisfying the default set of linter rules - we must and cannot have a space following the =, for cases that are within or at the end of an argument list.

The above behaviour is triggered in both the cran version (2.0.1) and current github (2.0.1.9000, eece3c1)

Activity

  1. AshesITR commented on Oct 23, 2020

    @AshesITR
    Collaborator

    This is related to #532

  2. richfitz commented on Oct 24, 2020

    @richfitz
    Author

    Ah, I'd looked though for issues about commas but managed to miss that!

  3. AshesITR commented on Oct 24, 2020

    @AshesITR
    Collaborator

    Your examples show that the commas_linter must also be fixed, not only the spaces_inside_linter so thanks 👍

  4. added
    bugan unexpected problem or unintended behavior
    on Dec 9, 2020
  5. MichaelChirico commented on Jan 31, 2021

    @MichaelChirico
    Collaborator

    Is this in fact the same as #532?

  6. AshesITR commented on Jan 31, 2021

    @AshesITR
    Collaborator

    #532 is a special case of this. Closing #532

  7. MichaelChirico commented on Oct 8, 2022

    @MichaelChirico
    Collaborator

    This is basically the same as #708 -- there, we now allow your second usage, but not your first:

    lintr::lint("switch(a = , b = 2)\n") # doesn't lint
    lintr::lint("switch(a =, b = 2)\n")
    # <text>:1:10: style: [infix_spaces_linter] Put spaces around all infix operators.
    # switch(a =, b = 2)
    #          ^

    This aligns with {styler}:

    styler::style_text("switch(a = , b = 2)\nswitch(a =, b = 2)\nalist(a = )\nalist(a =)")
    # switch(a = ,
    #   b = 2
    # )
    # switch(a = ,
    #   b = 2
    # )
    # alist(a = )
    # alist(a = )
  8. added
    false-positivecode that shouldn't lint, but does
    and removed
    bugan unexpected problem or unintended behavior
    on Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but does

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions