#27 Add pre-commit config and README
Merged 4 days ago by jcheca. Opened 11 days ago by kkleine.
tests/ kkleine/llvm pre-commit  into  main

@@ -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

file modified
+16
@@ -92,3 +92,19 @@ 

  # tag+:

  #   - sometag

  ```

+ 

+ ### Avoid common errors using pre-commit

+ 

+ This project uses [`pre-commit`](https://pre-commit.com/)

+ 

+ * to [lint fmf files](https://tmt.readthedocs.io/en/latest/guide.html#lint)

+ * to check that you don't have [trailing

+   whitespaces](https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#trailing-whitespace)

+ * to check that [files end 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.

@@ -8,4 +8,4 @@ 

  void qcrypto_akcipher_free(struct QCryptoAkCipher *akcipher)

  {

      akcipher->free(akcipher);

- } 

\ No newline at end of file

+ }

I've copied the README context here to explain what pre-commit does and how this project (and potentially the other test projects) can benefit from it.


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 and that every file ends with a newline.

Please install pre-commit using pip install pre-commit as described here. 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?

The pre-commit config looks good to me. However, the README additions feel redundant in this context. Both tmt lint and pre-commit are well-documented, and users can refer to their respective documentation for further details. IMHO, we could maintain a more concise README that points users to the relevant documentation for instructions on linting and pre-commit usage, going straight to the point and making it easier to read and digest.

Do you think we could reduce this a bit by adding only basic pre-commit installation instructions and referencing pre-commit docs and the tmt lint guide and lint checks docs for further info?

The pre-commit config looks good to me. However, the README additions feel redundant in this context. Both tmt lint and pre-commit are well-documented, and users can refer to their respective documentation for further details. IMHO, we could maintain a more concise README that points users to the relevant documentation for instructions on linting and pre-commit usage, going straight to the point and making it easier to read and digest.

Do you think we could reduce this a bit by adding only basic pre-commit installation instructions and referencing pre-commit docs and the tmt lint guide and lint checks docs for further info?

Yes, of course. Let me reduce it.

1 new commit added

  • simplify README.md
5 days ago

2 new commits added

  • simplify README.md
  • Add pre-commit config and README
5 days ago

1 new commit added

  • Fix wrapping
5 days ago

Thanks a ton! LGTM :)

rebased onto d853e73

4 days ago

Pull-Request has been merged by jcheca

4 days ago