Caphyon / clang-power-tools

Bringing clang-tidy magic to Visual Studio C++ developers.
http://www.clangpowertools.com
Apache License 2.0
472 stars 57 forks source link

Ability to Execute Clang-Tidy Workloads without Applying .clang-tidy Configuration #1339

Closed lursyy closed 4 months ago

lursyy commented 4 months ago

We have an .clang-tidy file in our repository root, which specifies some Checks, CheckOptions, FormatStyle, as well as WarningsAsErrors: '*', and is currently only used in the IDE via Resharper (not in any CI / refactoring manner, yet).

For a large refactoring, I might want to execute a tidy(-fix) workload focusing on a single check, and maybe configure some CheckOptions differently than in the .clang-tidy file. As far as I can tell however, the flags passed to tidy or tidy-fix only affect the -checks passed to clang-tidy.exe. Therefore, calling clang-build.ps1 -tidy "-*,readability-braces-around-statements" still takes into account the other options from the .clang-tidy file mentioned above.

Question: Is there a way to either ignore the .clang-tidy file completely, or override additional clang-tidy options besides just the checks? The way I noticed this is that the script aborts due to the checks being emitted as warnings. The parameter description in the powershell script suggests that the .clang-tidy file is only considered when passing ".clang-tidy" to the workload.

I am not sure if my use cases [^1] [^2] are valid, maybe we can discuss. In any case, thanks for the great work!

[^1]: Regarding WarningsAsErrors: In our case, we can actually remove the option from our .clang-tidy file, since it serves no other purpose (yet). But I think there might be other cases where one needs to have this enabled? The -continue option does not solve this issue either, if I understand correctly. [^2]: Regarding the other use case of overriding the CheckOptions, one might ask why this is necessary, since normally you would want to execute a refactoring with the same options that are used elsewhere for the check. The only "use case" here is experimenting locally with some checks and not having to edit the working copy of .clang-tidy.

mariru27 commented 4 months ago

Hi @lursyy,

Here you can find more information about clang-build.ps1 parameters.

However, we do not control the .clang-tidy search criteria (it is detected automatically). A workaround that we use is to move .clang-tidy (with needed checks) in %temp% and specify .clang-tidy temp path.

Custom config file: e.g. --config-file=/some/path/myTidyConfigFile. In this case clang-tidy is forced to use custom path.

If you want to use this workaround, do not forget to respect .clang-tidy format, you ca use Clang Power Tools UI from Visual Studio to export the file.

image

Kind regards, Marina

lursyy commented 4 months ago

A workaround that we use is to move .clang-tidy (with needed checks) in %temp% and specify .clang-tidy temp path.

Ah, I did not think of that. Good enough for me :) thanks!