Skip to content

Improve symbol detection #658

Closed
Closed

Description

@AshesITR

Currently, symbol-based linters use the parse data to determine of some token is a symbol or not.

When combined with the dollar operator, this can cause some confusing false positives, e.g. #582, #657.

It would be nice if we had a helper function that can find out whether a specific symbol is part of a dollar-operator (-chain) call and

  • skip such symbols in T_and_F_symbol_linter.
  • optionally skip such symbols in object_name_linter.

Note that for object_name_linter we could introduce some false negatives if variables are written to environments via a dollar-assignment instead of into lists or data.frames (where one might not consider them variable names)

These false negatives will be near impossible to discern from true negatives without running the code, since that would require type information on the dollar-accessed object.

Another, possibly even more useful, option for object_name_linter would be to allow separate linters.
A use-case would be to prescribe a different naming convention for data.frame column names than for variable names.
I use this in practice to easily distinguish which symbols in a dplyr call come from the data and which come from the surrounding environment.

What do you think about this? It could be implemented by adding a new argument to object_name_linters builder function, e.g.

object_name_linter(style = c("symbols", "snake_case"), dollar_style = style)

I'm also interested in suggestions for the possible argument name (colname_style might be misleading for cases where the user is not dealing with column names, I'm not very satisfied with dollar_style either, though).

Activity

  1. added
    feature
    on Dec 9, 2020
  2. AshesITR commented on Feb 18, 2021

    @AshesITR
    CollaboratorAuthor

    For the moment, #765 ignores the symbols used in dollar expressions.

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

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions