You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add newline after multiline function declaration #371
I remember Hadley suggested that an empty line after a long function header helps readability. I wouldn't formalize this as a rule yet, but I've seen this pattern a few times in dplyr.
For a propper implementation, we'd need #357 because we want to add a line break dependent on whether a token is multi-line, which we cannot do if the multi-line attribute is not up-to date. The multi-line attribute is not up-to-date because it is only updated after all line break rules were applied.
For a propper implementation, we'd need #357 because we want to add a line break dependent on whether a token is multi-line, which we cannot do if the multi-line attribute is not up-to date. The multi-line attribute is not up-to-date because it is only updated after all line break rules were applied.
Wrong. We need the exact line count, which we can compute ad-hoc within the transformer. It's as simple as in lorenzwalthert@d9f1b22. Performance implications probably small for non-package code because only taking effect for nests that are function declarations. Implementing it otherwise is most likely not much faster (i.e. doing it with a visitor for all top-level tokens) because most function declarations are not nested. (apparently there are more nested cases where this is insufficient, see #773). This rule needs to be at the end of the line-break transformers because it depends on them.
Activity
lorenzwalthert commentedon Mar 13, 2018
Is there a corresponding rule in the tidyverse style or do you plan to add one?
krlmlr commentedon Mar 13, 2018
I remember Hadley suggested that an empty line after a long function header helps readability. I wouldn't formalize this as a rule yet, but I've seen this pattern a few times in dplyr.
lorenzwalthert commentedon Mar 13, 2018
Ok. I think this is easy to implement. I just think for the sake of consistency, we should in general aim to keep the style guide in sync with styler.
lorenzwalthert commentedon Mar 13, 2018
For a propper implementation, we'd need #357 because we want to add a line break dependent on whether a token is multi-line, which we cannot do if the multi-line attribute is not up-to date. The multi-line attribute is not up-to-date because it is only updated after all line break rules were applied.
lorenzwalthert commentedon Mar 13, 2018
Blocked by #357.
lorenzwalthert commentedon Jan 26, 2019
Implemented in mlr branch: lorenzwalthert@2a3fbc6
lorenzwalthert commentedon Apr 17, 2019
The implementation in the mlr branch now depends on the number of lines in the body.
lorenzwalthert commentedon Apr 17, 2019
Wrong. We need the exact line count,
which we can compute ad-hoc within the transformer. It's as simple as in lorenzwalthert@d9f1b22. Performance implications probably small for non-package code because only taking effect for nests that are function declarations. Implementing it otherwise is most likely not much faster (i.e. doing it with a visitor for all top-level tokens) because most function declarations are not nested.(apparently there are more nested cases where this is insufficient, see #773). This rule needs to be at the end of the line-break transformers because it depends on them.maelle commentedon Oct 14, 2021
@krlmlr any specific examples of this pattern? 🙏
maelle commentedon Oct 14, 2021
For context I was looking into never removing the newline at the beginning of a function body if there was one, following a comment by @mpadge. 😁
krlmlr commentedon Oct 14, 2021
I have tweaked the "bad" example in the original post.
Keeping an extra newline, at least in non-strict mode, doesn't sound too bad as a starter.
maelle commentedon Oct 14, 2021
That's what I had guessed it should be. 😁