summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/SortIncludesTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Allow additional file suffixes/extensions considered as source in main ↵mydeveloperday2019-11-121-0/+51
| | | | | | | | | | | | | | | | | | | | | include grouping Summary: By additional regex match, grouping of main include can be enabled in files that are not normally considered as a C/C++ source code. For example, this might be useful in templated code, where template implementations are being held in *Impl.hpp files. On the occassion, 'assume-filename' option description was reworded as it was misleading. It has nothing to do with `style=file` option and it does not influence sourced style filename. Reviewers: rsmith, ioeric, krasimir, sylvestre.ledru, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Patch by: furdyna Tags: #clang Differential Revision: https://reviews.llvm.org/D67750
* [clang-format] [PR43372] - clang-format shows replacements in DOS files when ↵Paul Hoad2019-10-011-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | no replacement is needed Summary: This is a patch to fix PR43372 (https://bugs.llvm.org/show_bug.cgi?id=43372) - clang-format can't format file with includes, ( which really keep providing replacements for already sorted headers.) A similar issue was addressed by @krasimir in {D60199}, however, this seemingly only prevented the issue when the files being formatted did not contain windows line endings (\r\n) It's possible this is related to https://twitter.com/StephanTLavavej/status/1176722938243895296 given who @STL_MSFT works for! As people often used the existence of replacements to determine if a file needs clang-formatting, this is probably pretty important for windows users There may be a better way of comparing 2 strings and ignoring \r (which appear in both Results and Code), I couldn't choose between this idiom or the copy_if approach, but I'm happy to change it to whatever people consider more performant. Reviewers: krasimir, klimek, owenpan, ioeric Reviewed By: krasimir Subscribers: cfe-commits, STL_MSFT, krasimir Tags: #clang-format, #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D68227 llvm-svn: 373388
* [SortIncludesTest] Add SortPriority fields to fix ↵Mikael Holmen2019-09-261-2/+2
| | | | | | -Wmissing-field-initializers after D64695/r372919 llvm-svn: 372944
* [clang-format] Modified SortIncludes and IncludeCategories to priority for ↵Paul Hoad2019-09-251-0/+71
| | | | | | | | | | | | | | | | | | | | | | | | | sorting #includes within the Group Category. Summary: This new Style rule is made as a part of adding support for NetBSD KNF in clang-format. NetBSD have it's own priority of includes which should be followed while formatting NetBSD code. This style sorts the Cpp Includes according to the priorities of NetBSD, as mentioned in the [Style Guide](http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup) The working of this Style rule shown below: **Configuration:** This revision introduces a new field under IncludeCategories named `SortPriority` which defines the priority of ordering the `#includes` and the `Priority` will define the categories for grouping the `#include blocks`. Reviewers: cfe-commits, mgorny, christos, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: lebedev.ri, rdwampler, christos, mgorny, krytarowski Patch By: Manikishan Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D64695 llvm-svn: 372919
* [clang-format] Preserve include blocks in ObjC Google styleKrasimir Georgiev2019-04-041-0/+12
| | | | | | | | | | | | | | | | | | Summary: r357567 started to regroup include block for Google style; it was meant to apply only for C++. This patch reverts this for ObjC. Reviewers: ioeric Reviewed By: ioeric Subscribers: thakis, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60263 llvm-svn: 357695
* [clang-format] Do not emit replacements while regrouping if Cpp includes are OKKrasimir Georgiev2019-04-031-9/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Currently clang-format would always emit a replacement for multi-block #include sections if `IBS_Regroup`, even if the sections are correct: ``` % cat ~/test.h #include <a.h> #include "b.h" % bin/clang-format --output-replacements-xml -style=google ~/test.h <?xml version='1.0'?> <replacements xml:space='preserve' incomplete_format='false'> <replacement offset='0' length='30'>#include &lt;a.h>&#10;&#10;#include "b.h"</replacement> </replacements> % ``` This change makes clang-format not emit replacements in this case. The logic is similar to the one implemented for Java in r354452. Reviewers: ioeric Reviewed By: ioeric Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60199 llvm-svn: 357599
* [clang-format] Regroup #includes into blocks for Google styleEric Liu2019-04-031-3/+13
| | | | | | | | | | | | | | | | | Summary: Regrouping #includes in blocks separated by blank lines when sorting C++ #include headers was implemented recently, and it has been preferred in Google's C++ style guide: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes Reviewers: sammccall, klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60116 llvm-svn: 357567
* [clang-format] clang-format off/on not respected when using C Style commentsPaul Hoad2019-03-021-0/+37
| | | | | | | | | | | | | | | | | | | Summary: If the clang-format on/off is in a /* comment */ then the sorting of headers is not ignored PR40901 - https://bugs.llvm.org/show_bug.cgi?id=40901 Reviewers: djasper, klimek, JonasToth, krasimir, alexfh Reviewed By: alexfh Subscribers: alexfh, cfe-commits, llvm-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D58819 llvm-svn: 355266
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-format] Move #include related style to libToolingCoreEric Liu2018-05-141-22/+22
| | | | | | | | | | | | | | Summary: This will be shared by include insertion/deletion library. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgorny, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D46758 llvm-svn: 332284
* [clang-format] Add option to group multiple #include blocks when sorting ↵Krasimir Georgiev2017-11-271-0/+182
| | | | | | | | | | | | | | | | | | | | includes Summary: This patch allows grouping multiple #include blocks together and sort all includes as one big block. Additionally, sorted includes can be regrouped after sorting based on configured categories. Contributed by @KrzysztofKapusta! Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D40288 llvm-svn: 319024
* [clang-format] Do not format likely xmlKrasimir Georgiev2017-08-291-0/+11
| | | | | | | | | | | | | | | | | Summary: This patch detects the leading '<' in likely xml files and stops formatting in that case. A recent use of a Qt xml file with a .ts extension triggered this: http://doc.qt.io/qt-4.8/linguist-ts-file-format.html Reviewers: djasper Reviewed By: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37136 llvm-svn: 311999
* [clang-format] Switch to case-insensitive header matching and use it toChandler Carruth2017-06-291-0/+23
| | | | | | | | | | | | | | | | | | | | | | | improve support for LLVM-style include sorting. This really is a collection of improvements to the rules for LLVM include sorting: - We have gmock headers now, so it adds support for those to one of the categories. - LLVM does use 'FooTest.cpp' files to test 'Foo.h' so it adds that suffix for finding a main header. - At times the test file's case may not match the header file's case, so switch to case-insensitive regex matching of header names. With this set of changes, I can't spot any misbehaviors when re-sorting all of LLVM's unittest '#include' lines. Thanks to Eric and Daniel for help testing and refining the patch during review! Differential Revision: https://reviews.llvm.org/D33932 llvm-svn: 306759
* clang-format: Correctly calculate affected ranges when sorting #includes.Daniel Jasper2016-08-301-2/+14
| | | | | | affectedRanges takes a start and an end offset, not offset and length. llvm-svn: 280165
* Make clang-format remove duplicate headers when sorting #includes.Eric Liu2016-08-101-6/+83
| | | | | | | | | | | | Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23274 llvm-svn: 278206
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-3/+6
| | | | | | | | | | | | | | | | empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
* clang-format: Make include sorting's main include detection configurable.Daniel Jasper2016-03-211-1/+20
| | | | | | | | | | This patch adds a regular expression to configure suffixes of an included file to check whether it is the "main" include of the current file. Previously, clang-format has allowed arbitrary suffixes on the formatted file, which is still the case when no IncludeMainRegex is specified. llvm-svn: 263943
* clang-format: Use stable_sort when sorting #includes.Daniel Jasper2016-03-031-4/+18
| | | | | | | Otherwise, clang-format can output useless replacements in the presence of identical #includes llvm-svn: 262630
* clang-format: Only consider the first #include that looks right to beDaniel Jasper2015-12-211-0/+11
| | | | | | the main #include. llvm-svn: 256170
* clang-format: Only try to find the "main" include in the first block ofDaniel Jasper2015-12-211-0/+13
| | | | | | includes. llvm-svn: 256153
* clang-format: Extend detection of the "main" #include to use the filenameDaniel Jasper2015-12-211-5/+25
| | | | | | | | | | | Before, the first (non-system) header in a file was considered to be the main include. This is conservative as it makes clang-format change the #include order less often. Instead implement some basic usage of the filename itself. With this patch, clang-format considers every header to be a main include if the header file's basename is a prefix to the filename the #include is in. llvm-svn: 256148
* clang-format: Extend header sort category implementation.Daniel Jasper2015-12-161-0/+8
| | | | | | | | | | Specifically, it is sometimes necessary to keep certain #includes as the first #include, even before the main #include for a .cc file. Switching the category to be signed instead of unsigned isn't ideal, but it seems as good of an option as any and is fully backwards compatible. llvm-svn: 255757
* clang-format: Make moving of the Cursor work properly when sorting #includes.Daniel Jasper2015-11-231-0/+20
| | | | llvm-svn: 253860
* clang-format: Make sorting includes respect // clang-format offDaniel Jasper2015-11-211-0/+19
| | | | llvm-svn: 253772
* clang-format: Enable #include sorting by default.Daniel Jasper2015-11-161-0/+10
| | | | | | | | | This has seen quite some usage and I am not aware of any issues. Also add a style option to enable/disable include sorting. The existing command line flag can from now on be used to override whatever is set in the style. llvm-svn: 253202
* clang-format: Teach --sort-includes to interleave #include and #import.Nico Weber2015-10-211-0/+9
| | | | | | | | | | clang accepts both #include and #import for includes (the latter having an implicit header guard). Let clang-format interleave both types if --sort-includes is passed. #import is used frequently in Objective-C code. http://reviews.llvm.org/D13853 llvm-svn: 250909
* clang-format: Extend main header include sorting heuristic to Objective-C files.Nico Weber2015-10-191-0/+7
| | | | llvm-svn: 250675
* clang-format: Extend #include sorting functionalityDaniel Jasper2015-09-291-7/+37
| | | | | | | | | Recognize the main module header as well as different #include categories. This should now mimic the behavior of llvm/utils/sort_includes.py as well as clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp very closely. llvm-svn: 248782
* clang-format: Add initial #include sorting capabilities.Daniel Jasper2015-09-231-0/+108
To implement this nicely, add a function that merges two sets of replacements that are meant to be done in sequence. This functionality will also be useful for other applications, e.g. formatting the result of clang-tidy fixes. llvm-svn: 248367
OpenPOWER on IntegriCloud