Skip to content

Accept multiple styles in object_name_linter #341

Closed
@infotroph

Description

@infotroph
> library(lintr)
> txt <- c("var_one <- 1", "varTwo <- 2", "var.three <- 3")
> linter <- object_name_linter(c("snake_case", "lowerCamelCase"))

Current behavior:

> expect_lint(txt, list("should be snake_case", line_number=3), linter)
Error in vapply(x, `[[`, character(1), "message") : 
  values must be length 1,
 but FUN(X[[1]]) result is length 2
In addition: Warning messages:
1: In if (!matches_styles(name, style)) { :
  the condition has length > 1 and only the first element will be used
2: In if (!matches_styles(name, style)) { :
  the condition has length > 1 and only the first element will be used
3: In if (!matches_styles(name, style)) { :
  the condition has length > 1 and only the first element will be used

Proposed:

> expect_lint(txt, list("should be snake_case or lowerCamelCase", line_number=3), linter)
> 

I realize it's usually far better to pick one naming style and stick to it, but today I'm writing a package whose interface is dictated by two incompatible upstream APIs, so I'd like to allow "snake_case or dotted.case, but no others". Since users would need to explicitly opt into it by specifying multiple styles, I submit that this change doesn't pose too much of a moral hazard :)

Since matches_styles already returns a vector, I think this should be easy to implement and I can take a stab at it if y'all are OK with the concept.

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