Issue 1042 in include-what-you-use: [question] Pre-commit hook

291 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
May 5, 2022, 6:56:30 PM5/5/22
to include-wh...@googlegroups.com
New issue 1042 by xmnlab: [question] Pre-commit hook
https://github.com/include-what-you-use/include-what-you-use/issues/1042

Hi all!

I would like to add iwyu to my git pre-commit hook workflow.
does anyone have any experience with that?

currently, I am doing a very ugly workaround. I created a script where will execute the iwyu and redirect the results to a file and I use a `grep` to check if there any match for `The full include-list for`

https://github.com/arxlang/arx/pull/33/files#diff-167493c0b2324ad6aa87e4acd8e9a5a83acd617eaae8127fb53156228a35a71fR1

and I execute it from the pre-commit config file:

https://github.com/arxlang/arx/pull/33/files#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9R17

any better recommendation for that?

also, could I use it with `fix_includes.py` by change in the pre-commit hook?

thanks!


notifi...@include-what-you-use.org

unread,
May 7, 2022, 9:43:56 AM5/7/22
to include-wh...@googlegroups.com
Comment #1 on issue 1042 by kimgr: [question] Pre-commit hook
https://github.com/include-what-you-use/include-what-you-use/issues/1042

I don't have commit hook skills, but it feels like a sensitive place to do rewrites with `fix_includes.py`. IWYU has bugs, and it's a really bad time to munge your source code when trying to commit it to persistent history :-)


notifi...@include-what-you-use.org

unread,
May 7, 2022, 10:13:42 PM5/7/22
to include-wh...@googlegroups.com
Comment #2 on issue 1042 by xmnlab: [question] Pre-commit hook
https://github.com/include-what-you-use/include-what-you-use/issues/1042

thanks for your answer @kimgr. when you use a git commit with any git commit hook, if it hit any issue or if it change any file, it normally raises an error and the commit is blocked, so in order to finish it, you should run it again (and fix any issue pointed) in order to finish the commit. for python, for example, we can use black (general code auto formatter) and isort (for ordering the imports).

but as you pointed that IWYU has bugs, maybe it would be hard to force it as a pre-commit hook.

thank you so much for your explanation!


Reply all
Reply to author
Forward
0 new messages