[clang] efd8938 - [clang-format] Fix working -assume-filename with .clang-format-ignore (#113100)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 24 18:13:11 PDT 2024
Author: kakkoko
Date: 2024-10-24T18:13:08-07:00
New Revision: efd8938d575d1f8058bfe220e4c672d969c82be0
URL: https://github.com/llvm/llvm-project/commit/efd8938d575d1f8058bfe220e4c672d969c82be0
DIFF: https://github.com/llvm/llvm-project/commit/efd8938d575d1f8058bfe220e4c672d969c82be0.diff
LOG: [clang-format] Fix working -assume-filename with .clang-format-ignore (#113100)
Fixes #113099.
---------
Co-authored-by: Owen Pan <owenpiano at gmail.com>
Added:
Modified:
clang/test/Format/clang-format-ignore.cpp
clang/tools/clang-format/ClangFormat.cpp
Removed:
################################################################################
diff --git a/clang/test/Format/clang-format-ignore.cpp b/clang/test/Format/clang-format-ignore.cpp
index fb49fa9dd52c65..67d68aebde5d04 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -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
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 108db7204aa68a..96fb85e99bf5f0 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -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())) {
More information about the cfe-commits
mailing list