Skip to content

Commit 0cb9c6e

Browse files
committed
[clang-format] Allow empty .clang-format file
Differential Revision: https://reviews.llvm.org/D123535
1 parent 54a6cc3 commit 0cb9c6e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
17221722
FormatStyle::LanguageKind Language = Style->Language;
17231723
assert(Language != FormatStyle::LK_None);
17241724
if (Config.getBuffer().trim().empty())
1725-
return make_error_code(ParseError::Error);
1725+
return make_error_code(ParseError::Success);
17261726
Style->StyleSet.Clear();
17271727
std::vector<FormatStyle> Styles;
17281728
llvm::yaml::Input Input(Config, /*Ctxt=*/nullptr, DiagHandler,

clang/test/Format/style-on-command-line.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: mkdir -p %t
66
// RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
77
// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s
8-
// RUN: printf "\n" > %t/.clang-format
8+
// RUN: printf "Invalid:\n" > %t/.clang-format
99
// RUN: not clang-format -style=file -fallback-style=webkit -assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK6 %s
1010
// RUN: rm %t/.clang-format
1111
// RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format
@@ -20,19 +20,29 @@
2020
// Test yaml with no based style, and fallback style "none", LLVM formatting applied
2121
// RUN: clang-format -style="{IndentWidth: 7}" -fallback-style=none %s | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
2222

23+
// Empty config file tests
24+
// RUN: touch %t/.clang-format
25+
// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK12 %s
26+
// RUN: rm %t/.clang-format
27+
// RUN: printf "\n" > %t/_clang-format
28+
// RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK13 %s
29+
2330
void f() {
2431
// CHECK1: {{^ int\* i;$}}
2532
// CHECK2: {{^ int \*i;$}}
2633
// CHECK3: Unknown value for BasedOnStyle: invalid
2734
// CHECK3: Error parsing -style: [[MSG]]
2835
// CHECK4: Error parsing -style: [[MSG]]
2936
// CHECK5: {{^ int\* i;$}}
37+
// CHECK6: unknown key 'Invalid'
3038
// CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
3139
// CHECK7: {{^ int\* i;$}}
3240
// CHECK8: {{^ int\* i;$}}
3341
// CHECK9: {{^ int \*i;$}}
3442
// CHECK10: {{^ int \*i;$}}
3543
// CHECK11: {{^ int \*i;$}}
44+
// CHECK12: {{^ int \*i;$}}
45+
// CHECK13: {{^ int \*i;$}}
3646
int*i;
3747
int j;
3848
}

0 commit comments

Comments
 (0)