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

run styler on template-activate.R #2025

Closed

Conversation

fh-mthomson
Copy link
Contributor

When calling styler::style_dir() on a project using renv, renv/activate.R gets auto-updated, which leads to some subtle noise / churn.

Changes in this MR were made as follows:

> styler::style_file("templates/template-activate.R")
Styling  1  files:
 templates/template-activate.R ℹ 
────────────────────────────────────────
Status	Count	Legend 
✔ 	0	File unchanged.
ℹ 	1	File changed.
✖ 	0	Styling threw an error.
────────────────────────────────────────
Please review the changes carefully!

Using the latest version on CRAN:

> packageVersion('styler')
[1] ‘1.10.3’

@kevinushey
Copy link
Collaborator

It seems like "renv" should be one of the excluded directories for styler, though:

> formals(styler::style_dir)$exclude_dirs
c("packrat", "renv")

Do you know why that's not applying in your case?

@fh-mthomson
Copy link
Contributor Author

Good call! You caught me in a not-fully-reproducible example :)

I've dug into it in the series of commits in fh-mthomson/rsconnect_quarto#1 to better reproduce

We're running pre-commit run --all-files as a linter; in

  1. Most repos: run styler::style_dir(), which, indeed, doesn't change renv/activate.R
  2. A large repo: run styler::style_file() on changed files does change it (see fh-mthomson/rsconnect_quarto@0069713)
➜  rsconnect_quarto git:(mthomson/renv_tweaks) ✗ pre-commit run --all-files                 
styler...................................................................Failed
- hook id: styler
- exit code: 1
- files were modified by this hook

- The project is out-of-sync -- use `renv::status()` for details.
Styling  3  files:
 bin/styler.R    ✔ 
 doc.qmd         ✔ 
 renv/activate.R ℹ 
────────────────────────────────────────
Status  Count   Legend 
✔       2       File unchanged.
ℹ       1       File changed.
✖       0       Styling threw an error.
────────────────────────────────────────
Please review the changes carefully!

@kevinushey
Copy link
Collaborator

I wonder if you could instead configure pre-commit to ignore things in the renv directory?

https://pre-commit.com/#top_level-exclude

I don't think the activate script should try to adhere to any specific style, especially since different projects might have different styles (number of spaces; tabs versus spaces; and so on)

@fh-mthomson
Copy link
Contributor Author

Nice, thanks for the suggestion!

I've confirmed in https://github.com/fh-mthomson/rsconnect_quarto/pull/1/files/006971373c265d1e7c583475972cde9fdab9dd2f..60e2b051258af54b819e02b59db2725e143b9561

  1. pre-commit run --all-files no longer changes either renv/activate.R (parent folder, child folder)
  2. styler::style_file() manually does show changes for each.

So, that approach makes sense to me - totally hear you on the style principles.

@fh-mthomson fh-mthomson deleted the mthomson/style_activate branch October 25, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants