process-analytics / bpmn-visualization-R

A R package for visualizing process execution data on BPMN diagrams
https://process-analytics.github.io/bpmn-visualization-R/
Apache License 2.0
16 stars 4 forks source link

[INFRA] Add a R/JS formater #33

Open csouchet opened 3 years ago

csouchet commented 3 years ago

For now, we have to manage formatting manually. In RStudio, select the file content and then do Ctrl + Shift + A

See this article for general guidelines: https://blog.r-hub.io/2022/03/21/code-style/

For formatting rules

tooling candidates

IDE extension supporting autoformating

ColinFay commented 2 years ago

For {golem}, we have the following formatter grkstyle::grk_style_transformer()

I suggest all {golem} contributor to add the following code to their .Rprofile.

# If you work in RStudio
options(styler.addins_style_transformer = "grkstyle::grk_style_transformer()")

# If you work in VSCode
options(languageserver.formatting_style = function(options) {
  grkstyle::grk_style_transformer()
})

This is a piece of my personal .Rprofile that does format the code every time I open VScode :

if (file.exists("~/.Rprofile") { 
    source("~/.Rprofile") 
}

cli::cat_rule("[.Rprofile] Sourcing project-wide RProfile")

options(styler.addins_style_transformer = "grkstyle::grk_style_transformer()")

options(languageserver.formatting_style = function(options) {
  grkstyle::grk_style_transformer()
})

try(
  {
    grkstyle::grk_style_pkg(".")
  },
  silent = TRUE
)

options(styler.cache_root = "styler-perm")

Given that the package is in a folder, you can enforce the formatting with a project Rprofile

ColinFay commented 2 years ago

For the JS, I would suggest minifying too, for example with https://github.com/ColinFay/minifyr (requires nodejs)

tbouffard commented 2 years ago

@ColinFay thanks for the information, we will review quickly. I have seen some formatting changes in your PR #117 probably because of the configuration you use. We definitively need to setup shared linting settings for all contributors.

ColinFay commented 2 years ago

Ah, yes, I've turned on "Format on save" in VSCode :)