[PATCH] D54881: Prevent Clang-Format from editing leading whitespace on lines outside of the format range
Russell McClellan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 25 14:32:12 PST 2018
russellmcc created this revision.
russellmcc added a reviewer: djasper.
Herald added a subscriber: cfe-commits.
When clang-format is set to always use tabs (with tab width 4), when asked to format line 3 (using the `-lines=3:3` flag):
int f() {
int a;
foobar();
int b;
}
We would expect clang-format to not modify the leading whitespace on line 4. However, it does - see the new test. This is because the whitespace manager is called to replace the whitespace before the first token of line 4. This is necessary to edit the number of new lines before line 4, and to edit the trailing whitespace on line 3. I've added a flag to `replaceWhitespace` that allows it to not edit the leading whitespace, and only edit the whitespace up to the last newline.
We ran into this when trying to integrate clang-format into our CI to ensure no new formatting diffs were introduced in a patch. With the behavior without this patch, the number of affected lines grew each time clang-format was run, so running clang-format locally was not enough to ensure that CI would pass.
Repository:
rC Clang
https://reviews.llvm.org/D54881
Files:
lib/Format/UnwrappedLineFormatter.cpp
lib/Format/UnwrappedLineFormatter.h
lib/Format/WhitespaceManager.cpp
lib/Format/WhitespaceManager.h
unittests/Format/FormatTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54881.175184.patch
Type: text/x-patch
Size: 7247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181125/cdfa310b/attachment.bin>
More information about the cfe-commits
mailing list