Skip to content

[clang-format] .clang-format-ignore does not match / with * wildcardΒ #110160

@ameerj

Description

@ameerj

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

/// 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions