Add pre-commit config and README
This commit is contained in:
parent
004f89d043
commit
d853e7371a
3 changed files with 73 additions and 1 deletions
14
.pre-commit-config.yaml
Normal file
14
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.5.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
||||
# See https://tmt.readthedocs.io/en/latest/guide.html#checking-data-validity
|
||||
- repo: https://github.com/teemtee/tmt.git
|
||||
rev: 1.32.2
|
||||
hooks:
|
||||
- id: tmt-lint
|
||||
58
README.md
58
README.md
|
|
@ -92,3 +92,61 @@ tier: 1
|
|||
# tag+:
|
||||
# - sometag
|
||||
```
|
||||
|
||||
### Avoid common errors using pre-commit
|
||||
|
||||
Have you ever been asked to add a newline to the end of a file in your pull request? Don't worry no more.
|
||||
|
||||
This project uses `pre-commit` to validate that certain files (e.g. fmf) are not broken.
|
||||
|
||||
Pre-commit also checks that you don't have [trailing whitespaces](https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#trailing-whitespace) and that every file [ends with a newline](https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#end-of-file-fixer).
|
||||
|
||||
Please install `pre-commit` using `pip install pre-commit` as described [here](https://pre-commit.com/#install). Then navigate to your clone of this project and install the git hook scripts using `pre-commit install`. This will run pre-commit on every `git commit` that you make in this repository from now on.
|
||||
|
||||
The nice part is this: `pre-commit` will not only complain but fix your code when it runs and if your `git commit` is rejected because `pre-commit` complains, you can just run `git add -p` to check and pick the changes that it made in order to fix your commit. Then just re-run your `git commit` command.
|
||||
|
||||
From time to time you might want to run `pre-commit autoupdate` to refresh config to the latest version.
|
||||
|
||||
#### Example of tmt linting
|
||||
|
||||
Let's take the `tests/llvm-config/main.fmf` file:
|
||||
|
||||
```
|
||||
summary: Make sure llvm-config symlink is properly set up
|
||||
tier: 1
|
||||
duration: 1m
|
||||
extra-summary: /tools/llvm/llvm-config
|
||||
extra-task: /tools/llvm/llvm-config
|
||||
extra-nitrate: TC#0614096
|
||||
```
|
||||
|
||||
And change `duration: 1m` to `durations: 1m`.
|
||||
|
||||
Now add this change with `git add -p` and then run `git commit` to see how pre-commit complains:
|
||||
|
||||
```
|
||||
$ git commit
|
||||
trim trailing whitespace.................................................Passed
|
||||
fix end of files.........................................................Passed
|
||||
tmt lint.................................................................Failed
|
||||
- hook id: tmt-lint
|
||||
- exit code: 1
|
||||
|
||||
.fmf/version
|
||||
warn: /tests/llvm-config: - 'durations' does not match any of the regexes: '^extra-'
|
||||
/tests/llvm-config
|
||||
warn C000 key "durations" not recognized by schema, and does not match "^extra-" pattern
|
||||
warn C000 fmf node failed schema validation
|
||||
warn C001 summary key is missing
|
||||
fail T001 unknown key "durations" is used
|
||||
pass T002 test script is defined
|
||||
pass T003 directory path is absolute
|
||||
pass T004 test path '/home/kkleine/src/tests/llvm/tests/llvm-config' does exist
|
||||
skip T005 legacy relevancy not detected
|
||||
skip T006 legacy 'coverage' field not detected
|
||||
skip T007 not a manual test
|
||||
skip T008 not a manual test
|
||||
skip T009 library/file requirements not used
|
||||
```
|
||||
|
||||
Notice the error `unknown key "durations" is used`. Isn't that nice?
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ void qcrypto_akcipher_free(struct QCryptoAkCipher *akcipher);
|
|||
void qcrypto_akcipher_free(struct QCryptoAkCipher *akcipher)
|
||||
{
|
||||
akcipher->free(akcipher);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue