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

lintr does not like for loop bodies with a single line and no braces #2564

Open
rlaboiss opened this issue Apr 23, 2024 · 1 comment
Open
Labels
false-positive code that shouldn't lint, but does indentation 📏

Comments

@rlaboiss
Copy link

R accepts single-line bodies, without curly braces, for theif and the for statements.

Is there any reason why lintr accepts that for if but not for for? For instance:

> lint("if (TRUE)\n  x")
> lint("for (i in 0)\n  x")
<text>:2:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
@IndrajeetPatil
Copy link
Collaborator

There is definitely an inconsistency here. Thanks for pointing out.

cat("if (TRUE)\n  x")
#> if (TRUE)
#>   x
cat("for (i in 0)\n  x")
#> for (i in 0)
#>   x
cat("while (TRUE)\n  x")
#> while (TRUE)
#>   x

lintr::lint(text= "if (TRUE)\n  x", linters = lintr::indentation_linter())
lintr::lint(text= "for (i in 0)\n  x", linters = lintr::indentation_linter())
#> <text>:2:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
#>   x
#> ~^
lintr::lint(text= "while (TRUE)\n  x", linters = lintr::indentation_linter())

Created on 2024-04-23 with reprex v2.1.0

@IndrajeetPatil IndrajeetPatil added the false-positive code that shouldn't lint, but does label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does indentation 📏
Projects
None yet
Development

No branches or pull requests

3 participants