precommit icon indicating copy to clipboard operation
precommit copied to clipboard

Style Quarto docs

Open RoyalTS opened this issue 3 years ago • 5 comments
trafficstars

As soon as the next styler release is cut and https://github.com/r-lib/styler/issues/913 goes live, add .qmd files to apply the style-files hook to.

RoyalTS avatar Apr 19 '22 13:04 RoyalTS

You can already do this by overriding files and additional_dependencies: - r-lib/styler in your .pre-commit-config.yaml if you want.

lorenzwalthert avatar Apr 19 '22 18:04 lorenzwalthert

What exactly does that files attribute have to be for this to work?

RoyalTS avatar Jul 27 '22 13:07 RoyalTS

We are not bound by CRAN version of {styler} (because we user env to manage versions and styler is already pinned to a GitHub version), so we could already implement that now. files just has to be a regex that matches quarto docs, see https://github.com/lorenzwalthert/precommit/blob/main/.pre-commit-hooks.yaml#L21

lorenzwalthert avatar Jul 27 '22 13:07 lorenzwalthert

You're saying a .pre-commit-config.yaml that includes

- repo: https://github.com/lorenzwalthert/precommit
  rev: v0.3.2
  hooks:
  - id: style-files
    args: [--style_pkg=styler, --style_fun=tidyverse_style]
    additional_dependencies:
    - r-lib/styler
    files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw|\.qmd)$'
    exclude: 'renv/activate\.R'

should do the trick?

RoyalTS avatar Jul 27 '22 15:07 RoyalTS

Yes, that should work. If the hook release v0.3.2 already includes a styler version that's large enough, you don't need the additional_dependencies.

lorenzwalthert avatar Jul 27 '22 16:07 lorenzwalthert