Giter VIP home page Giter VIP logo

Comments (12)

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024 1

Thanks! Looks good. Do you think we should merge the vignette on additional arguments with the available hooks vignette? I think there would be enough space here for one more column.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024 1

Actually I think we should not use a table anyways, I just unified two vignettes in #109.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Yes, I think we could do that. We should take as input:

  • the precommit config file.
  • some other file that describes all other attributes of the hooks, preferably in yaml too (I am not sure if pre-commit allows us to add new fields to the config file).

We could also try to add the information to the .pre-commit-hooks.yaml file. If it does not produce errors at commit time or while other hooks are running, I think it might even preferred.

I am not sure if we prefer tables. We can also use the R package https://github.com/kiernann/gluedown to generate markdown in R chunks in the vignette and set output = "asis" (if I remember the Rmarkdown options correctly).

I am open to PRs here.

The same is probably also possible with the argument vignette.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

If all current formatting with links etc. is possible in tabular format, you are probably right that this would be better than the current bullets.

from precommit.

maelle avatar maelle commented on July 27, 2024

Here's what I have at the moment.

info <- yaml::read_yaml("/home/maelle/Documents/ropensci/precommit/.pre-commit-hooks.yaml")

info_df <- data.frame(
  id = unlist(
    lapply(
      info, "[", "id"
    )
  ),
  description = unlist(
  lapply(
    info, "[", "description"
    )
  )
)

knitr::kable(info_df)
id description
roxygenize run roxygen2::roxygenize()
use-tidy-description run usethis::use_tidy_description()
style-files style files with styler
no-browser-statement check if a .R file contains a browser() statement
parsable-R check if a .R file is parsable
readme-rmd-rendered make sure README.Rmd hasn’t been edited more recently than README.md
codemeta-description-updated make sure codemeta.json is in sync with DESCRIPTION. It should be run after use-tidy-description.
spell-check perform a spell check with spelling::spell_check_files()
deps-in-desc Check if dependencies that can be parsed from code are in DESCRIPTION.
lintr check if a .R file is lint free (using lintr)

Created on 2020-01-08 by the reprex package (v0.3.0)

Are you saying more info could be added to the same YAML? It'd be great because it'd be more transparent than having info about each hook split in two places.

from precommit.

maelle avatar maelle commented on July 27, 2024

Yes, all info in one place sounds good. Is it possible to use html details tag in a table? If so it'd be a good way to keep the table compact at first glance.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

I don't understand the question, sorry.

from precommit.

maelle avatar maelle commented on July 27, 2024

Look I've added a test below in the first cell. The column with arguments could have details tags so one would click to see arguments. I think the details package could help.

id description
argumentsblablabla
roxygenize
run roxygen2::roxygenize()
use-tidy-description run usethis::use_tidy_description()
style-files style files with styler
no-browser-statement check if a .R file contains a browser() statement
parsable-R check if a .R file is parsable
readme-rmd-rendered make sure README.Rmd hasn’t been edited more recently than README.md
codemeta-description-updated make sure codemeta.json is in sync with DESCRIPTION. It should be run after use-tidy-description.
spell-check perform a spell check with spelling::spell_check_files()
deps-in-desc Check if dependencies that can be parsed from code are in DESCRIPTION.
lintr check if a .R file is lint free (using lintr)

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

That's pretty cool. I assume this would also work in the {pkgdown} html page? And can we easily generate the source code of the table programmatically?

from precommit.

maelle avatar maelle commented on July 27, 2024

I suppose so thanks to details, but my problem is where the info would live (can you add any field to the YAML without breaking it for precommit purposes)?

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

We could create a .pre-commit-docs.yaml and link via id:

-   id: roxygenize
-   id: use-tidy-description
-   id: style-files
    args: 
    - --style_pkg=<package name >, defaulting to styler
    - --style_fun=<tidyverse_style>, defaulting to tidyverse_style
-   id: no-browser-statement
-   id: parsable-R
-   id: readme-rmd-rendered
-   id: codemeta-description-updated
-   id: spell-check 
-   id: deps-in-desc
-   id: lintr

An then do something like this:

library(magrittr)
library(rlang)
#> 
#> Attaching package: 'rlang'
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names
hooks <- yaml::read_yaml("~/git/precommit/.pre-commit-hooks.yaml")
details <- yaml::read_yaml("~/git/precommit/.pre-commit-docs.yaml")

hooks_df <- data.frame(
  id = unlist(
    lapply(
      hooks, "[", "id"
    )
  ),
  description = unlist(
    lapply(
      hooks, "[", "description"
    )
  )
)

details_df <- purrr::map_dfr(details, 
    ~ tibble::tibble(id = .x$id, args = paste0(" ", .x$args %||% ""))
) %>%
  dplyr::group_by(.data$id) %>%
  dplyr::summarize(args = paste0(.data$args, collapse = " "))

as_details <- function(args) {
  purrr::map_if(
    args, args != " ",
    ~details::details(.x, lang = NULL, output = "character") %>%
      gsub("\\n", "", .)
  )
}


details_df %>%
  dplyr::full_join(hooks_df) %>%
  dplyr::mutate(
    args = as_details(.data$args),
    description = paste0(
      .data$description, 
      args
    )
  ) %>% # View()
  dplyr::select(-.data$args) %>%
  knitr::kable(format = "markdown")
#> Joining, by = "id"
#> Warning: Column `id` joining character vector and factor, coercing into
#> character vector
id description
codemeta-description-updated make sure codemeta.json is in sync with DESCRIPTION
deps-in-desc Check if dependencies that can be parsed from code are in DESCRIPTION.
lintr check if a .R file is lint free (using lintr)
no-browser-statement check if a .R file contains a browser() statement
parsable-R check if a .R file is parsable
readme-rmd-rendered make sure README.Rmd hasn't been edited more recently than README.md
roxygenize run roxygen2::roxygenize()
spell-check perform a spell check with spelling::spell_check_files()
style-files style files with styler
--style_pkg=, defaulting to styler --style_fun=<tidyverse_style>, defaulting to tidyverse_style

use-tidy-description run usethis::use_tidy_description()
Created on 2020-01-15 by the reprex package (v0.3.0)

from precommit.

maelle avatar maelle commented on July 27, 2024

Or details in a third column? It looks good in any case!

from precommit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.