How to run pre-commit inside folder
See original GitHub issueHi! I have project structure like this
.
├── README.md
├── backend
│ ├── Pipfile
│ ├── Pipfile.lock
│ ├── mypy.ini
│ ├── pylintrc
│ ├── pyproject.toml
│ ├── src
│ ├── tests
│ └── tox.ini
├── docker
│ ├── backend
│ └── postgres
├── docker-compose.yml
└── .pre-commit-config.yaml
I would like to run pre-commit’s flake8 inside backend folder, how could I achieve this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:25 (9 by maintainers)
Top Results From Across the Web
Run hooks on files in specific dir, rather than using `--all-files`
I am able to successfully use pre-commit run --all-files to run ... Now, I'm trying to run the hooks just on files in...
Read more >Git pre-commit hooks only for a specific subfolder?
I want to have a pre-commit hook that will run jshint but only if any of the staged files are in the Javascript...
Read more >pre-commit
Run pre-commit install to install pre-commit into your git hooks. pre-commit will now run on every commit. Every time you clone a project...
Read more >How to use git pre-commit hooks, the hard way and the easy ...
git/ directory, open up the .git/hooks/ directory. You will see a bunch of files named hook-type.sample . You should see one named pre...
Read more >Pre-Commit Hook Example in GitKraken Client | Git Hooks ...
First navigate to the hooks directory for the target repo. Open a Visual Studio Code window and navigate to repo .git hooks. From...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone who comes across this later, I based my approach on what patrick91 did (thanks for the tips!), but noticed that the approach with
entry: bash -c 'cd ... && ... "$@"'(i.e., passing the file names along with bash via$@) actually ends up dropping the first filename and doesn’t send the complete list. For me, rather than:This worked instead:
@asottile I had to do something a bit hacky to support
entry: bash -c 'cd ... && ... "$@"'. My use case is that I want to use eslint without having to install dependencies twice, I’m also running in a monorepo setup, similar to the one in the first comment. We have a frontend folder with all the configuration for eslint and running eslint from outside the frontend folder has been a bit tricky, for example it would ignore the .eslintignore file. Also using the bash hack didn’t work as pre-commit passes the path withfrontend/, so the file wasn’t being found. For now I’ve solved using a custom script that fixes the paths, but I don’t really like it 😃Do you have a better suggestion?
Here’s the hack I did, for more context: https://github.com/pythonitalia/pycon/pull/808/commits/f623cf87bc235bcfab07fbad0eed7d119fa971e1