使用clang-tidy输出格式问题

时间:2018-08-13 17:26:25

标签: clang-format clang-tidy

是否可以设置clang-tidy来输出在.clang-format文件中定义的源代码格式中发现的问题。基本上,告诉您如果在文件上运行clang格式会进行哪些更改。类似于:

Line 23: improper indentation, 4 spaces should be used

Line 47: opening brace for loops should be on the same line

如果没有,是否可以编写自定义检查,这对我有帮助?

1 个答案:

答案 0 :(得分:0)

您无法用clang-tidy做到这一点,因为它会将代码解析为AST,并且不关心格式。

您可以将clang-format-output-replacements-xml选项一起使用。

该xml输出将告诉您您想要什么(发生了什么变化以及在哪里进行更改),但是不会为人类读者带来很好的输出。

示例:

<?xml version='1.0'?>
<replacements xml:space='preserve' incomplete_format='false'>
<replacement offset='337' length='8'>&#13;&#10;&#13;&#10;  </replacement>
</replacements>