1 //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Various functions to configurably format source code.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
16 #define LLVM_CLANG_FORMAT_FORMAT_H
18 #include "clang/Basic/LangOptions.h"
19 #include "clang/Tooling/Core/Replacement.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include <system_error>
27 class DiagnosticConsumer;
35 enum class ParseError { Success = 0, Error, Unsuitable };
36 class ParseErrorCategory final : public std::error_category {
38 const char *name() const noexcept override;
39 std::string message(int EV) const override;
41 const std::error_category &getParseCategory();
42 std::error_code make_error_code(ParseError e);
44 /// \brief The ``FormatStyle`` is used to configure the formatting to follow
45 /// specific guidelines.
47 /// \brief The extra indent or outdent of access modifiers, e.g. ``public:``.
48 int AccessModifierOffset;
50 /// \brief Different styles for aligning after open brackets.
51 enum BracketAlignmentStyle {
52 /// \brief Align parameters on the open bracket, e.g.:
54 /// someLongFunction(argument1,
58 /// \brief Don't align, instead use ``ContinuationIndentWidth``, e.g.:
60 /// someLongFunction(argument1,
64 /// \brief Always break after an open bracket, if the parameters don't fit
65 /// on a single line, e.g.:
68 /// argument1, argument2);
73 /// \brief If ``true``, horizontally aligns arguments after an open bracket.
75 /// This applies to round brackets (parentheses), angle brackets and square
77 BracketAlignmentStyle AlignAfterOpenBracket;
79 /// \brief If ``true``, aligns consecutive assignments.
81 /// This will align the assignment operators of consecutive lines. This
82 /// will result in formattings like
88 bool AlignConsecutiveAssignments;
90 /// \brief If ``true``, aligns consecutive declarations.
92 /// This will align the declaration names of consecutive lines. This
93 /// will result in formattings like
97 /// std::string ccc = 23;
99 bool AlignConsecutiveDeclarations;
101 /// \brief Different styles for aligning escaped newlines.
102 enum EscapedNewlineAlignmentStyle {
103 /// \brief Don't align escaped newlines.
111 /// \brief Align escaped newlines as far left as possible.
122 /// \brief Align escaped newlines in the right-most column.
132 /// \brief Options for aligning backslashes in escaped newlines.
133 EscapedNewlineAlignmentStyle AlignEscapedNewlines;
135 /// \brief If ``true``, horizontally align operands of binary and ternary
138 /// Specifically, this aligns operands of a single expression that needs to be
139 /// split over multiple lines, e.g.:
141 /// int aaa = bbbbbbbbbbbbbbb +
146 /// \brief If ``true``, aligns trailing comments.
149 /// int a; // My comment a vs. int a; // My comment a
150 /// int b = 2; // comment b int b = 2; // comment about b
152 bool AlignTrailingComments;
154 /// \brief If the function declaration doesn't fit on a line,
155 /// allow putting all parameters of a function declaration onto
156 /// the next line even if ``BinPackParameters`` is ``false``.
160 /// int a, int b, int c, int d, int e);
163 /// void myFunction(int a,
169 bool AllowAllParametersOfDeclarationOnNextLine;
171 /// \brief Allows contracting simple braced statements to a single line.
173 /// E.g., this allows ``if (a) { return; }`` to be put on a single line.
174 bool AllowShortBlocksOnASingleLine;
176 /// \brief If ``true``, short case labels will be contracted to a single line.
179 /// switch (a) { vs. switch (a) {
180 /// case 1: x = 1; break; case 1:
181 /// case 2: return; x = 1;
187 bool AllowShortCaseLabelsOnASingleLine;
189 /// \brief Different styles for merging short functions containing at most one
191 enum ShortFunctionStyle {
192 /// \brief Never merge functions into a single line.
194 /// \brief Only merge functions defined inside a class. Same as "inline",
195 /// except it does not implies "empty": i.e. top level empty functions
196 /// are not merged either.
199 /// void f() { foo(); }
208 /// \brief Only merge empty functions.
216 /// \brief Only merge functions defined inside a class. Implies "empty".
219 /// void f() { foo(); }
227 /// \brief Merge all functions fitting on a single line.
230 /// void f() { foo(); }
232 /// void f() { bar(); }
237 /// \brief Dependent on the value, ``int f() { return 0; }`` can be put on a
239 ShortFunctionStyle AllowShortFunctionsOnASingleLine;
241 /// \brief If ``true``, ``if (a) return;`` can be put on a single line.
242 bool AllowShortIfStatementsOnASingleLine;
244 /// \brief If ``true``, ``while (true) continue;`` can be put on a single
246 bool AllowShortLoopsOnASingleLine;
248 /// \brief Different ways to break after the function definition return type.
249 /// This option is **deprecated** and is retained for backwards compatibility.
250 enum DefinitionReturnTypeBreakingStyle {
251 /// Break after return type automatically.
252 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
254 /// Always break after the return type.
256 /// Always break after the return types of top-level functions.
260 /// \brief Different ways to break after the function definition or
261 /// declaration return type.
262 enum ReturnTypeBreakingStyle {
263 /// Break after return type automatically.
264 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
267 /// int f() { return 0; };
270 /// int f() { return 1; }
273 /// Always break after the return type.
289 /// Always break after the return types of top-level functions.
292 /// int f() { return 0; };
302 /// Always break after the return type of function definitions.
317 /// Always break after the return type of top-level definitions.
320 /// int f() { return 0; };
328 RTBS_TopLevelDefinitions,
331 /// \brief The function definition return type breaking style to use. This
332 /// option is **deprecated** and is retained for backwards compatibility.
333 DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
335 /// \brief The function declaration return type breaking style to use.
336 ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
338 /// \brief If ``true``, always break before multiline string literals.
340 /// This flag is mean to make cases where there are multiple multiline strings
341 /// in a file look more consistent. Thus, it will only take effect if wrapping
342 /// the string at that point leads to it being indented
343 /// ``ContinuationIndentWidth`` spaces from the start of the line.
346 /// aaaa = vs. aaaa = "bbbb"
350 bool AlwaysBreakBeforeMultilineStrings;
352 /// \brief If ``true``, always break after the ``template<...>`` of a template
356 /// template <typename T> vs. template <typename T> class C {};
359 bool AlwaysBreakTemplateDeclarations;
361 /// \brief If ``false``, a function call's arguments will either be all on the
362 /// same line or will have one line each.
366 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
367 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
372 /// f(aaaaaaaaaaaaaaaaaaaa,
373 /// aaaaaaaaaaaaaaaaaaaa,
374 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
377 bool BinPackArguments;
379 /// \brief If ``false``, a function declaration's or function definition's
380 /// parameters will either all be on the same line or will have one line each.
383 /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
384 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
387 /// void f(int aaaaaaaaaaaaaaaaaaaa,
388 /// int aaaaaaaaaaaaaaaaaaaa,
389 /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
391 bool BinPackParameters;
393 /// \brief The style of breaking before or after binary operators.
394 enum BinaryOperatorStyle {
395 /// Break after operators.
397 /// LooooooooooongType loooooooooooooooooooooongVariable =
398 /// someLooooooooooooooooongFunction();
400 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
401 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
402 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
403 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
404 /// ccccccccccccccccccccccccccccccccccccccccc;
407 /// Break before operators that aren't assignments.
409 /// LooooooooooongType loooooooooooooooooooooongVariable =
410 /// someLooooooooooooooooongFunction();
412 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
413 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
414 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
415 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
416 /// > ccccccccccccccccccccccccccccccccccccccccc;
419 /// Break before operators.
421 /// LooooooooooongType loooooooooooooooooooooongVariable
422 /// = someLooooooooooooooooongFunction();
424 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
425 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
426 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
427 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
428 /// > ccccccccccccccccccccccccccccccccccccccccc;
433 /// \brief The way to wrap binary operators.
434 BinaryOperatorStyle BreakBeforeBinaryOperators;
436 /// \brief Different ways to attach braces to their surrounding context.
437 enum BraceBreakingStyle {
438 /// Always attach braces to surrounding context.
444 /// void foo() { bar(); }
449 /// enum X : int { A, B };
452 /// Like ``Attach``, but break before braces on function, namespace and
453 /// class definitions.
459 /// void foo() { bar(); }
466 /// enum X : int { A, B };
469 /// Like ``Attach``, but break before braces on enum, function, and record
476 /// void foo() { bar(); }
483 /// enum X : int { A, B };
486 /// Like ``Attach``, but break before function definitions, ``catch``, and
493 /// void foo() { bar(); }
507 /// Always break before braces.
514 /// void foo() { bar(); }
521 /// enum X : int { A, B };
524 /// Always break before braces and add an extra level of indentation to
525 /// braces of control statements, not to those of class, function
526 /// or other definitions.
535 /// void foo() { bar(); }
552 /// Like ``Attach``, but break before functions.
558 /// void foo() { bar(); }
564 /// enum X : int { A, B };
567 /// Configure each individual brace in `BraceWrapping`.
571 /// \brief The brace breaking style to use.
572 BraceBreakingStyle BreakBeforeBraces;
574 /// \brief Precise control over the wrapping of braces.
576 /// # Should be declared this way:
577 /// BreakBeforeBraces: Custom
581 struct BraceWrappingFlags {
582 /// \brief Wrap class definitions.
592 /// \brief Wrap control statements (``if``/``for``/``while``/``switch``/..).
599 /// for (int i = 0; i < 10; ++i)
606 /// for (int i = 0; i < 10; ++i) {
609 bool AfterControlStatement;
610 /// \brief Wrap enum definitions.
619 /// enum X : int { B };
622 /// \brief Wrap function definitions.
638 /// \brief Wrap namespace definitions.
654 /// \brief Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
655 bool AfterObjCDeclaration;
656 /// \brief Wrap struct definitions.
670 /// \brief Wrap union definitions.
684 /// \brief Wrap extern blocks.
697 bool AfterExternBlock;
698 /// \brief Wrap before ``catch``.
714 /// \brief Wrap before ``else``.
728 /// \brief Indent the wrapped braces themselves.
730 /// \brief If ``false``, empty function body can be put on a single line.
731 /// This option is used only if the opening brace of the function has
732 /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
733 /// set, and the function could/should not be put on a single line (as per
734 /// `AllowShortFunctionsOnASingleLine` and constructor formatting options).
736 /// int f() vs. inf f()
741 bool SplitEmptyFunction;
742 /// \brief If ``false``, empty record (e.g. class, struct or union) body
743 /// can be put on a single line. This option is used only if the opening
744 /// brace of the record has already been wrapped, i.e. the `AfterClass`
745 /// (for classes) brace wrapping mode is set.
747 /// class Foo vs. class Foo
752 bool SplitEmptyRecord;
753 /// \brief If ``false``, empty namespace body can be put on a single line.
754 /// This option is used only if the opening brace of the namespace has
755 /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
758 /// namespace Foo vs. namespace Foo
763 bool SplitEmptyNamespace;
766 /// \brief Control of individual brace wrapping cases.
768 /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
769 /// each individual brace case should be handled. Otherwise, this is ignored.
771 /// # Example of usage:
772 /// BreakBeforeBraces: Custom
775 /// AfterStruct: false
776 /// SplitEmptyFunction: false
778 BraceWrappingFlags BraceWrapping;
780 /// \brief If ``true``, ternary operators will be placed after line breaks.
783 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
785 /// : SecondValueVeryVeryVeryVeryLong;
788 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
790 /// SecondValueVeryVeryVeryVeryLong;
792 bool BreakBeforeTernaryOperators;
794 /// \brief Different ways to break initializers.
795 enum BreakConstructorInitializersStyle {
796 /// Break constructor initializers before the colon and after the commas.
799 /// : initializer1(),
803 /// Break constructor initializers before the colon and commas, and align
804 /// the commas with the colon.
811 /// Break constructor initializers after the colon and commas.
820 /// \brief The constructor initializers style to use.
821 BreakConstructorInitializersStyle BreakConstructorInitializers;
823 /// \brief Break after each annotation on a field in Java files.
826 /// @Partial vs. @Partial @Mock DataLoad loader;
830 bool BreakAfterJavaFieldAnnotations;
832 /// \brief Allow breaking string literals when formatting.
833 bool BreakStringLiterals;
835 /// \brief The column limit.
837 /// A column limit of ``0`` means that there is no column limit. In this case,
838 /// clang-format will respect the input's line breaking decisions within
839 /// statements unless they contradict other rules.
840 unsigned ColumnLimit;
842 /// \brief A regular expression that describes comments with special meaning,
843 /// which should not be split into lines or otherwise changed.
845 /// // CommentPragmas: '^ FOOBAR pragma:'
846 /// // Will leave the following line unaffected
847 /// #include <vector> // FOOBAR pragma: keep
849 std::string CommentPragmas;
851 /// \brief If ``true``, in the class inheritance expression clang-format will
852 /// break before ``:`` and ``,`` if there is multiple inheritance.
855 /// class MyClass vs. class MyClass : public X, public Y {
860 bool BreakBeforeInheritanceComma;
862 /// \brief If ``true``, consecutive namespace declarations will be on the same
863 /// line. If ``false``, each namespace is declared on a new line.
866 /// namespace Foo { namespace Bar {
876 /// If it does not fit on a single line, the overflowing namespaces get
879 /// namespace Foo { namespace Bar {
880 /// namespace Extra {
883 bool CompactNamespaces;
885 /// \brief If the constructor initializers don't fit on a line, put each
886 /// initializer on its own line.
889 /// SomeClass::Constructor()
890 /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
895 /// SomeClass::Constructor()
896 /// : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
897 /// aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
901 bool ConstructorInitializerAllOnOneLineOrOnePerLine;
903 /// \brief The number of characters to use for indentation of constructor
904 /// initializer lists.
905 unsigned ConstructorInitializerIndentWidth;
907 /// \brief Indent width for line continuations.
909 /// ContinuationIndentWidth: 2
911 /// int i = // VeryVeryVeryVeryVeryLongComment
912 /// longFunction( // Again a long comment
915 unsigned ContinuationIndentWidth;
917 /// \brief If ``true``, format braced lists as best suited for C++11 braced
920 /// Important differences:
921 /// - No spaces inside the braced list.
922 /// - No line break before the closing brace.
923 /// - Indentation with the continuation indent, not with the block indent.
925 /// Fundamentally, C++11 braced lists are formatted exactly like function
926 /// calls would be formatted in their place. If the braced list follows a name
927 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
928 /// the parentheses of a function call with that name. If there is no name,
929 /// a zero-length name is assumed.
932 /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
933 /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
934 /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
935 /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
937 bool Cpp11BracedListStyle;
939 /// \brief If ``true``, analyze the formatted file for the most common
940 /// alignment of ``&`` and ``*``.
941 /// Pointer and reference alignment styles are going to be updated according
942 /// to the preferences found in the file.
943 /// ``PointerAlignment`` is then used only as fallback.
944 bool DerivePointerAlignment;
946 /// \brief Disables formatting completely.
949 /// \brief If ``true``, clang-format detects whether function calls and
950 /// definitions are formatted with one parameter per line.
952 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
953 /// inconclusive, e.g. completely on one line, but a decision needs to be
954 /// made, clang-format analyzes whether there are other bin-packed cases in
955 /// the input file and act accordingly.
957 /// NOTE: This is an experimental flag, that might go away or be renamed. Do
958 /// not use this in config files, etc. Use at your own risk.
959 bool ExperimentalAutoDetectBinPacking;
961 /// \brief If ``true``, clang-format adds missing namespace end comments and
962 /// fixes invalid existing ones.
965 /// namespace a { vs. namespace a {
967 /// } // namespace a; }
969 bool FixNamespaceComments;
971 /// \brief A vector of macros that should be interpreted as foreach loops
972 /// instead of as function calls.
974 /// These are expected to be macros of the form:
976 /// FOREACH(<variable-declaration>, ...)
980 /// In the .clang-format configuration file, this can be configured like:
982 /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
985 /// For example: BOOST_FOREACH.
986 std::vector<std::string> ForEachMacros;
988 /// \brief Styles for sorting multiple ``#include`` blocks.
989 enum IncludeBlocksStyle {
990 /// \brief Sort each ``#include`` block separately.
992 /// #include "b.h" into #include "b.h"
994 /// #include <lib/main.h> #include "a.h"
995 /// #include "a.h" #include <lib/main.h>
998 /// \brief Merge multiple ``#include`` blocks together and sort as one.
1000 /// #include "b.h" into #include "a.h"
1002 /// #include <lib/main.h> #include <lib/main.h>
1006 /// \brief Merge multiple ``#include`` blocks together and sort as one.
1007 /// Then split into groups based on category priority. See
1008 /// ``IncludeCategories``.
1010 /// #include "b.h" into #include "a.h"
1012 /// #include <lib/main.h>
1013 /// #include "a.h" #include <lib/main.h>
1018 /// \brief Dependent on the value, multiple ``#include`` blocks can be sorted
1019 /// as one and divided based on category.
1020 IncludeBlocksStyle IncludeBlocks;
1022 /// \brief See documentation of ``IncludeCategories``.
1023 struct IncludeCategory {
1024 /// \brief The regular expression that this category matches.
1026 /// \brief The priority to assign to this category.
1028 bool operator==(const IncludeCategory &Other) const {
1029 return Regex == Other.Regex && Priority == Other.Priority;
1033 /// \brief Regular expressions denoting the different ``#include`` categories
1034 /// used for ordering ``#includes``.
1036 /// These regular expressions are matched against the filename of an include
1037 /// (including the <> or "") in order. The value belonging to the first
1038 /// matching regular expression is assigned and ``#includes`` are sorted first
1039 /// according to increasing category number and then alphabetically within
1042 /// If none of the regular expressions match, INT_MAX is assigned as
1043 /// category. The main header for a source file automatically gets category 0.
1044 /// so that it is generally kept at the beginning of the ``#includes``
1045 /// (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1046 /// can also assign negative priorities if you have certain headers that
1047 /// always need to be first.
1049 /// To configure this in the .clang-format file, use:
1051 /// IncludeCategories:
1052 /// - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1054 /// - Regex: '^(<|"(gtest|gmock|isl|json)/)'
1059 std::vector<IncludeCategory> IncludeCategories;
1061 /// \brief Specify a regular expression of suffixes that are allowed in the
1062 /// file-to-main-include mapping.
1064 /// When guessing whether a #include is the "main" include (to assign
1065 /// category 0, see above), use this regex of allowed suffixes to the header
1066 /// stem. A partial match is done, so that:
1067 /// - "" means "arbitrary suffix"
1068 /// - "$" means "no suffix"
1070 /// For example, if configured to "(_test)?$", then a header a.h would be seen
1071 /// as the "main" include in both a.cc and a_test.cc.
1072 std::string IncludeIsMainRegex;
1074 /// \brief Indent case labels one level from the switch statement.
1076 /// When ``false``, use the same indentation level as for the switch statement.
1077 /// Switch statement body is always indented one level more than case labels.
1080 /// switch (fool) { vs. switch (fool) {
1084 /// default: default:
1088 bool IndentCaseLabels;
1090 /// \brief Options for indenting preprocessor directives.
1091 enum PPDirectiveIndentStyle {
1092 /// Does not indent any directives.
1101 /// Indents directives after the hash.
1112 /// \brief The preprocessor directive indenting style to use.
1113 PPDirectiveIndentStyle IndentPPDirectives;
1115 /// \brief The number of columns to use for indentation.
1121 /// if (true, false) {
1126 unsigned IndentWidth;
1128 /// \brief Indent if a function definition or declaration is wrapped after the
1132 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
1133 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1136 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
1137 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1139 bool IndentWrappedFunctionNames;
1141 /// \brief Quotation styles for JavaScript strings. Does not affect template
1143 enum JavaScriptQuoteStyle {
1144 /// Leave string quotes as they are.
1146 /// string1 = "foo";
1147 /// string2 = 'bar';
1150 /// Always use single quotes.
1152 /// string1 = 'foo';
1153 /// string2 = 'bar';
1156 /// Always use double quotes.
1158 /// string1 = "foo";
1159 /// string2 = "bar";
1164 /// \brief The JavaScriptQuoteStyle to use for JavaScript strings.
1165 JavaScriptQuoteStyle JavaScriptQuotes;
1167 /// \brief Whether to wrap JavaScript import/export statements.
1171 /// VeryLongImportsAreAnnoying,
1172 /// VeryLongImportsAreAnnoying,
1173 /// VeryLongImportsAreAnnoying,
1174 /// } from 'some/module.js'
1177 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1179 bool JavaScriptWrapImports;
1181 /// \brief If true, the empty line at the start of blocks is kept.
1184 /// if (foo) { vs. if (foo) {
1189 bool KeepEmptyLinesAtTheStartOfBlocks;
1191 /// \brief Supported languages.
1193 /// When stored in a configuration file, specifies the language, that the
1194 /// configuration targets. When passed to the ``reformat()`` function, enables
1195 /// syntax features specific to the language.
1199 /// Should be used for C, C++.
1201 /// Should be used for Java.
1203 /// Should be used for JavaScript.
1205 /// Should be used for Objective-C, Objective-C++.
1207 /// Should be used for Protocol Buffers
1208 /// (https://developers.google.com/protocol-buffers/).
1210 /// Should be used for TableGen code.
1212 /// Should be used for Protocol Buffer messages in text format
1213 /// (https://developers.google.com/protocol-buffers/).
1216 bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
1218 /// \brief Language, this format style is targeted at.
1219 LanguageKind Language;
1221 /// \brief A regular expression matching macros that start a block.
1224 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
1226 /// MacroBlockEnd: "^\
1228 /// NS_TABLE_.*_END$"
1236 /// NS_TABLE_FOO_END
1245 /// NS_TABLE_FOO_END
1247 std::string MacroBlockBegin;
1249 /// \brief A regular expression matching macros that end a block.
1250 std::string MacroBlockEnd;
1252 /// \brief The maximum number of consecutive empty lines to keep.
1254 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1255 /// int f() { int f() {
1256 /// int = 1; int i = 1;
1258 /// i = foo(); return i;
1263 unsigned MaxEmptyLinesToKeep;
1265 /// \brief Different ways to indent namespace contents.
1266 enum NamespaceIndentationKind {
1267 /// Don't indent in namespaces.
1277 /// Indent only in inner namespaces (nested in other namespaces).
1287 /// Indent in all namespaces.
1299 /// \brief The indentation used for namespaces.
1300 NamespaceIndentationKind NamespaceIndentation;
1302 /// \brief The number of characters to use for indentation of ObjC blocks.
1304 /// ObjCBlockIndentWidth: 4
1306 /// [operation setCompletionBlock:^{
1307 /// [self onOperationDone];
1310 unsigned ObjCBlockIndentWidth;
1312 /// \brief Add a space after ``@property`` in Objective-C, i.e. use
1313 /// ``@property (readonly)`` instead of ``@property(readonly)``.
1314 bool ObjCSpaceAfterProperty;
1316 /// \brief Add a space in front of an Objective-C protocol list, i.e. use
1317 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1318 bool ObjCSpaceBeforeProtocolList;
1320 /// \brief The penalty for breaking around an assignment operator.
1321 unsigned PenaltyBreakAssignment;
1323 /// \brief The penalty for breaking a function call after ``call(``.
1324 unsigned PenaltyBreakBeforeFirstCallParameter;
1326 /// \brief The penalty for each line break introduced inside a comment.
1327 unsigned PenaltyBreakComment;
1329 /// \brief The penalty for breaking before the first ``<<``.
1330 unsigned PenaltyBreakFirstLessLess;
1332 /// \brief The penalty for each line break introduced inside a string literal.
1333 unsigned PenaltyBreakString;
1335 /// \brief The penalty for each character outside of the column limit.
1336 unsigned PenaltyExcessCharacter;
1338 /// \brief Penalty for putting the return type of a function onto its own
1340 unsigned PenaltyReturnTypeOnItsOwnLine;
1342 /// \brief The ``&`` and ``*`` alignment style.
1343 enum PointerAlignmentStyle {
1344 /// Align pointer to the left.
1349 /// Align pointer to the right.
1354 /// Align pointer in the middle.
1361 /// \brief Pointer and reference alignment style.
1362 PointerAlignmentStyle PointerAlignment;
1364 /// See documentation of ``RawStringFormats``.
1365 struct RawStringFormat {
1366 /// \brief The delimiter that this raw string format matches.
1367 std::string Delimiter;
1368 /// \brief The language of this raw string.
1369 LanguageKind Language;
1370 /// \brief The style name on which this raw string format is based on.
1371 /// If not specified, the raw string format is based on the style that this
1372 /// format is based on.
1373 std::string BasedOnStyle;
1374 bool operator==(const RawStringFormat &Other) const {
1375 return Delimiter == Other.Delimiter && Language == Other.Language &&
1376 BasedOnStyle == Other.BasedOnStyle;
1380 /// \brief Raw string delimiters denoting that the raw string contents are
1381 /// code in a particular language and can be reformatted.
1383 /// A raw string with a matching delimiter will be reformatted assuming the
1384 /// specified language based on a predefined style given by 'BasedOnStyle'.
1385 /// If 'BasedOnStyle' is not found, the formatting is based on llvm style.
1387 /// To configure this in the .clang-format file, use:
1389 /// RawStringFormats:
1390 /// - Delimiter: 'pb'
1391 /// Language: TextProto
1392 /// BasedOnStyle: llvm
1393 /// - Delimiter: 'proto'
1394 /// Language: TextProto
1395 /// BasedOnStyle: google
1397 std::vector<RawStringFormat> RawStringFormats;
1399 /// \brief If ``true``, clang-format will attempt to re-flow comments.
1402 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1403 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1406 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1408 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1409 /// * information */
1411 bool ReflowComments;
1413 /// \brief If ``true``, clang-format will sort ``#includes``.
1416 /// #include "b.h" vs. #include "a.h"
1417 /// #include "a.h" #include "b.h"
1421 /// \brief If ``true``, clang-format will sort using declarations.
1423 /// The order of using declarations is defined as follows:
1424 /// Split the strings by "::" and discard any initial empty strings. The last
1425 /// element of each list is a non-namespace name; all others are namespace
1426 /// names. Sort the lists of names lexicographically, where the sort order of
1427 /// individual names is that all non-namespace names come before all namespace
1428 /// names, and within those groups, names are in case-insensitive
1429 /// lexicographic order.
1432 /// using std::cout; vs. using std::cin;
1433 /// using std::cin; using std::cout;
1435 bool SortUsingDeclarations;
1437 /// \brief If ``true``, a space is inserted after C style casts.
1440 /// (int)i; vs. (int) i;
1442 bool SpaceAfterCStyleCast;
1444 /// \brief If \c true, a space will be inserted after the 'template' keyword.
1447 /// template <int> void foo(); vs. template<int> void foo();
1449 bool SpaceAfterTemplateKeyword;
1451 /// \brief If ``false``, spaces will be removed before assignment operators.
1454 /// int a = 5; vs. int a=5;
1457 bool SpaceBeforeAssignmentOperators;
1459 /// \brief Different ways to put a space before opening parentheses.
1460 enum SpaceBeforeParensOptions {
1461 /// Never put a space before opening parentheses.
1470 /// Put a space before opening parentheses only after control statement
1471 /// keywords (``for/if/while...``).
1479 SBPO_ControlStatements,
1480 /// Always put a space before opening parentheses, except when it's
1481 /// prohibited by the syntax rules (in function-like macro definitions) or
1482 /// when determined by other style rules (after unary operators, opening
1483 /// parentheses, etc.)
1494 /// \brief Defines in which cases to put a space before opening parentheses.
1495 SpaceBeforeParensOptions SpaceBeforeParens;
1497 /// \brief If ``true``, spaces may be inserted into ``()``.
1500 /// void f( ) { vs. void f() {
1501 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1502 /// if (true) { if (true) {
1507 bool SpaceInEmptyParentheses;
1509 /// \brief The number of spaces before trailing line comments
1510 /// (``//`` - comments).
1512 /// This does not affect trailing block comments (``/*`` - comments) as
1513 /// those commonly have different usage patterns and a number of special
1516 /// SpacesBeforeTrailingComments: 3
1518 /// if (true) { // foo1
1523 unsigned SpacesBeforeTrailingComments;
1525 /// \brief If ``true``, spaces will be inserted after ``<`` and before ``>``
1526 /// in template argument lists.
1529 /// static_cast< int >(arg); vs. static_cast<int>(arg);
1530 /// std::function< void(int) > fct; std::function<void(int)> fct;
1532 bool SpacesInAngles;
1534 /// \brief If ``true``, spaces are inserted inside container literals (e.g.
1535 /// ObjC and Javascript array and dict literals).
1538 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
1539 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
1541 bool SpacesInContainerLiterals;
1543 /// \brief If ``true``, spaces may be inserted into C style casts.
1546 /// x = ( int32 )y vs. x = (int32)y
1548 bool SpacesInCStyleCastParentheses;
1550 /// \brief If ``true``, spaces will be inserted after ``(`` and before ``)``.
1553 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
1555 bool SpacesInParentheses;
1557 /// \brief If ``true``, spaces will be inserted after ``[`` and before ``]``.
1558 /// Lambdas or unspecified size array declarations will not be affected.
1561 /// int a[ 5 ]; vs. int a[5];
1562 /// std::unique_ptr<int[]> foo() {} // Won't be affected
1564 bool SpacesInSquareBrackets;
1566 /// \brief Supported language standards.
1567 enum LanguageStandard {
1568 /// Use C++03-compatible syntax.
1570 /// Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
1571 /// ``A<A<int> >``).
1573 /// Automatic detection based on the input.
1577 /// \brief Format compatible with this standard, e.g. use ``A<A<int> >``
1578 /// instead of ``A<A<int>>`` for ``LS_Cpp03``.
1579 LanguageStandard Standard;
1581 /// \brief The number of columns used for tab stops.
1584 /// \brief Different ways to use tab in formatting.
1588 /// Use tabs only for indentation.
1590 /// Use tabs only for line continuation and indentation.
1591 UT_ForContinuationAndIndentation,
1592 /// Use tabs whenever we need to fill whitespace that spans at least from
1593 /// one tab stop to the next one.
1597 /// \brief The way to use tab characters in the resulting file.
1600 bool operator==(const FormatStyle &R) const {
1601 return AccessModifierOffset == R.AccessModifierOffset &&
1602 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
1603 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
1604 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
1605 AlignEscapedNewlines == R.AlignEscapedNewlines &&
1606 AlignOperands == R.AlignOperands &&
1607 AlignTrailingComments == R.AlignTrailingComments &&
1608 AllowAllParametersOfDeclarationOnNextLine ==
1609 R.AllowAllParametersOfDeclarationOnNextLine &&
1610 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
1611 AllowShortCaseLabelsOnASingleLine ==
1612 R.AllowShortCaseLabelsOnASingleLine &&
1613 AllowShortFunctionsOnASingleLine ==
1614 R.AllowShortFunctionsOnASingleLine &&
1615 AllowShortIfStatementsOnASingleLine ==
1616 R.AllowShortIfStatementsOnASingleLine &&
1617 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
1618 AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
1619 AlwaysBreakBeforeMultilineStrings ==
1620 R.AlwaysBreakBeforeMultilineStrings &&
1621 AlwaysBreakTemplateDeclarations ==
1622 R.AlwaysBreakTemplateDeclarations &&
1623 BinPackArguments == R.BinPackArguments &&
1624 BinPackParameters == R.BinPackParameters &&
1625 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
1626 BreakBeforeBraces == R.BreakBeforeBraces &&
1627 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
1628 BreakConstructorInitializers == R.BreakConstructorInitializers &&
1629 CompactNamespaces == R.CompactNamespaces &&
1630 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
1631 BreakStringLiterals == R.BreakStringLiterals &&
1632 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
1633 BreakBeforeInheritanceComma == R.BreakBeforeInheritanceComma &&
1634 ConstructorInitializerAllOnOneLineOrOnePerLine ==
1635 R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
1636 ConstructorInitializerIndentWidth ==
1637 R.ConstructorInitializerIndentWidth &&
1638 ContinuationIndentWidth == R.ContinuationIndentWidth &&
1639 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
1640 DerivePointerAlignment == R.DerivePointerAlignment &&
1641 DisableFormat == R.DisableFormat &&
1642 ExperimentalAutoDetectBinPacking ==
1643 R.ExperimentalAutoDetectBinPacking &&
1644 FixNamespaceComments == R.FixNamespaceComments &&
1645 ForEachMacros == R.ForEachMacros &&
1646 IncludeBlocks == R.IncludeBlocks &&
1647 IncludeCategories == R.IncludeCategories &&
1648 IndentCaseLabels == R.IndentCaseLabels &&
1649 IndentPPDirectives == R.IndentPPDirectives &&
1650 IndentWidth == R.IndentWidth && Language == R.Language &&
1651 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
1652 JavaScriptQuotes == R.JavaScriptQuotes &&
1653 JavaScriptWrapImports == R.JavaScriptWrapImports &&
1654 KeepEmptyLinesAtTheStartOfBlocks ==
1655 R.KeepEmptyLinesAtTheStartOfBlocks &&
1656 MacroBlockBegin == R.MacroBlockBegin &&
1657 MacroBlockEnd == R.MacroBlockEnd &&
1658 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
1659 NamespaceIndentation == R.NamespaceIndentation &&
1660 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
1661 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
1662 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
1663 PenaltyBreakAssignment ==
1664 R.PenaltyBreakAssignment &&
1665 PenaltyBreakBeforeFirstCallParameter ==
1666 R.PenaltyBreakBeforeFirstCallParameter &&
1667 PenaltyBreakComment == R.PenaltyBreakComment &&
1668 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
1669 PenaltyBreakString == R.PenaltyBreakString &&
1670 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
1671 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
1672 PointerAlignment == R.PointerAlignment &&
1673 RawStringFormats == R.RawStringFormats &&
1674 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
1675 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
1676 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
1677 SpaceBeforeParens == R.SpaceBeforeParens &&
1678 SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
1679 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
1680 SpacesInAngles == R.SpacesInAngles &&
1681 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
1682 SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
1683 SpacesInParentheses == R.SpacesInParentheses &&
1684 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
1685 Standard == R.Standard && TabWidth == R.TabWidth &&
1690 /// \brief Returns a format style complying with the LLVM coding standards:
1691 /// http://llvm.org/docs/CodingStandards.html.
1692 FormatStyle getLLVMStyle();
1694 /// \brief Returns a format style complying with one of Google's style guides:
1695 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
1696 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
1697 /// https://developers.google.com/protocol-buffers/docs/style.
1698 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
1700 /// \brief Returns a format style complying with Chromium's style guide:
1701 /// http://www.chromium.org/developers/coding-style.
1702 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
1704 /// \brief Returns a format style complying with Mozilla's style guide:
1705 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
1706 FormatStyle getMozillaStyle();
1708 /// \brief Returns a format style complying with Webkit's style guide:
1709 /// http://www.webkit.org/coding/coding-style.html
1710 FormatStyle getWebKitStyle();
1712 /// \brief Returns a format style complying with GNU Coding Standards:
1713 /// http://www.gnu.org/prep/standards/standards.html
1714 FormatStyle getGNUStyle();
1716 /// \brief Returns style indicating formatting should be not applied at all.
1717 FormatStyle getNoStyle();
1719 /// \brief Gets a predefined style for the specified language by name.
1721 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
1722 /// compared case-insensitively.
1724 /// Returns ``true`` if the Style has been set.
1725 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
1726 FormatStyle *Style);
1728 /// \brief Parse configuration from YAML-formatted text.
1730 /// Style->Language is used to get the base style, if the ``BasedOnStyle``
1731 /// option is present.
1733 /// When ``BasedOnStyle`` is not present, options not present in the YAML
1734 /// document, are retained in \p Style.
1735 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
1737 /// \brief Gets configuration in a YAML string.
1738 std::string configurationAsText(const FormatStyle &Style);
1740 /// \brief Returns the replacements necessary to sort all ``#include`` blocks
1741 /// that are affected by ``Ranges``.
1742 tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
1743 ArrayRef<tooling::Range> Ranges,
1745 unsigned *Cursor = nullptr);
1747 /// \brief Returns the replacements corresponding to applying and formatting
1748 /// \p Replaces on success; otheriwse, return an llvm::Error carrying
1749 /// llvm::StringError.
1750 llvm::Expected<tooling::Replacements>
1751 formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
1752 const FormatStyle &Style);
1754 /// \brief Returns the replacements corresponding to applying \p Replaces and
1755 /// cleaning up the code after that on success; otherwise, return an llvm::Error
1756 /// carrying llvm::StringError.
1757 /// This also supports inserting/deleting C++ #include directives:
1758 /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
1759 /// that is an #include directive, this will insert the #include into the
1760 /// correct block in the \p Code. When searching for points to insert new
1761 /// header, this ignores #include's after the #include block(s) in the
1762 /// beginning of a file to avoid inserting headers into code sections where
1763 /// new #include's should not be added by default. These code sections
1765 /// - raw string literals (containing #include).
1767 /// - Special #include's among declarations (e.g. functions).
1768 /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
1769 /// that is the name of the header to be removed, the header will be removed
1770 /// from \p Code if it exists.
1771 llvm::Expected<tooling::Replacements>
1772 cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
1773 const FormatStyle &Style);
1775 /// \brief Represents the status of a formatting attempt.
1776 struct FormattingAttemptStatus {
1777 /// \brief A value of ``false`` means that any of the affected ranges were not
1778 /// formatted due to a non-recoverable syntax error.
1779 bool FormatComplete = true;
1781 /// \brief If ``FormatComplete`` is false, ``Line`` records a one-based
1782 /// original line number at which a syntax error might have occurred. This is
1783 /// based on a best-effort analysis and could be imprecise.
1787 /// \brief Reformats the given \p Ranges in \p Code.
1789 /// Each range is extended on either end to its next bigger logic unit, i.e.
1790 /// everything that might influence its formatting or might be influenced by its
1793 /// Returns the ``Replacements`` necessary to make all \p Ranges comply with
1796 /// If ``Status`` is non-null, its value will be populated with the status of
1797 /// this formatting attempt. See \c FormattingAttemptStatus.
1798 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1799 ArrayRef<tooling::Range> Ranges,
1800 StringRef FileName = "<stdin>",
1801 FormattingAttemptStatus *Status = nullptr);
1803 /// \brief Same as above, except if ``IncompleteFormat`` is non-null, its value
1804 /// will be set to true if any of the affected ranges were not formatted due to
1805 /// a non-recoverable syntax error.
1806 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
1807 ArrayRef<tooling::Range> Ranges,
1809 bool *IncompleteFormat);
1811 /// \brief Clean up any erroneous/redundant code in the given \p Ranges in \p
1814 /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
1815 tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
1816 ArrayRef<tooling::Range> Ranges,
1817 StringRef FileName = "<stdin>");
1819 /// \brief Fix namespace end comments in the given \p Ranges in \p Code.
1821 /// Returns the ``Replacements`` that fix the namespace comments in all
1822 /// \p Ranges in \p Code.
1823 tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
1825 ArrayRef<tooling::Range> Ranges,
1826 StringRef FileName = "<stdin>");
1828 /// \brief Sort consecutive using declarations in the given \p Ranges in
1831 /// Returns the ``Replacements`` that sort the using declarations in all
1832 /// \p Ranges in \p Code.
1833 tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
1835 ArrayRef<tooling::Range> Ranges,
1836 StringRef FileName = "<stdin>");
1838 /// \brief Returns the ``LangOpts`` that the formatter expects you to set.
1840 /// \param Style determines specific settings for lexing mode.
1841 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
1843 /// \brief Description to be used for help text for a ``llvm::cl`` option for
1844 /// specifying format style. The description is closely related to the operation
1845 /// of ``getStyle()``.
1846 extern const char *StyleOptionHelpDescription;
1848 /// \brief Construct a FormatStyle based on ``StyleName``.
1850 /// ``StyleName`` can take several forms:
1851 /// * "{<key>: <value>, ...}" - Set specic style parameters.
1852 /// * "<style name>" - One of the style names supported by
1853 /// getPredefinedStyle().
1854 /// * "file" - Load style configuration from a file called ``.clang-format``
1855 /// located in one of the parent directories of ``FileName`` or the current
1856 /// directory if ``FileName`` is empty.
1858 /// \param[in] StyleName Style name to interpret according to the description
1860 /// \param[in] FileName Path to start search for .clang-format if ``StyleName``
1862 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
1863 /// in case \p StyleName is "file" and no file can be found.
1864 /// \param[in] Code The actual code to be formatted. Used to determine the
1865 /// language if the filename isn't sufficient.
1866 /// \param[in] FS The underlying file system, in which the file resides. By
1867 /// default, the file system is the real file system.
1869 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
1870 /// "file" and no file is found, returns ``FallbackStyle``. If no style could be
1871 /// determined, returns an Error.
1872 llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
1873 StringRef FallbackStyle,
1874 StringRef Code = "",
1875 vfs::FileSystem *FS = nullptr);
1877 // \brief Returns a string representation of ``Language``.
1878 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
1880 case FormatStyle::LK_Cpp:
1882 case FormatStyle::LK_ObjC:
1883 return "Objective-C";
1884 case FormatStyle::LK_Java:
1886 case FormatStyle::LK_JavaScript:
1887 return "JavaScript";
1888 case FormatStyle::LK_Proto:
1890 case FormatStyle::LK_TextProto:
1897 } // end namespace format
1898 } // end namespace clang
1902 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
1905 #endif // LLVM_CLANG_FORMAT_FORMAT_H