summaryrefslogtreecommitdiff
path: root/test/Format
diff options
context:
space:
mode:
authorPaul Hoad <mydeveloperday@gmail.com>2019-10-12 15:36:05 +0000
committerPaul Hoad <mydeveloperday@gmail.com>2019-10-12 15:36:05 +0000
commite8a69024320059ce0ec36980520bb3de7c0dedd0 (patch)
treebcefab477b3d951106e836cf69d8007a21ede580 /test/Format
parentb96f4ed98396fcd5e5e74efe93746c2200599ddf (diff)
downloadclang-e8a69024320059ce0ec36980520bb3de7c0dedd0.tar.gz
[clang-format] Proposal for clang-format to give compiler style warnings
Summary: Related somewhat to {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" > ^ ``` Reviewers: mitchell-stellar, klimek, owenpan Reviewed By: klimek Subscribers: mgorny, cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D68554 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Format')
-rw-r--r--test/Format/dry-run-alias.cpp4
-rw-r--r--test/Format/dry-run.cpp4
2 files changed, 8 insertions, 0 deletions
diff --git a/test/Format/dry-run-alias.cpp b/test/Format/dry-run-alias.cpp
new file mode 100644
index 0000000000..e58d4cd747
--- /dev/null
+++ b/test/Format/dry-run-alias.cpp
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i -n %s 2> %t.stderr
+// RUN: grep -E "*code should be clang-formatted*" %t.stderr
+
+int a ;
diff --git a/test/Format/dry-run.cpp b/test/Format/dry-run.cpp
new file mode 100644
index 0000000000..9d6cd34204
--- /dev/null
+++ b/test/Format/dry-run.cpp
@@ -0,0 +1,4 @@
+// RUN: clang-format -style=LLVM -i --dry-run %s 2> %t.stderr
+// RUN: grep -E "*code should be clang-formatted*" %t.stderr
+
+int a ;