Skip to content

Commit

Permalink
[clang-format] Fix working -assume-filename with .clang-format-ignore (
Browse files Browse the repository at this point in the history
…llvm#113100)

Fixes llvm#113099.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
  • Loading branch information
kakkoko and owenca authored Oct 25, 2024
1 parent a35ebcf commit efd8938
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions clang/test/Format/clang-format-ignore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@
// CHECK5-NEXT: {{Formatting \[4/5] .*foo\.c}}
// CHECK5-NOT: foo.js

// RUN: echo "foo.*" > .clang-format-ignore
// RUN: echo "int i ;" > foo.c
// RUN: clang-format -assume-filename=foo.c < foo.c \
// RUN: | FileCheck %s -check-prefix=CHECK6 -allow-empty
// CHECK6-NOT: int

// RUN: clang-format -assume-filename=bar.c < foo.c \
// RUN: | FileCheck %s -check-prefix=CHECK7 -match-full-lines
// CHECK7: int i;

// RUN: cd ..
// RUN: rm -r %t.dir
5 changes: 4 additions & 1 deletion clang/tools/clang-format/ClangFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,11 @@ int main(int argc, const char **argv) {
errs() << "Clang-formatting " << LineNo << " files\n";
}

if (FileNames.empty())
if (FileNames.empty()) {
if (isIgnored(AssumeFileName))
return 0;
return clang::format::format("-", FailOnIncompleteFormat);
}

if (FileNames.size() > 1 &&
(!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
Expand Down

0 comments on commit efd8938

Please sign in to comment.