[clang] [clang-format] Fix working -assume-filename with .clang-format-ignore (PR #113100)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 23 04:28:44 PDT 2024
kakkoko wrote:
@mydeveloperday
> However what you are saying is, its not using that assume-filename to locate the .clang-format-ignore file?
>
> Hence in the IDE it reformats myfile.* meaning you can't save it unformatted
Yes, that is correct.
You can see that in [the following file of `Clang-Format.cpp`, `main()`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.2/clang/tools/clang-format/ClangFormat.cpp#L709-L735):
```c++
// If no file name is specified on the command line to be processed,
// formatting is performed on standard input and terminates.
if (FileNames.empty())
return clang::format::format("-", FailOnIncompleteFormat);
...
// Sequentially process each file specified on the command line
for (const auto &FileName : FileNames) {
// Check for .clang-format-ignore
const bool Ignored = isIgnored(FileName);
...
// If the pattern matches the pattern written in .clang-format-ignore,
// do nothing and proceed to the next file
if (Ignored)
continue;
...
// do formatting
Error |= clang::format::format(FileName, FailOnIncompleteFormat);
}
```
The `isIgnored()` function, which determines whether or not to ignore using `.clang-format-ignore`, is only called in the part that processes the files enumerated on the command line in order.
https://github.com/llvm/llvm-project/pull/113100
More information about the cfe-commits
mailing list