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

object_name_linter catches nonalphanumeric operator names #615

Closed
MichaelChirico opened this issue Nov 28, 2020 · 4 comments · Fixed by #621
Closed

object_name_linter catches nonalphanumeric operator names #615

MichaelChirico opened this issue Nov 28, 2020 · 4 comments · Fixed by #621

Comments

@MichaelChirico
Copy link
Collaborator

 writeLines("
`%++%` <- function(x, y) x+y
", tmp <- tempfile())

lintr::lint(tmp, lintr::object_name_linter())
# /tmp/Rtmp0dwFUb/file7f2d15642314:2:1: style: Variable and function name style should be snake_case.
# `%++%` <- function(x, y) x+y
# ^~~~~~

Seems like that's not possible to put into snake case...

@AshesITR
Copy link
Collaborator

Such functions should be rare enought to warrant an occasional # nolint imo.
Note that `%my_op%` <- function(x, y) x + y lints fine

@MichaelChirico
Copy link
Collaborator Author

In this case, I am staring at what lintr is telling me and thinking "How would I even do that?", so if there's an easy fix, I think we should do it and avoid needless confusion. I think (somewhat speculative) it's more uncommon for operators to have alphanumerics than not, so conditional on writing operators, it seems this warning is likely to arise.

@AshesITR
Copy link
Collaborator

AshesITR commented Nov 28, 2020

Yeah, I see that happening.
What should happen for e.g. %T>% from {magrittr}?
Maybe a new option check_operators = TRUE could be added and that would allow you to do whatever with objects that are named %something%?

I mean you'd certainly want a lint if a variable named `++` were used, no?

@MichaelChirico
Copy link
Collaborator Author

Not a perfect search but a grep-based approach on my CRAN mirror turned up these operators:

with alphanumeric

in, nin, chnin, btwn, nin, !in, and, nin, alike, chin, iscall, between, inrange, like, ilike, flike, in, ni, dominates, isDominatedBy, into, nest, add_rows, merge, calc, calculate, row_in, col_in, thru, a, r, to, to_list, if_na, na_if, then, matrixPower, matBinPower, bq, bt, bq, !in, n, n, L*, nin, check&&, check||, c=, union=, or, except, between, dof, dofc, like, nlike, ilike, nilike, regexp, iregexp, over, like, rlike, regexp

without alphanumeric

??, *, :::, ||, $, @, , >>, >>, <<, <>>, <<<, >|, |<, +=, -=, <=, ^, &, ||, ||, ||, +, <=>, <!=>, ||, :::, :::, *, =, ==, *, {*}, *[, ]*, *{, }*, *|, |*

My gut is to treat %++% differently than ++ (by default, don't really see the need for an option). A matter of how hard it is to implement.

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

Successfully merging a pull request may close this issue.

2 participants