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

Accept multiple styles in object_name_linter #341

Closed
infotroph opened this issue Aug 13, 2018 · 1 comment
Closed

Accept multiple styles in object_name_linter #341

infotroph opened this issue Aug 13, 2018 · 1 comment

Comments

@infotroph
Copy link
Contributor

infotroph commented Aug 13, 2018

> 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.

@jimhester
Copy link
Member

Sure, that seems reasonable, give it a shot!

jimhester pushed a commit that referenced this issue Aug 13, 2018
allow multiple naming styles if user really wants them (#341)

Fixes #341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants