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

call. argument should not be added for custom conditions #2647

Open
Bisaloo opened this issue Aug 8, 2024 · 2 comments
Open

call. argument should not be added for custom conditions #2647

Bisaloo opened this issue Aug 8, 2024 · 2 comments

Comments

@Bisaloo
Copy link
Contributor

Bisaloo commented Aug 8, 2024

lintr::condition_call_linter() will recommend the addition of call. even for custom conditions crafted with errorCondition() / warningCondition() when these don't support call.=.

stop(errorCondition("stop right there!", class = "custom_error_condition"))
#> Error: stop right there!

lintr::lint(
  text = "stop(errorCondition('stop right there!', class = 'custom_error_condition'))",
  linters = lintr::condition_call_linter()
)
#> <text>:1:1: warning: [condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message.
#> stop(errorCondition('stop right there!', class = 'custom_error_condition'))
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

stop(errorCondition("stop right there!", class = "custom_error_condition"), call. = FALSE)
#> Warning in stop(errorCondition("stop right there!", class =
#> "custom_error_condition"), : additional arguments ignored in stop()
#> Error: stop right there!

Created on 2024-08-08 with reprex v2.1.1

@MichaelChirico
Copy link
Collaborator

I suspect

err_cond <- errorCondition(...)
stop(err_cond)

Is more common than calling both together. E.g. here's 139,000 matches of stop() to a non-literal string, but only about 100 where it's stop(errorCondition(.

https://github.com/search?q=language%3AR+%2Fstop%5B%28%5D%5Cs*%5B%5E+%5Cn%22%27%29%5D%2F&type=code

https://github.com/search?q=language%3AR+%2Fstop%5B%28%5D%5Cs*errorCondition%5B%28%5D%2F&type=code

Do you propose only excluding stop(errorCondition(, or should we never lint unless it's stop(<string literal>?

@Bisaloo
Copy link
Contributor Author

Bisaloo commented Aug 13, 2024

I would probably only exclude stop(errorCondition( (and the likes).

But I'm happy to align to the usual policy. Are we more leaning towards: "potentially get a lot more more missed lints" OR "potentially get some incorrect lints"?

Of the 139k matches, I suspect most of them should probably still include call.. But indeed, since we cannot statically determine it when a non-string literal is actually a string or not, some of them might also be linting incorrectly.

Another option could be to add an argument to let the user decide but it stills leaves the question of what the default should be.

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