-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
When using a .clang-format-ignore file, a * wildcard is expected to match a directory separator.
For example, a line containing *g_* should match any file in the current directory and all subdirectories that match the pattern *g_*
Currently, the * does not match the path separator. So a *g_* in the .clang-format-ignore file will only match this pattern for the current working directory. There does not seem to be a way to match the pattern for the current dir and subdirs.
Looking into the source code, it seems that this behavior is from the matchFilePath function, which is based on the POSIX fnmatch() function
llvm-project/clang/lib/Format/MatchFilePath.cpp
Lines 10 to 11 in d4d38bc
| /// This file implements the functionality of matching a file path name to | |
| /// a pattern, similar to the POSIX fnmatch() function. |
All of the following tests added to MatchFilePathTest.cpp fail:
EXPECT_TRUE(match("some/nested/dir/file.cpp", "*nested*"));
EXPECT_TRUE(match("some/nested/dir/file.cpp", "*/nested/*"));
EXPECT_TRUE(match("some/nested/dir/g_file.cpp", "*g_*"));
EXPECT_TRUE(match("some/nested/dir/g_file.cpp", "*/g_*"));The fnmatch() function matches these cases:
https://godbolt.org/z/6qxYW41Yv
@owenca is this expected behavior?
P.S. I am seeing this behavior on Windows/MSVC, not sure if this affects all environments or is Windows specific.