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

Formatting and linting are inconsistent in terms of spacing a^(b) #273

Open
bersbersbers opened this issue Jun 4, 2020 · 3 comments
Open

Comments

@bersbersbers
Copy link

Note that I am using https://github.com/REditorSupport/vscode-r-lsp, but I feel that particular implementation is not the core issue, so I'll try here first.

My problem is this line:

x^(y + z)

which I feel is nicely spaced. However, lintr says

Place a space before left parenthesis, except in a function call.

So when I do this,

x^ (y + z)

the lintr message disappears, but a subsequent "Format Document With ... - R LSP Client" in VS Code will remove the space and I end up with the first line and its lintr message. (The same is true for x ^ (y + z).)

I guess the problem is that lintr follows Hadley Wickham's style guide (source), which states

Place a space before left parentheses, except in a function call.

and

Place spaces around all infix operators

(emphasis mine) and has an y ^ x example in the code. So it's hard to argue that lintr is wrong.

At the same time, styler follows the tidyverse style guide (source), which does not require spaces around all parentheses and has an exception for certain infix operators, including ^:

There are a few exceptions, which should never be surrounded by spaces:

  • The operators with high precedence: ::, :::, $, @, [, [[, ^, unary -, unary +, and :.
@renkun-ken
Copy link
Member

This is more of inconsistencies between styler and lintr. We are using styler to do formatting and lintr for diagnostics.

@bersbersbers
Copy link
Author

I think you can see from my original question that you basically rephrased my analysis ;) The question is, what should be done about it?

I did my own research and found r-lib/lintr#302 - which is fixed but for some reason, the fix maybe has not made it into CRAN yet.

@bersbersbers
Copy link
Author

bersbersbers commented Oct 10, 2020

Here's another example:

a <- -(b)

Place a space before left parenthesis, except in a function call.

a <- - (b)

No lintr message, but "Format Document" reverts it back to the above code.

Since the lintr documentation has changed since I reported this (it now says

Most of the default linters are based on Hadley Wickham's The tidyverse style guide.

I will also report this in r-lib/lintr#508

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