From f0a3e1c6a539aa374e3bb29c2694e4cac70bf16d Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 25 May 2025 23:21:10 +0300 Subject: [PATCH 1/4] docs: add example to use files in pre-commmit --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index c61bb1d..db015a6 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,21 @@ repos: args: [--checks=.clang-tidy, --version=16] # Specifies version ``` +> [!IMPORTANT] +> If you run `pre-commit` longer than expected, highly suggest to add `files` in `hooks` to limit the scope of the hook. For example below: + +```yaml +- repo: https://github.com/cpp-linter/cpp-linter-hooks + rev: v0.6.1 + hooks: + - id: clang-format + args: [--style=file, --version=16] + files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$ # limit the scope + - id: clang-tidy + args: [--checks=.clang-tidy, --version=16] + files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$ +``` + ## Output ### clang-format Example From ec3ab960b12de7fd6b328a062a20c313984fef8b Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 25 May 2025 23:21:49 +0300 Subject: [PATCH 2/4] chore: bump pre-commit-hooks version --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9f4dbf..06eae45 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,11 +10,11 @@ repos: - id: check-toml - id: requirements-txt-fixer - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.20.0 hooks: - id: pyupgrade - repo: https://github.com/pycqa/flake8 - rev: '7.0.0' + rev: '7.2.0' hooks: - id: flake8 args: [--max-line-length=120] From 61cf4376571e84ca4ab814f7b7091d731102429d Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 25 May 2025 23:31:03 +0300 Subject: [PATCH 3/4] docs: revise readme.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db015a6..8175dd6 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ repos: ``` > [!IMPORTANT] -> If you run `pre-commit` longer than expected, highly suggest to add `files` in `hooks` to limit the scope of the hook. For example below: +> If your `pre-commit` runs longer than expected, it is highly recommended to add `files` in `.pre-commit-config.yaml` to limit the scope of the hook. This helps improve performance by reducing the number of files being checked and avoids unnecessary processing. For example below: + ```yaml - repo: https://github.com/cpp-linter/cpp-linter-hooks From 82de5b1884186ca9ce316ca1290b1259f5665557 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Mon, 26 May 2025 10:06:06 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8175dd6..bb0ce9d 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ repos: ``` > [!IMPORTANT] -> If your `pre-commit` runs longer than expected, it is highly recommended to add `files` in `.pre-commit-config.yaml` to limit the scope of the hook. This helps improve performance by reducing the number of files being checked and avoids unnecessary processing. For example below: +> If your `pre-commit` runs longer than expected, it is highly recommended to add `files` in `.pre-commit-config.yaml` to limit the scope of the hook. This helps improve performance by reducing the number of files being checked and avoids unnecessary processing. Here's an example configuration: ```yaml @@ -73,6 +73,14 @@ repos: files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$ ``` +Alternatively, if you want to run the hooks manually on only the changed files, you can use the following command: + +```bash +pre-commit run --files $(git diff --name-only) +``` + +This approach ensures that only modified files are checked, further speeding up the linting process during development. + ## Output ### clang-format Example