Comments (10)
At the moment I am testing with the following hook setup:
"action": "vendor/bin/phpcs $(git diff --cached --name-only --diff-filter=ACMR -z | xargs -0)",
I totally agree with @heiglandreas that it's better to verify before pushing, but the script will be far more complex.
from captainhook.
This could get quite big, it should not, but it could.
So providing this placeholder upfront maybe is not the best idea.
To solve this we could improve our placeholder system.
We would have to allow placeholder that can be computed only if they where used in an action configuration.
If you don't want to wait, you can have a look at the linting action and create your own code sniffer action accordingly.
But I will look into the placeholder thing
from captainhook.
The other thing is that you will still get notices about parts of your chamged files that you never touched but that where broken beforehand. IMO it would be best to always have a clean codesniffer run before you start. And then only your changes will cause codesniffer to complain. If you are worried about the speed: I wouldn't run CS on every commit but only on push to be able to commit fast and also probably unclean code and then have a cleanup before I push. Or think about running such tests (perhaps with an autocleaner) in CI.
Git Hooks are no replacement for CI!
from captainhook.
And you probably want to have a look at https://github.com/exussum12/coverageChecker
from captainhook.
Thanks for all responses. I agree we should do a codesniffer run on whole codebase, but I thought it would be nice to 'grow' into this, without a big task beforehand. Thanks @dimitar-ivanov-tryzens for the suggestion. Will try it out.
from captainhook.
That's what coverageChecker does. 😉
from captainhook.
Ah, missed that one, thanks!
from captainhook.
In version 5 this is available for pre-commit
hooks.
"pre-commit": {
"enabled": true,
"actions": [
{
"action": "tools/phpcs.phar --standard=psr12 {$STAGED_FILES|of-type:php}"
}
]
}
}
{$STAGED_FILES}
will get replaced by the list of changed or added files. You can filter the list by using the {$STAGED_FILES|of-type:php}
modifier or change the glue between files with {$STAGED_FILES|separated-by:, }
and of course you can combine both modifiers.
from captainhook.
@sebastianfeldmann If there is no staged PHP file e.g. the phpcs command will result in
ERROR: You must supply at least one file or directory to process.
Run "phpcs --help" for usage information
Is usage of https://github.com/exussum12/coverageChecker the only way to handle this? Or would it be possible to skip the wohl action?
from captainhook.
You can configure a Condition
like this
{
"action": "...",
"options": {},
"conditions": [
{
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
"args": ["php"]
}
]
}
With this Condition
the Action
will only get executed if PHP files are included in this commit.
For a more detailed explanation have a look at the documentation
from captainhook.
Related Issues (20)
- Using $ENV in run-exec config HOT 3
- Support for Relative Path to CaptainHook Executable in Generated Hooks HOT 5
- Allow Staged and Changed files condition to define diff-filter HOT 1
- PHP Fatal error: Argument #2 ($filter) must be of type array HOT 7
- InjectIssueKeyFromBranch does not work as expected HOT 10
- http://captainhook.info is not available anymore? HOT 1
- Support Symfony 7 HOT 2
- $CHANGED_FILES placeholder is empty for first push HOT 1
- [FEATURE-REQUEST] New placeholder `ALL_CHANGED_FILES` HOT 17
- Docker mode not working? HOT 9
- Linting fails when it shouldn't? HOT 3
- Default config file does not work HOT 3
- Error 'The "--input" option does not exist' when rerunning the hooks HOT 1
- captainhook/captainhook-phar failing, prefer captainhook/captainhook in README HOT 3
- Running Hooks in Subrepositories fails HOT 10
- Execute PHAR hook installation without an autoloader HOT 9
- [Feature] Parallel execution of actions HOT 1
- [Bug?] Pre-push hook failing with ddev/docker HOT 4
- Installation not working behind a proxy
- Install fails with a missing class HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from captainhook.