r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
724 stars 71 forks source link

Don't force line break for unnamed 1st argument #1190

Closed MichaelChirico closed 6 months ago

MichaelChirico commented 6 months ago

I think the style guide is being mis- or over-interpreted here:

https://style.tidyverse.org/syntax.html#long-lines

{styler} does the following:

styler::style_text('
c(a,
  b
)
')
# c(
#   a,
#   b
# )

styler::style_text('
c(a,
  b = c
)
')
# c(a,
#   b = c
# )

It looks like {styler} has decided that unnamed arguments are only allowed on the first line if arguments on subsequent lines are named, but I don't see that explicated anywhere in the text.

{styler} is meant to be minimally-invasive, i.e. only make changes that are explicitly required by the style guide, hence I think this is a bug.

lorenzwalthert commented 6 months ago

I think given the context from this issue, it should be come evident what the intention was and I think styler is compliant with that. If you don’t agree, please re-open.

MichaelChirico commented 6 months ago

Thanks... I do think it's not ideal to enforce rules that are not explicitly in the style guide, even if there's been some discussion that it should be in the guide, this is not the case until such rule is "in production" by merging to the style guide itself.

Anyway I followed up upstream: https://github.com/tidyverse/style/issues/212

lorenzwalthert commented 6 months ago

Thanks @MichaelChirico. I don’t see a lot of responsiveness at the moment upstream so I don’t know when this will be resolved there. But anyways it can’t hurt to file it. I don’t have bandwidth to work on styler much these days so sorry if I am a bit passive or defensive of the current behavior. In general, I think if there is no rule in the style guide and styler has a certain behavior, it is up to the person who wants to change that behavior to enforce a decision upstream. If upstream does not want to formalize a rule in the style guide or otherwise take a position, I think it’s up to the maintainers of styler to decide what they find appropriate. Just as you did now.