Skip to content

Commit b24169c

Browse files
authored
Support passing clang version (#18)
* chore: update debug infor * chore: add debug info * chore: update debug infor * chore: update debug infor * chore: update * docs: update README.md
1 parent 4d7a774 commit b24169c

File tree

11 files changed

+50
-34
lines changed

11 files changed

+50
-34
lines changed

.github/workflows/test.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,4 @@ jobs:
3434
fail_ci_if_error: true # optional (default = false)
3535
verbose: true # optional (default = false)
3636
- name: Test cpp-linter-hooks
37-
run: |
38-
pip install pre-commit
39-
pre-commit install
40-
pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true
41-
grep -e "Failed" result.txt
42-
if [ $? -ne 0 ]; then
43-
exit 1
44-
fi
37+
run: sh testing/run.sh

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ tests/__pycache__
77
.coverage
88
__pycache__
99
venv
10-
result.txt
10+
result.txt
11+
testing/main.c

README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The example of using custom config: `.clang-format` and `.clang-tidy`
3131
```yaml
3232
repos:
3333
- repo: https://github.com/cpp-linter/cpp-linter-hooks
34-
rev: v0.2.1
34+
rev: v0.2.5
3535
hooks:
3636
- id: clang-format
3737
args: [--style=file] # to load .clang-format
@@ -44,12 +44,12 @@ The example of using any version of [clang-tools](https://github.com/cpp-linter/
4444
```yaml
4545
repos:
4646
- repo: https://github.com/cpp-linter/cpp-linter-hooks
47-
rev: v0.2.1
47+
rev: v0.2.5
4848
hooks:
4949
- id: clang-format
50-
args: [--style=file, --version=13]
50+
args: [--style=file, --version=16]
5151
- id: clang-tidy
52-
args: [--checks=.clang-tidy, --version=12]
52+
args: [--checks=.clang-tidy, --version=16]
5353
```
5454

5555
## Output
@@ -107,25 +107,21 @@ int main() {for (;;) break; printf("Hello world!\n");return 0;}
107107
^
108108
```
109109

110-
### chang-tidy output
110+
### clang-tidy output
111111

112112
```bash
113113
clang-tidy...............................................................Failed
114114
- hook id: clang-tidy
115115
- exit code: 1
116116
117-
418 warnings and 1 error generated.
118-
Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
119-
Suppressed 417 warnings (417 in non-user code).
117+
522 warnings generated.
118+
Suppressed 521 warnings (521 in non-user code).
120119
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
121-
Found compiler error(s).
122-
/home/ubuntu/cpp-linter-hooks/testing/main.c:3:11: warning: statement should be inside braces [readability-braces-around-statements]
123-
for (;;) break;
124-
^
125-
{
126-
/usr/include/stdio.h:33:10: error: 'stddef.h' file not found [clang-diagnostic-error]
127-
#include <stddef.h>
128-
^~~~~~~~~~
120+
/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]
121+
for (;;)
122+
^
123+
{
124+
129125
```
130126

131127
## Contributing

cpp_linter_hooks/clang_format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def run_clang_format(args) -> int:
2424
else:
2525
retval = subprocess.run(command, stdout=subprocess.PIPE).returncode
2626
return retval, output
27-
except FileNotFoundError as e:
27+
except FileNotFoundError as stderr:
2828
retval = 1
29-
return retval, e
29+
return retval, stderr
3030

3131

3232
def main() -> int:

cpp_linter_hooks/clang_tidy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def run_clang_tidy(args) -> int:
2323
if "warning:" in output or "error:" in output:
2424
retval = 1
2525
return retval, output
26-
except FileNotFoundError as e:
26+
except FileNotFoundError as stderr:
2727
retval = 1
28-
return retval, e
28+
return retval, stderr
2929

3030

3131
def main() -> int:

cpp_linter_hooks/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def install_clang_tools(version: str) -> int:
1919
# clang-tools exist because install_requires=['clang-tools'] in setup.py
2020
install_tool_cmd = ['clang-tools', '-i', version]
2121
else:
22-
# install verison 13 by default if clang-tools not exist.
22+
# install version 13 by default if clang-tools not exist.
2323
install_tool_cmd = ['clang-tools', '-i', '13']
2424
try:
2525
subprocess.run(install_tool_cmd, stdout=subprocess.PIPE)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ authors = [
1313
]
1414
classifiers = [
1515
# https://pypi.org/pypi?%3Aaction=list_classifiers
16-
"Development Status :: 4 - Beta",
16+
"Development Status :: 5 - Production/Stable",
1717
"Intended Audience :: Developers",
1818
"Intended Audience :: System Administrators",
1919
"Intended Audience :: Information Technology",

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
coverage
2+
pre-commit
23
pytest

testing/.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
repos:
22
- repo: https://github.com/cpp-linter/cpp-linter-hooks
3-
rev:
3+
rev: 2a92e91720ca4bc79d67c3e4aea57642f598d534
44
hooks:
55
- id: clang-format
6-
args: [--style=file] # to load .clang-format
6+
args: [--style=file, --version=16] # to load .clang-format
77
- id: clang-tidy
8-
args: [--checks=.clang-tidy] # path/to/.clang-tidy
8+
args: [--checks=.clang-tidy, --version=16] # path/to/.clang-tidy

testing/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test cpp-linter-hooks
2+
3+
## Test locally
4+
5+
```bash
6+
pre-commit try-repo ./.. clang-format --verbose --all-files
7+
pre-commit try-repo ./.. clang-tidy --verbose --all-files
8+
```

testing/run.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pre-commit install
2+
pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true
3+
4+
failed_cases=`grep -c "Failed" result.txt`
5+
6+
if [ $failed_cases -eq 2 ]; then
7+
echo "=============================="
8+
echo "Test cpp-linter-hooks success."
9+
echo "=============================="
10+
exit 0
11+
rm result.txt
12+
else
13+
echo "============================="
14+
echo "Test cpp-linter-hooks failed."
15+
echo "============================="
16+
exit 1
17+
fi

0 commit comments

Comments
 (0)