-
Notifications
You must be signed in to change notification settings - Fork 186
Allow { }
or {}
in brace_linter independently of allow_single_line?
#1346
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
Comments
The empty expression should be We should allow |
I'm not sure. If the expression is just thrown away, |
Well, no disagreement on what we should do then :) |
A bit, but we can't really distinguish it from https://google.github.io/styleguide/cppguide.html#Loops_and_Switch_Statements
Is that an "if and only if"? FWIW, styler treats empty expressions differently: library(styler)
style_text("while (TRUE) { }")
# while (TRUE) { }
style_text("while (TRUE) {}")
# while (TRUE) {}
style_text("while (TRUE) { 1 }")
# while (TRUE) {
# 1
# } And personally I don't think splitting Filed tidyverse/style#191 for potential clarity from the Tidyverse guide. |
(Sorry I accidentally hit edit instead of comment. Is there a way to revert?)
Yes. My reasoning is if you don't want to while (function_that_stops_after_some_retries()) {
# comment why we allow an empty loop here
}
# The empty function actually returns NULL, so make it explicit:
function() NULL NB how control flow ( |
I don't really agree with the need force awkwardly shoehorning a comment in where there was none before... but on the other hand, I originally opened this issue because I thought it was a regression from 2.0.1 behavior that these lints were showing up. But all of the examples in the issue header generate at least So I am happy to just table this for now, until there's any feedback on the style guide stance for these, or user feedback after release. Perhaps @lorenzwalthert could chime in if there's some discussion that took place in |
Thanks @MichaelChirico. I think first and foremost, we should improve consistency between styler and lintr. This goes beyond just this particular question. I don’t personally use lintr so I don’t have a feeling for it but I got some feedback that people turn off either one with precommit to avoid headache. As for this specific case, I think there is some discussion in r-lib/styler#256, but it’s mainly my and Kirill’s opinion. If you have one expression in curly braces, I think you can omit the curly braces, no? call(x = {call2()}
# equivalent
call(x = call2()) That's why I'd only use them for multi line expressions like call(
x = {
a = 1 + 3
call2(a, 44)
}
) Let's wait for tidyverse/style#191, I don't have strong preferences. |
{ }
or {}
in brace_linter?{ }
or {}
in brace_linter independently of allow_single_line?
Essentially yes, and we have a linter in the works for this, but NB {testthat} enforces using test_that("a simple test", expect_true(TRUE))
# Test passed 🥳
# Warning message:
# The `code` argument to `test_that()` must be a braced expression to get accurate file-line information for failures. |
I think we should follow {styler} on this issue for now and lint neither |
I am seeing some code linted by
brace_linter
that wasn't throwing a lint in 2.0.1, e.g.Should we allow any/all of the above to be used without linting? If so, should we require a uniform # of spaces, e.g.
{}
is OK but{ }
is not?The text was updated successfully, but these errors were encountered: