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

Set off each comment with one blank line? #1076

Open
IndrajeetPatil opened this issue Nov 30, 2022 · 4 comments
Open

Set off each comment with one blank line? #1076

IndrajeetPatil opened this issue Nov 30, 2022 · 4 comments

Comments

@IndrajeetPatil
Copy link
Collaborator

Preamble

An effective way to get an overview of the code is to read the comments without reading the code. Setting comments off with a blank line helps distinguish code from comments and makes it easy for the reader to scan the code or the comment.

Actual

This is a minimal reprex to illustrate the issue, but you can scale this to more complex comments and highly involved code block below each comment.

styler::style_text("# comment-1
if (TRUE) {
  # comment-2
  x <- 1
  # comment-3
  a <- 3
}
# comment-4
x + 1")
#> # comment-1
#> if (TRUE) {
#>   # comment-2
#>   x <- 1
#>   # comment-3
#>   a <- 3
#> }
#> # comment-4
#> x + 1

Created on 2022-11-30 with reprex v2.0.2

Expected

Note that this doesn't apply to the comments at the start of the scope.

#> # comment-1
#> if (TRUE) {
#>   # comment-2
#>   x <- 1
+ #>               
#>   # comment-3
#>   a <- 3
#> }
+ #>               
#> # comment-4
#> x + 1
@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Nov 30, 2022

I see the use case, but most people won't want this always. Note that {styler} preserves line breaks around comments in certain situations (search the issues for more context), e.g. in your case,

styler::style_text("# comment-1
if (TRUE) {
  
  # comment-2
  x <- 1
  
  # comment-3
  a <- 3
}

# comment-4
x + 1")
#> # comment-1
#> if (TRUE) {
#>   # comment-2
#>   x <- 1
#> 
#>   # comment-3
#>   a <- 3
#> }
#> 
#> # comment-4
#> x + 1

Created on 2022-11-30 with reprex v2.0.2

Hence, I consider such an invasive formatting out of scope for {styler}. Maybe also check out https://github.com/lionel-/codegrip?

@IndrajeetPatil
Copy link
Collaborator Author

I see the use case, but most people won't want this always.

Maybe this can be an optional argument? E.g. offset_comment_with_one_blank_line?

start_comments_with_one_space = FALSE,

Note that {styler} preserves line breaks around commas in certain situations

I didn't get the connection between this comment and the reprex in your comment.

Hence, I consider such an invasive formatting out of scope for {styler}. Maybe also check out https://github.com/lionel-/codegrip?

Looking at the roadmap section of codegrip, I doubt it's in the scope of that package either.

@lorenzwalthert
Copy link
Collaborator

I didn't get the connection between this comment and the reprex in your comment.

Fixed, I meant comments, not commas :D

@lorenzwalthert
Copy link
Collaborator

I am not gonna implement this, but if you want, you can send a PR. I think the default should be the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants