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

Feature requests for styling list of functions and arguments #870

Closed
IndrajeetPatil opened this issue Dec 10, 2021 · 2 comments
Closed

Feature requests for styling list of functions and arguments #870

IndrajeetPatil opened this issue Dec 10, 2021 · 2 comments

Comments

@IndrajeetPatil
Copy link
Collaborator

I see at least two ways that this can be improved:

  • Deliberately left empty lines between methods and arguments should not be removed. Although the current is minimal, a typical R6 class can be large and with many methods, and it is really helpful to have empty lines to demarcate different functions. Here is a good example.
  • Alignment is not detected in "other object properties" part of the class.
styler::style_text(
"
xData <- R6::R6Class(
  classname = 'xData',
  
  # public fields and methods ------------------------------------
  
  public = list(
    
    initialize = function() {
    },
    
    addx = function(x) {
      private$.x <- x
    },
    
    toDataFrame = function() {
      return(as.data.frame(private$.x))
    }
  ),
  
  # private fields and methods -----------------------------------
  
  private = list(
    .x = NULL,
    .y = NULL
  ),
  
  # other object properties --------------------------------------
  
  lock_objects = TRUE,
  lock_class   = FALSE,
  cloneable    = TRUE,
  portable     = TRUE
)
"
)
#> 
#> xData <- R6::R6Class(
#>   classname = "xData",
#> 
#>   # public fields and methods ------------------------------------
#> 
#>   public = list(
#>     initialize = function() {
#>     },
#>     addx = function(x) {
#>       private$.x <- x
#>     },
#>     toDataFrame = function() {
#>       return(as.data.frame(private$.x))
#>     }
#>   ),
#> 
#>   # private fields and methods -----------------------------------
#> 
#>   private = list(
#>     .x = NULL,
#>     .y = NULL
#>   ),
#> 
#>   # other object properties --------------------------------------
#> 
#>   lock_objects = TRUE,
#>   lock_class = FALSE,
#>   cloneable = TRUE,
#>   portable = TRUE
#> )

Created on 2021-12-10 by the reprex package (v2.0.1)

If you feel this is too specific of a context for {styler} to concern itself with, feel free to close this. I can always turn off styling, but that is not ideal since I might miss out on some other formatting issues.

@lorenzwalthert
Copy link
Collaborator

Thanks @IndrajeetPatil.

For your first point, please note from NEWS.md:

blank lines in function calls and headers are now removed, for the former only when there are no comments before or after the blank line (#629, #630, #635, #723).

I am not going to adjust this further.

Your second point is a duplicate for #757.

@IndrajeetPatil
Copy link
Collaborator Author

Thanks for the detailed response!

for the former only when there are no comments before

Unfortunately, not that common to have roxygen or regular comments before private member methods, but I think it will be overengineering to cover this one specific context.

Your second point is a duplicate for #757

Cool, closing in favor of #757

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