Skip to content

.clang-format-ignore not being used #13005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jalanh11640 opened this issue Nov 27, 2024 · 4 comments
Open

.clang-format-ignore not being used #13005

jalanh11640 opened this issue Nov 27, 2024 · 4 comments

Comments

@jalanh11640
Copy link

Environment

  • OS and Version: macOS Sequoia 15.2
  • VS Code Version: 1.95.3 (Universal)
  • C/C++ Extension Version: v1.22.11
  • If using SSH remote, specify OS of remote machine: N/A

Bug Summary and Steps to Reproduce

Bug Summary: When using Format Document from the (right click) context menu, the active file is formatted when that file is listed in .clang-format-ignore.

Steps to reproduce:

  1. Create test.cpp in root of project with contents of
#include <iostream>

int main(int argc, char *argv[])
{
  int value = 5;
  int x = 0;

  return 0;
}
  1. Create .clang-format file in root of project with contents of AlignConsecutiveAssignments: true
  2. Create .clang-format-ignore file in the root of the project with the absolute path to test.cpp
  3. Open test.cpp in editor, right click and select Format Document
  4. Notice that file has been updated with the formatting specified in .clang-format

If you run clang-format -i test.cpp in the integrated kernel, the file's format is not updated.

Expected behavior: File should not be formatted

Configuration and Logs

I have no c_cpp_properties.json.  Log diagnostics show the clang-format command as:
/Users/jeff/.vscode/extensions/ms-vscode.cpptools-1.22.11-darwin-arm64/bin/../LLVM/bin/clang-format -style=file -fallback-style=LLVM --Wno-error=unknown -assume-filename=/Users/jeff/Development/clang-format/test.cpp

Other Extensions

No response

Additional context

No response

@sean-mcmanus
Copy link
Contributor

@jalanh11640 This appears to be clang-format bug llvm/llvm-project#113099 . It looks like the fix will be available in clang-format 20.x.

@jalanh11640
Copy link
Author

@jalanh11640 This appears to be clang-format bug llvm/llvm-project#113099 . It looks like the fix will be available in clang-format 20.x.

Thanks, I’ll look forward to when that version of clang-format is pulled into the extension.

@simonhammes
Copy link

I just stumbled upon this issue. The same happens when using format on save, since that also runs clang-format with the --assume-filename flag.

@escherstair
Copy link

Based on the changelog, PR #13348 updated clang-format to v20.1.2.
I double-checked this and clang-format.exe --version returns
clang-format version 20.1.2 (https://github.com/llvm/llvm-project.git 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
on my Windows 10 machine.

With ths release, .clang-format-ignore should be honored, but this doesn't happen (unfortunately).
Here is what happens:

  • if no .clang-format-ignore exists, clang formatting (on save) works as expected (on all the files)
  • if .clang-format-ignore exists, format on save doesn't complete anymore (on all the files). It stays forever with the following popup
    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants