REditorSupport / REditorSupport/languageserver
Formatting and linting are inconsistent in terms of spacing a^(b)
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 675
- Forks
- 118
- Avg merge
- 1d 37m
- Merged PRs (30d)
- 11
Description
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:.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the spacing difference for x^(y + z) and x^ (y + z) with lintr and the R language server's formatting behavior. Compare the relevant lintr and styler guidance, then determine the intended handling for the ^ operator and verify that linting and formatting agree on the resulting expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100