Skip to content

Ignore certain file types / directories in style_file() #656

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

Closed
pat-s opened this issue Aug 5, 2020 · 9 comments
Closed

Ignore certain file types / directories in style_file() #656

pat-s opened this issue Aug 5, 2020 · 9 comments

Comments

@pat-s
Copy link
Contributor

pat-s commented Aug 5, 2020

I would like {styler} to either

  • ignore certain file types (in my case .yml files).
  • certain directories (in my case inst/).

I know this exists in style_pkg(exclude_dirs = ). However, when invoking {styler} via {precommit}, style_file() is called which does not have this option.

This might be a bit tricky since style_file is explicitly called on a path by {precommit} and hence some preprocessing before calling it might need to happen?

@lorenzwalthert
Copy link
Collaborator

I don't think this is a styler problem, although #319 might be a related issue. If it's only about using pre-commit, use the exclude: key. You can find documentation and example here: https://lorenzwalthert.github.io/precommit/articles/available-hooks.html#spell-check

@pat-s
Copy link
Contributor Author

pat-s commented Aug 5, 2020

Will setting a file type in exclude of the spell-check hook have an effect of what happens in the style-files hook? According to your link it might be as you do some copying but I cannot get it working.

I tried excluding all YAML files by adding .*\.yml to it and adding exclude to the style-files hook.
Still, my YAML files get styled.
What am I doing wrong?

Feel free to move the issue to {precommit} :)

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Aug 5, 2020

No you have to set the exclude: key in the styler hook. well yml or yaml? Like this maybe?

# ...
    -   id: style-files
        exclude: >
            (?x)^(
                .*\.yaml
            )$

@pat-s
Copy link
Contributor Author

pat-s commented Aug 5, 2020

Thanks. Still gets styled. And yes, it is .yml.

Does it matter that the files lives in inst/?

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Aug 5, 2020

I don't get why you want to exclude them from the hook, they are not going to be changed anyways. What do you mean with gets styled? Not skipped from the pre-commit output during git commit? It should not matter, but you can try to move it to the root and see what happens.

@pat-s
Copy link
Contributor Author

pat-s commented Aug 6, 2020

I don't get why you want to exclude them from the hook, they are not going to be changed anyways. What do you mean with gets styled? Not skipped from the pre-commit output during git commit?

The styler hook also styles .yml files for me. Not the ones listed in .github or .travis.yml but .yml files which live in inst/.
Specifically not the code gets styled, but superfluous blank lines.
However, in my case these are not superfluous but intended.
Or am I wrong and styler is not the hook responsible for this action?

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Aug 6, 2020

Are you sure it's the styler hook? styler can only style R files and friends (Rnw, Rmd, Rpfofile etc). I have the stong apprehension that it is in fact a hook like https://github.com/lorenzwalthert/precommit/blob/master/.pre-commit-config.yaml#L45 or similar. Can you show the output of git commit that changes the file or maybe easier for you, the .pre-commit-config.yaml of the repo of concern?

Screenshot 2020-08-06 at 10 25 13

@pat-s
Copy link
Contributor Author

pat-s commented Aug 6, 2020

Ahh! I did not see this hook before.

Just tested it and indeed it is the end-of-file-fixer hook.
Works fine if I exclude .yml there 🎉

Sorry for the trouble!
I was also confused why styler would touch .yml files 😅

@pat-s pat-s closed this as completed Aug 6, 2020
@lorenzwalthert
Copy link
Collaborator

Yeah, me too haha. Good to have some context sometimes, then tricky problems become simple 😊.

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

No branches or pull requests

2 participants