[PATCH] D68554: [clang-format] Proposal for clang-format to give compiler style warnings

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 6 09:01:52 PDT 2019


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: mitchell-stellar, klimek, owenpan.
MyDeveloperDay added projects: clang-format, clang-tools-extra.
Herald added a subscriber: mgorny.
Herald added a project: clang.

Related somewhat to D29039: [clang-format] Proposal for clang-format -r option <https://reviews.llvm.org/D29039>

On seeing a quote on twitter by @invalidop

> If it's not formatted with clang-format it's a build error.

This made me want to change the way I use clang-format into a tool that could optionally show me where my source code violates clang-format syle.

When I'm making a change to clang-format itself, one thing I like to do to test the change is to ensure I didn't cause a huge wave of changes, what I want to do is simply run this on a known formatted directory and see if any new differences arrive in a manner I'm used to.

This started me thinking that we should allow build systems to run clang-format on a whole tree and emit compiler style warnings about files that fail clang-format in a form that would make them as a warning in most build systems and because those build systems range in their construction I don't think its unreasonable to NOT expect them to have to do the directory searching or parsing the output replacements themselves, but simply transform that into an error code when there are changes required.

I am starting this by suggesing adding a -n or -dry-run command line argument which would emit a warning/error of the form

Support for various common compiler command line argumuments like '-Werror' and '-ferror-limit' could make this very flexible to be integrated into build systems and CI systems.

  > $ /usr/bin/clang-format --dry-run ClangFormat.cpp -ferror-limit=3 -fcolor-diagnostics
  > ClangFormat.cpp:54:29: warning: code should be clang-formatted [-Wclang-format-violations]
  > static cl::list<std::string>
  >                             ^
  > ClangFormat.cpp:55:20: warning: code should be clang-formatted [-Wclang-format-violations]
  > LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
  >                    ^
  > ClangFormat.cpp:55:77: warning: code should be clang-formatted [-Wclang-format-violations]
  > LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
  >                                                                             ^


Repository:
  rC Clang

https://reviews.llvm.org/D68554

Files:
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-format/ClangFormat.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68554.223426.patch
Type: text/x-patch
Size: 6858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191006/3b191e3f/attachment-0001.bin>


More information about the cfe-commits mailing list