pocc / pre-commit-hooks Goto Github PK
View Code? Open in Web Editor NEWC/C++ hooks to integrate with pre-commit
License: Apache License 2.0
C/C++ hooks to integrate with pre-commit
License: Apache License 2.0
if "-p" is specified alone (so the "-p" in args -check could succeed) clang-tidy complains about missing value.
If it's specified correctly for clang-tidy ("-p=cmake-build-debug") then the check fails and the -D is added which makes clang-tidy not find for example included libraries...
I will submit a PR soonish.
> For clang-format, with a `.clang-format` file in the base of your repo:
- repo: https://github.com/pocc/pre-commit-hooks rev: v1.3.5 hooks: - id: clang-format args: [-i, --style=file]
Thanks for your reply. I will try it.
Originally posted by @sangshuduo in #50 (comment)
Clang-format has a limitation that it only looks in the current director, or above it, when searching for a config file.
I have multiple repositories, A, B, and C.
A and B have source code.
C has common configuration including the clang-format file, which is shared with B and C.
Latest clang-format has support for this: https://stackoverflow.com/a/70859277/11032285
Is there anything that I should do to use that?
I'm trying to use the uncrustify hook, but if you try to specify a language or configuration file, the parser seems to think they are file names instead of arguments?
Config file:
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.1.1
hooks:
- id: uncrustify
args: ["-l CPP", "-c build/uncrustify.cfg", "--replace" ]
Example error call stack:
[INFO] Stashing unstaged files to C:\Users\test\.cache\pre-commit\patch1629754966-43936.
uncrustify...............................................................Failed
- hook id: uncrustify
- duration: 0.31s
- exit code: 1
Traceback (most recent call last):
File "c:\users\test\scoop\apps\python\3.9.6\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\test\scoop\apps\python\3.9.6\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\test\.cache\pre-commit\repo3sfmc84z\py_env-default\Scripts\uncrustify-hook.EXE\__main__.py", line 7, in <module>
File "C:\Users\test\.cache\pre-commit\repo3sfmc84z\py_env-default\lib\site-packages\hooks\uncrustify.py", line 55, in main
cmd.run()
File "C:\Users\test\.cache\pre-commit\repo3sfmc84z\py_env-default\lib\site-packages\hooks\uncrustify.py", line 47, in run
self.compare_to_formatted(filename)
File "C:\Users\test\.cache\pre-commit\repo3sfmc84z\py_env-default\lib\site-packages\hooks\utils.py", line 164, in compare_to_formatted
actual = self.get_filelines(filename)
File "C:\Users\test\.cache\pre-commit\repo3sfmc84z\py_env-default\lib\site-packages\hooks\utils.py", line 201, in get_filelines
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '-l CPP'
This is something that clang-format-diff and clang-tidy-diff do to varying degrees of success.
Via https://www.reddit.com/r/cpp/comments/pnli5r/cc_precommit_hooks_for_static_analyzers_and/
Hi,
Thanks for putting this repo together, I just found out about the pre-commit framework after a week of trying to make my own hooks work on my Windows 10 machine and it's much easier to use. This is more a question than a issue.
I'm currently working on a C project and I'm setting on my workflow to launch both clang-format
and cppcheck
hooks on my files (and ignoring some third party files)
My first question is, if I want to run cppcheck
on multiple files, does the following .pre-commit-config.yaml
should be able to launch cppcheck on all the .c
and .h
files under my lm/src
directory?
# Exclude vendor autogenerated files
exclude: 'Core'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
# Don't let commit in the master branch
- id: no-commit-to-branch
args: ['--branch', 'master']
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.1.1
hooks:
# - id: clang-format
# args: [--style=file]
- id: cppcheck
args: ['--quiet', '--enable=all' '--inline-suppr']
# Run on files with c or h extension on lm directory
files: 'lm/src/\.(c)$'
The output I'm getting:
Trim Trailing Whitespace.................................................Passed
Don't commit to branch...................................................Passed
cppcheck.............................................(no files to check)Skipped
I've cppcheck v2.3 installed on my Windows 10 machine tho.
Regards
Hi,
clang-format hook is working fine in git bash on Windows.
However it seems that it doesn't work in 'cmd' prompt on Windows. It fails with the following error:
diff: /dev/fd/63: No such file or directory
It fails whether my C++ file is correctly formatted or not.
I am using this config:
_______________________________________________________________________ TestCLinters.test_clang_tidy_err ________________________________________________________________________
self = <tests.hooks_test.TestCLinters object at 0x110d08128>
def test_clang_tidy_err(self):
clang_tidy_error = r"""{0}:1:28: error: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,-warnings-as-errors]
int main() {{ int i; return 10; }}
^
""" # noqa: E501
self.run_clang_tidy(
filelist=self.errfiles,
expected_output=clang_tidy_error,
> expected_retcode=1,
)
tests/hooks_test.py:127:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <tests.hooks_test.TestCLinters object at 0x110d08128>
filelist = ['/Users/guihaoliang/Work/playground/github/pre-commit-hooks/tests/files/err.c', '/Users/guihaoliang/Work/playground/github/pre-commit-hooks/tests/files/err.cpp']
expected_output = '{0}:1:28: error: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,-warnings-as-errors]\nint main() {{ int i; return 10; }}\n ^\n'
expected_retcode = 1, version = ''
def run_clang_tidy(self, filelist, expected_output, expected_retcode, version=""):
"""Test that clang tidy returns correct retcode & output for files."""
cmds = [
"./hooks/clang-tidy",
"-quiet",
"-checks=*",
"-warnings-as-errors=*",
]
if version:
cmds += ["--version=" + version]
for filename in filelist:
if version: # Version docstring doesn't contain a {0}
expected = expected_output
else:
expected = expected_output.format(filename)
# In case num warnings changes due to more checks
actual, retcode = self.get_all_output(cmds, filename)
actual = re.sub(r"^\d+", "2", actual)
# Expecting error text with a err return code
> assert actual == expected
E AssertionError: assert '/Users/guiha... ^\n' == '/Users/guiha... ^\n'
E - /Users/guihaoliang/Work/playground/github/pre-commit-hooks/tests/files/err.cpp:1:5: error: use a trailing return type for this function [modernize-use-trailing-return-type,-warnings-as-errors]
E - int main() { int i; return 10; }
E - ~~~ ^
E - auto -> int
E /Users/guihaoliang/Work/playground/github/pre-commit-hooks/tests/files/err.cpp:1:28: error: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,-warnings-as-errors]
E int main() { int i; return 10; }
E ^
tests/hooks_test.py:166: AssertionError
===========================================
Hi,
I would like to run all of the hooks only on specific directories. To achieve this I'm using file exclude pattern. The exclude works for the clang-format but not for the clang-tidy (for example it reports errors in Utilities directory with manufacturer files). Basically clang-tidy takes all files.
How I can make the exclude pattern work for clang-tidy also? I saw files: .*\.c
option but I would have to repeat the excludes in - id: clang-tidy
hook
PS. I noticed cpplint also runs on all the files and ignores file exclude pattern
Here is my config file:
exclude: |
(?x)^(
.vscode/.*|
Core/.*|
Drivers/.*|
LoRaWAN/.*|
Middlewares/Third_Party/.*|
Utilities/.*|
config/.*|
^.*\.(svd|ld)|
.mxproject
)$
repos:
- repo: local
hooks:
- id: compiledb
name: compiledb
entry: compiledb
language: system
args: [--overwrite, make, -n, -B]
always_run: true
require_serial: true
pass_filenames: false
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: cpplint
- id: clang-tidy
args: [-checks=clang-diagnostic-return-type]
@guihao-liang @sparfenyuk @TheButlah @zbeekman @bsergean You guys have interacted with this repo and I'd like your input. Issues have been created in part due to how bash parses strings or interacts with arrays/hash maps (#5, #9, #10), or how it's not even the same across platforms (#4 - thanks to zbeekman for a likely fix).
Python is required to install pre-commit and so everyone using pre-commit already has it on their system. Python has more predictable behavior, which is what I'm aiming for here in contrast to bash (e.g. ${args[*]}
vs ${args[@]}
). It's also a well-known glue language for C/C++, so it would fit well here.
Thoughts?
include-what-you-use does not fail even if it is supposed to fail. I needed to modify my pre-commit yaml file to include the line entry
:
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: uncrustify
- id: include-what-you-use
entry: include-what-you-use -Xiwyu --error=1
Currently, the hooks require tooling to be available on the machines where the hooks are running. Would the project be open to supporting specifying which version of clang-tidy to download and download the appropriate version on the machine as part of pre-commit so that the user doesn't have to worry about installing the tooling?
The upstream has clang-tidy releases multiple versions of clang-tidy.
and the pre-commit for clang downloads the specific version corresponding to os based on version arg provided for the hook.
Happy to look into a patch along these lines.
I am trying to set the directory where compile_commands.json file exists by using -p argument. Clang-tidy hook doesn't use it much. It causes errors while the tool looks for external libraries that are used in the project.
fail_fast: false
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: master
hooks:
- id: clang-format
types: [c++]
- id: clang-tidy
args: [-p=/home/user/projects/myproject/build]
pre-commit run
clang-format.............................................................Failed
- hook id: clang-format
- exit code: 1
firmware/src/main.cpp
====================
--- original
+++ formatted
@@ -33,7 +33,7 @@
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
-int x= 0;
+int x = 0;
int main(void) {
which clang-format
/home/USER/.local/bin/clang-format
Ubuntu 22 LTS
clang-format LLVM installed locally
Any way to find out why it failed?
thanks
Maybe I'm just too new to integrating pre-commit into my project and use it incorrectly, but it seems that the arguments for include-what-you-use are passed incorrectly.
The manpage reads
USAGE: include-what-you-use [-Xiwyu --iwyu_opt]... <clang opts> <source file>
but hooks/include_what_you_use.py:25 currently reads
self.run_command([filename] + self.args)
If I include a standard header e.g. stdio.h
, clang-tidy will analyse it and fail because the header's content doesn't comply with the checks:
2816 warnings generated.
Suppressed 2816 warnings (2816 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.
In the context of pre-commit, this is a problem because it causes the process to exit with code 1. Therefore, the check fails even though these warnings are being "suppressed". clang-tidy clearly knows these warnings are not from user code, yet I cannot find a way to make it stop exiting with code 1 (--quiet
doesn't help). I'm a novice with clang-tidy, so I may have misconfigured something.
With this in mind, how is it even practical to use clang-tidy at all with pre-commit? How do you use it?
pre-commit-hooks/hooks/clang_tidy.py
Line 22 in 336fdd7
The comment above seems misleading; passing --fix-errors seems to actually trigger the error if one is found..
Issue's target is master. To reproduce, create a repo with two err files and run clang-format-hook over it with -i
.
Current behavior is to immediately fail if there's one file that's failing.
Expected (and more useful) behavior is to fix all files and then fail.
Running pre-commit with Cppcheck 2.4.1 on my machine does not provide any output despite the return code not being 0.
Actual:
$ pre-commit run --all-files cppcheck
cppcheck.................................................................Failed
- hook id: cppcheck
- exit code: 1
Expected:
cppcheck.................................................................Failed
- hook id: cppcheck
- exit code: 1
/tmp/temp/src/err.cpp:2:18: style: Unused variable: i [unusedVariable]
int main() { int i; return 10; }
^
Hey! I read in your documentation that installing llvm with brew on Mac should also install clang-format and clang-tidy. This does not work on my machine however. Both clang-format and clang-tidy give me errors suggesting they are not installed when I do pre-commit run -a
I noticed this issue with ClangTidyCmd
but it it is an issue for all the other similar concrete classes (CppcheckCmd
, CpplintCmd
, IncludeWhatYouUseCmd
, etc.).
I am working on a cross-platform C++ repo that has windows/ and linux/ subfolders for implementations on a specific OS. I'm setting up linting. Clang-tidy, as expected, can only process the code for the current system (Linux / Windows). e.g. if I am on Linux and run your hooks with the command pre-commit run --all-files clang-tidy
, it will try to parse the Windows files and error out.
Because pre-commit-config.yaml does not take variables, I created a shim script that filters out any files from the wrong folder. For example, if I am on Linux and pre-commit passes some file named foo/windows/bar.cpp
in argv, the shim will create a new list without that file and call your hook.
.pre-commit-config.yaml:
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-tidy
entry: scripts/pocc-shim.py
scripts/pocc-shim.py:
def main() -> int:
"""Filter out filenames from other system implementations and call pocc's clang-tidy hook with the modified args."""
if sys.platform == "win32":
exclude = "linux"
elif sys.platform == "linux":
exclude = "windows"
else:
raise NotImplementedError(f"Not implemented for system: {sys.platform}")
filtered_args = shim_utils.filter_args(exclude, sys.argv)
return hooks.clang_tidy.main(filtered_args)
The issue is that this doesn't work. Clang-tidy is still failing on files shouldn't have been passed to it.
I had a look at utils.py and saw that Command.get_added_files
is reading directly from sys.argv
instead of the args
variable passed in.
My current workaround is to just set sys.argv.
scripts/pocc-shim.py:
filtered_args = shim_utils.filter_args(exclude, sys.argv)
sys.argv = filtered_args # set sys.argv as workaround
return hooks.clang_tidy.main(filtered_args)
After this, the hook passes on both systems, properly ignoring files from the excluded folders.
I find this workaround distasteful, but it works fine and is acceptable for my purposes.
However, the underlying issue should still be addressed.
You can see my code here akfreed/CppSocketsXPlatform@df8ac58. At the moment it is easier to reproduce on Linux. You will need clang-tidy version 13 (I installed with brew).
OS: Ubuntu 20
Toolchain: (All Ubuntu 20 apt default versions except clang-tidy)
git clone https://github.com/akfreed/CppSocketsXPlatform.git
cd CppSocketsXPlatform
git checkout df8ac584207130e305de562e01e154407857e2ea
git submodule update --init --recursive
mkdir build && cd build
cmake ..
cd ..
python3 -m venv .venv
. .venv/bin/activate
pip install -U pip
pip install pre-commit
pre-commit run --all-files clang-tidy
(.venv) freed@ubuntu20:~/cpp/repro$ pre-commit run --all-files clang-tidy
[INFO] Installing environment for https://github.com/pocc/pre-commit-hooks. [INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
clang-tidy...............................................................Passed
it fails on a file under the windows folder
(.venv) freed@ubuntu20:~/cpp/repro$ pre-commit run --all-files clang-tidy
clang-tidy...............................................................Failed
- hook id: clang-tidy - exit code: 1
/home/freed/cpp/repro/StrapperNet/lib/windows/SocketHandle.cpp:25:1: error: constructor does not initialize thes
e fields: m_socketId [cppcoreguidelines-pro-type-member-init,hicpp-member-init,-warnings-as-errors]
SocketHandle::SocketHandle() = default; ^
...
...lots and lots of errors...
...
tool can be found here: https://github.com/cpplint/cpplint
It's written in python, so should be implement/test against all platforms.
I have seen in the hook's code that uncrustify
is hardcoded as a command. It would be really useful to specify some custom path for the executable, e.g. /home/skelly37/.local/bin/uncrustify
, so the end-user can have multiple uncrustify installations or so they do not have to mess with the system's PATH
If I can already do something like this, I would appreciate showing me how to do it.
Hi, I am trying to use the clang-tidy hook.
my .pre-commit-config.yaml looks something like:
`repos:
Notice the args. I specify the path to the database.
When trying to run, I get:
clang-tidy: for the -p option: may not occur within a group! error: clang-tidy: Unknown command line argument '-p build/meson'. Try: 'clang-tidy --help' clang-tidy: Did you mean '-p'?
Thank you for your help
On macOS if I pass --check=*
to clang-tidy, it flags a macro expanded from a system header. If I add the appropriate clang-tidy directive to ignore the error on that line, the pre-commit hook still fails:
clang-tidy...........................................................................Failed
hookid: clang-tidy
1080 warnings generated.
Suppressed 1090 warnings (1080 in non-user code, 10 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Adding a --suppress
to the args in the pre-commit-config.yaml like so args: ["--suppress=*:*test*"]
will prevent the hook from adding the other default --suppress
present in the cppcheck.py :
self.add_if_missing( ["--suppress=unmatchedSuppression", "--suppress=missingIncludeSystem", "--suppress=unusedFunction"] )
This is because the add_if_missing() function will see that a --suppress
was already added in the args field so it will not add it again.
If you specify the -max-priority-3 0
as an option for the file int main() { int i; return 10; }
, oclint will return 5 instead of 0. My understanding of oclint return codes was faulty in that there are various levels of errors, some of which are suppressed by default vis-a-vis the return code.
More information about this issue can be found at oclint/oclint#538
Additional info can be found about this oclint flag is at https://docs.oclint.org/en/stable/manual/oclint.html#exit-status-options
My .clang-format file isn't processed ... could it be a bug in pre-commit ?
This is the repo I'm using -> https://github.com/machinezone/IXWebSocket
Any clue ?
repos:
- repo: https://github.com/pocc/pre-commit-hooks
sha: master
hooks:
- id: clang-format
args: [--style=Google, -i]
exclude: \.pb\.(h|cc)$
clang-format.............................................................Failed
- hook id: clang-format
- exit code: 2
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
modified utils,
function diff_formatted {
69 # Quoting $1 interferes with array creation
70 # shellcheck disable=SC2206
71 args=($1)
72 filename="$2"
+ 73 echo $filename
74 if [[ " ${args[*]} " == *" -i "* ]]; then
75 # Here, diff compares what the file is before and after transform
76 diff "$filename" <(clang-format "${args[@]}"; cat "$filename")
77 else
78 # Otherwise clang-format should send output to stdout, and can be compared
79 diff "$filename" <(clang-format "${args[@]}")
80 fi
output:
-i
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
-i
diff: missing operand after `/dev/fd/63'
diff: Try `diff --help' for more information.
The filename is -i
, which makes the pipe fail.
clang-format supports -i
, why you don't want to use it but use diff
instead?
Thanks for this !
For Python pre-commit is able to apply the proposed changes to the files, so that one has to just review the changes with git. Can the same be done here?
Current behavior is to just print file differences, which isn't helpful for multiple files.
Add support for running Include-What-You-Use alongside the other linters in this repository.
The aim of the tool is best described by them on their webpage:
"Include what you use" means this: for every symbol (type, function variable, or macro) that you use in foo.cc,
either foo.cc or foo.h should #include a .h file that exports the declaration of that symbol. The
include-what-you-use tool is a program that can be built with the clang libraries in order to analyze
#includes of source files to find include-what-you-use violations, and suggest fixes for them.
The main goal of include-what-you-use is to remove superfluous #includes. It does this both by figuring out
what #includes are not actually needed for this file (for both .cc and .h files), and replacing #includes
with forward-declares when possible.
Since CMake 3.3, IWYU is also natively supported alongside the build (see CMAKE_<LANG>_INCLUDE_WHAT_YOU_USE CMake variable).
The tool also ships with a supporting Python scripts iwyu_tool.py
that is able to take advantage of compilation databases (compile_commands.json
). For more information see their GitHub page.
my pre-commit file look like:
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- repo: https://github.com/pocc/pre-commit-hooks
rev: master
hooks:
- id: clang-format
args: [-i]
- id: clang-tidy
# - id: oclint
# - id: uncrustify
# - id: cppcheck
# - id: cpplint
and it's a cmake c++ projects and I added set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
on my cmakelist.txt
and cmake generate file namedcompile_commands.json
and it`s contain the file c++ src file path.
{
"directory": "/Users/chendongsheng/github/cmake_test/build",
"command": "/usr/bin/clang++ -I/Users/chendongsheng/github/cmake_test/lib1/. -I/Users/chendongsheng/github/cmake_test/lib2/. -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -o lib1/CMakeFiles/lib1.dir/aaa.cpp.o -c /Users/chendongsheng/github/cmake_test/lib1/aaa.cpp",
"file": "/Users/chendongsheng/github/cmake_test/lib1/aaa.cpp"
},
but when i try to run pre-commit run --all-files
I got error like:
[WARNING] The 'rev' field of repo 'https://github.com/pocc/pre-commit-hooks' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
clang-format.............................................................Passed
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1
/Users/chendongsheng/github/cmake_test/app/main.cpp:1:10: error: 'lib1.h' file not found [clang-diagnostic-error]
#include "lib1.h"
^~~~~~~~
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "lib1/aaa.cpp"
No compilation database found in /Users/chendongsheng/github/cmake_test/lib1 or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "app/main.cpp"
No compilation database found in /Users/chendongsheng/github/cmake_test/app or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 error generated.
Error while processing /Users/chendongsheng/github/cmake_test/app/main.cpp.
Found compiler error(s).
With the default test repo (pre-commit-hooks/tests/test_repo
) and the following config...
fail_fast: false
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [--version=10.0.0, --style=Google]
... the following happens (incorrectly, it should detect the incorrect formatting):
$ pre-commit run -a
clang-format.............................................................Passed
But when I remove --version=10.0.0
, it's working:
$ pre-commit run -a
clang-format.............................................................Failed
- hook id: clang-format
- exit code: 1
err.cpp
====================
--- original
+++ formatted
@@ -1,2 +1,5 @@
#include <string>
-int main(){int i;return;}
+int main() {
+ int i;
+ return;
+}
err.c
====================
--- original
+++ formatted
@@ -1,2 +1,5 @@
#include <stdio.h>
-int main(){int i;return;}
+int main() {
+ int i;
+ return;
+}
There is a conflict:
modernize wants to use trailing return type https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-trailing-return-type.html
but Fuchsia disallows it https://clang.llvm.org/extra/clang-tidy/checks/fuchsia-trailing-return.html
maybe set the default to "-checks=*,-fuchsia*"
? If someone is specifically targeting Fuchsia they probably need to disable some other default checks than modernize as well...
I tried to look for answers from early issues but was still confused if it was possible or impossible or on the to-do list.
I think both clang-format and clang-tidy usually need multiple arguments for customization.
Sorry if I missed any critical document already described it.
Hi!
I am trying to configure the pre-commit hook with oclint.
What I am noticing is that while executing the commit the program is executed but...
as an example this is the output that I get from a test application:
oclint...................................................................Failed
- hook id: oclint
- exit code: 5
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=3[0]
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=2[0]
oclint: error: violations exceed threshold
P1=0[0] P2=1[0] P3=1[0]
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=3[0]
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=4[0]
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=1[0]
oclint: error: violations exceed threshold
P1=0[0] P2=2[0] P3=3[0]
oclint: error: violations exceed threshold
P1=0[0] P2=0[0] P3=1[0]
If I try to attach the html output in the configuration yaml, then the file is always rewritten with the last run. If I execute oclint from command line, then, I have an html file that groups all the outputs from every file.
At line 28 of hooks/utils.py
, the comment says that this would capture the target files from the configuration file, but it seems to me that in reality the only file regex that it uses are the ones that are hardcoded, right after those lines.
Is that an actual error and/or are there plans to fix that?
def set_file_regex(self):
"""Get the file regex for a command's target files from the .pre-commit-hooks.yaml."""
Traceback (most recent call last):
File "/home/dave/.cache/pre-commit/repov7j0xgwa/py_env-python3.8/bin/uncrustify-hook", line 8, in <module>
sys.exit(main())
File "/home/dave/.cache/pre-commit/repov7j0xgwa/py_env-python3.8/lib/python3.8/site-packages/hooks/uncrustify.py", line 53, in main
cmd.run()
File "/home/dave/.cache/pre-commit/repov7j0xgwa/py_env-python3.8/lib/python3.8/site-packages/hooks/uncrustify.py", line 45, in run
self.compare_to_formatted(filename)
File "/home/dave/.cache/pre-commit/repov7j0xgwa/py_env-python3.8/lib/python3.8/site-packages/hooks/utils.py", line 164, in compare_to_formatted
actual = self.get_filelines(filename)
File "/home/dave/.cache/pre-commit/repov7j0xgwa/py_env-python3.8/lib/python3.8/site-packages/hooks/utils.py", line 203, in get_filelines
return str(filetext, encoding="utf-8").split("\n")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 631: invalid start byte
Perhaps an additional parameter in the yaml file? It can default to UTF-8, but allow the user to configure it if they want something else?
Thanks for the great hooks!
My interpretation of the documentation was that --version=X
would try to enforce using version X of a linter. However, it seems that it only validates the correct version is used.
E.g. in one of my ubuntu machines, the clang-format
binary is at version 10, but version 11 is also installed (as clang-format-11
).
Would it make sense that --version=11
would try to use the latter? Otherwise, could we have a knob exposed for the binary that the hook will use?
Hello,
Thank you for these hooks. They're great.
I am using clang-format hook.
I'd like to check version of clang-format tool but I think it is too strict.
I'd like to put in my config '--version=6.0'. But some people in my team are using version '6.0.1' while others are using version '6.0.0-1ubuntu2'.
I would be nice to be able to specify a version pattern instead of a strict version. Or use Semantic Versioning if it makes sense.
Pre-commit does not find stagged vala file.
As I saw you comment here, it seems that this hook does not work with vala
pre-commit-hooks/.pre-commit-hooks.yaml
Line 28 in 336fdd7
I just want to get a comfirm before going in the rabbit hole, is this possible?
Usually compile_commands.json
is created by the build system at the build or generation time. It is never stored in a repo.
Is it possible to add extra option so the database is generated automatically somehow? I can think of this syntax:
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: python
hooks:
- id: clang-tidy
args: [-p __compdb/compile_commands.json]
generate_compile_commands: ["mkdir __compdb", "cd __compdb", "cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"]
Is something like this available? Would it make sense?
How can configure the hook to run against my own .clang-format settings files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.