Comments (8)
Thank you for reporting this issue. Off the top of my head, I would try using a comma instead of an equals like so:
args: [-p, /home/user/projects/myproject/build]
Failing that, please provide a Minimal Reproducible Example, including the error message.
from pre-commit-hooks.
Unfortunately, your suggestion doesn't work for me. Here you can see the minimal reproducible example mre.zip. Conan is required since it puts external libraries into its own path so clang-tidy cannot locate them even if '-p' argument is set in the parameter list. By the way, I want to be able to set a relative path not an absolute one.
from pre-commit-hooks.
I believe I have this same issue. Does pre-commit always use the project root as the current working directory, or does it use the actual cwd? Being able to specify things relative to the project root would be ideal.
from pre-commit-hooks.
Update: This is still an issue for me. The intended behavior would be to provide the location of the build
directory relative to the project root. For example, both [-p, build]
, and [-p=build]
fail, but if I manually run clang-tidy (not the hook), with clang-tidy -p=build my_file.cpp
, it works.
I attempted to get around this by using [-p=$(git rev-parse --show-toplevel)/build]
but that didn't work either, as it doesn't appear as though the shell command was expanded.
(See here for an explanation of the git command)
from pre-commit-hooks.
I'm sorry this is still an issue for you. I haven't had time to look at this properly. If you can make a PR, I would be happy to merge.
from pre-commit-hooks.
@sparfenyuk I've attempted to use your MRE and I see the same 3 errors with the pre-commit config hook as clang-tidy with the same arguments. This is after building it with cmake with the commands provided (on Macos 10.14).
Note: I have also made a python branch of this repo (use rev: python
), which should play nicer with relative file names.
clang-tidy with arguments
build rj$ clang-tidy src/* -checks=* -warnings-as-errors=* -p ../build
Error while trying to load a compilation database:
Could not auto-detect compilation database from directory "../build"
No compilation database found in /Users/rj/code/mre/../build 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 processing /Users/rj/code/mre/src/CMakeLists.txt.
396 warnings and 2 errors generated.
Error while processing /Users/rj/code/mre/src/main.cpp.
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
/Users/rj/code/mre/src/main.cpp:1:10: error: 'opencv2/opencv.hpp' file not found [clang-diagnostic-error]
#include <opencv2/opencv.hpp>
^
/Users/rj/code/mre/src/main.cpp:3:14: error: parameter 'argc' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
^~~~
/*argc*/
/Users/rj/code/mre/src/main.cpp:3:27: error: parameter 'argv' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
^~~~
/*argv*/
Suppressed 394 warnings (394 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.
2 warnings treated as errors
Same output from clang-tidy hook
clang-tidy...............................................................Failed
hookid: clang-tidy
Error while processing /Users/rj/code/mre/src/main.cpp.
/Users/rj/code/mre/src/main.cpp:1:10: error: 'opencv2/opencv.hpp' file not found [clang-diagnostic-error]
#include <opencv2/opencv.hpp>
^
/Users/rj/code/mre/src/main.cpp:3:14: error: parameter 'argc' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
^~~~
/*argc*/
/Users/rj/code/mre/src/main.cpp:3:27: error: parameter 'argv' is unused [misc-unused-parameters,-warnings-as-errors]
int main(int argc, char** argv)
^~~~
/*argv*/
Suppressed 393 warnings (393 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.
2 warnings treated as errors
from pre-commit-hooks.
@TheButlah Pre-commit should use project root as cwd.
from pre-commit-hooks.
Closing as I was adding --
-DCMAKEOPTIONS=ON
to suppress no compilation database errors in the bash version, which likely caused this issue. The python version checks for -p
and --
options first.
from pre-commit-hooks.
Related Issues (20)
- Add ability to only lint/analyze committed lines
- Resolve Tooling and support multiple version of clang-tidy HOT 3
- run clang-format againt own .clang-format file HOT 2
- file regex not read from the configuration file HOT 10
- clang-format stops working when using --version HOT 5
- oclint multiple execution and inability to see the output HOT 4
- Class ClangTidyCmd disregards its `args` parameter HOT 2
- Incorrect order of arguments for include-what-you-use?
- can I add few more arguments for clang-format and clang-tidy? HOT 2
- clang-tidy file exclude pattern ignored
- LLVM really includes clang-format and clang-tidy?
- clang format failed HOT 2
- include-what-you-use does not fail
- add_if_missing() does not allow multiple --suppress arguments HOT 2
- Configurable `uncrustify` executable path for the uncrustify hook HOT 2
- clang-tidy: for the -p option: may not occur within a group! HOT 1
- Use a clang-format file that isn't at the root of the repo
- Mistake in comment ? HOT 1
- file not found [clang-diagnostic-error] #include "lib1.h" ^~~~~~~~ HOT 2
- Example hook config for vala
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pre-commit-hooks.