Skip to content

Support passing clang version #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,4 @@ jobs:
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
- name: Test cpp-linter-hooks
run: |
pip install pre-commit
pre-commit install
pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true
grep -e "Failed" result.txt
if [ $? -ne 0 ]; then
exit 1
fi
run: sh testing/run.sh
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ tests/__pycache__
.coverage
__pycache__
venv
result.txt
result.txt
testing/main.c
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The example of using custom config: `.clang-format` and `.clang-tidy`
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.2.1
rev: v0.2.5
hooks:
- id: clang-format
args: [--style=file] # to load .clang-format
Expand All @@ -44,12 +44,12 @@ The example of using any version of [clang-tools](https://github.com/cpp-linter/
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.2.1
rev: v0.2.5
hooks:
- id: clang-format
args: [--style=file, --version=13]
args: [--style=file, --version=16]
- id: clang-tidy
args: [--checks=.clang-tidy, --version=12]
args: [--checks=.clang-tidy, --version=16]
```

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

### chang-tidy output
### clang-tidy output

```bash
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1

418 warnings and 1 error generated.
Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
Suppressed 417 warnings (417 in non-user code).
522 warnings generated.
Suppressed 521 warnings (521 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
/home/ubuntu/cpp-linter-hooks/testing/main.c:3:11: warning: statement should be inside braces [readability-braces-around-statements]
for (;;) break;
^
{
/usr/include/stdio.h:33:10: error: 'stddef.h' file not found [clang-diagnostic-error]
#include <stddef.h>
^~~~~~~~~~
/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]
for (;;)
^
{

```

## Contributing
Expand Down
4 changes: 2 additions & 2 deletions cpp_linter_hooks/clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def run_clang_format(args) -> int:
else:
retval = subprocess.run(command, stdout=subprocess.PIPE).returncode
return retval, output
except FileNotFoundError as e:
except FileNotFoundError as stderr:
retval = 1
return retval, e
return retval, stderr


def main() -> int:
Expand Down
4 changes: 2 additions & 2 deletions cpp_linter_hooks/clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def run_clang_tidy(args) -> int:
if "warning:" in output or "error:" in output:
retval = 1
return retval, output
except FileNotFoundError as e:
except FileNotFoundError as stderr:
retval = 1
return retval, e
return retval, stderr


def main() -> int:
Expand Down
2 changes: 1 addition & 1 deletion cpp_linter_hooks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def install_clang_tools(version: str) -> int:
# clang-tools exist because install_requires=['clang-tools'] in setup.py
install_tool_cmd = ['clang-tools', '-i', version]
else:
# install verison 13 by default if clang-tools not exist.
# install version 13 by default if clang-tools not exist.
install_tool_cmd = ['clang-tools', '-i', '13']
try:
subprocess.run(install_tool_cmd, stdout=subprocess.PIPE)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [
]
classifiers = [
# https://pypi.org/pypi?%3Aaction=list_classifiers
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Intended Audience :: Information Technology",
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
pre-commit
pytest
6 changes: 3 additions & 3 deletions testing/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev:
rev: 2a92e91720ca4bc79d67c3e4aea57642f598d534
hooks:
- id: clang-format
args: [--style=file] # to load .clang-format
args: [--style=file, --version=16] # to load .clang-format
- id: clang-tidy
args: [--checks=.clang-tidy] # path/to/.clang-tidy
args: [--checks=.clang-tidy, --version=16] # path/to/.clang-tidy
8 changes: 8 additions & 0 deletions testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Test cpp-linter-hooks

## Test locally

```bash
pre-commit try-repo ./.. clang-format --verbose --all-files
pre-commit try-repo ./.. clang-tidy --verbose --all-files
```
17 changes: 17 additions & 0 deletions testing/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pre-commit install
pre-commit try-repo . -c testing/.pre-commit-config.yaml --files testing/main.c | tee result.txt || true

failed_cases=`grep -c "Failed" result.txt`

if [ $failed_cases -eq 2 ]; then
echo "=============================="
echo "Test cpp-linter-hooks success."
echo "=============================="
exit 0
rm result.txt
else
echo "============================="
echo "Test cpp-linter-hooks failed."
echo "============================="
exit 1
fi