Skip to content

Exclude paths/files from being formatted #49

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
carun opened this issue Mar 12, 2025 · 5 comments
Open

Exclude paths/files from being formatted #49

carun opened this issue Mar 12, 2025 · 5 comments

Comments

@carun
Copy link

carun commented Mar 12, 2025

We use kind of mono repo and thus our repo consists of a mix of languages such as C++, Python, Go and Java. The tree is somewhat akin to this.

How do we exclude certain paths and files from being formatted? Alternatively, is there a way to include only certain paths?

$ tree -a
.
├── .clang-format
├── .cmake-format
├── CMakeLists.txt
├── cpp1
│   └── main.cpp
├── cpp2
│   └── main.cpp
├── go1
│   └── main.go
├── go2
│   └── main.go
├── java1
│   └── Main.java
├── java2
│   └── Main.java
├── proto
│   ├── Message.proto
│   └── Service.proto
├── python1
│   └── main.py
└── python2
    └── main.py
@ClausKlein
Copy link
Contributor

@carun
Copy link
Author

carun commented Mar 12, 2025

I think the python script in this repo is overriding it. See:

/tmp/repo (main)$ clang-format --version
Ubuntu clang-format version 18.1.3 (1ubuntu1)
/tmp/repo (main)$
/tmp/repo (main)$ ll .clang-format*
-rw-r--r-- 1 arun arun 1110 Mar 12 16:20 .clang-format
-rw-r--r-- 1 arun arun   10 Mar 12 16:25 .clang-format-ignore
/tmp/repo (main)$
/tmp/repo (main)$ cat .clang-format-ignore
java*
go*
/tmp/repo (main)$ cd build
/tmp/repo/build (main)$
/tmp/repo/build (main)$ ninja fix-format
[1/2] cd /tmp/repo && /bin/python3 /tmp/repo/build/_deps/format.cmake-src/git-clang-format.py --binary=/bin/clang-format 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -f
FAILED: _deps/format.cmake-build/CMakeFiles/fix-clang-format /tmp/repo/build/_deps/format.cmake-build/CMakeFiles/fix-clang-format
cd /tmp/repo && /bin/python3 /tmp/repo/build/_deps/format.cmake-src/git-clang-format.py --binary=/bin/clang-format 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -f
Configuration file(s) do(es) not support Java: /tmp/repo/.clang-format
error: `/bin/clang-format -lines=1:5 java1/Main.java` failed
[2/2] cd /tmp/repo && /usr/bin/cmake -DGIT_PROGRAM=/bin/git -DCMAKE_FORMAT_PROGRAM=/bin/cmak...e-build -DCMAKE_FORMAT_EXCLUDE= -P /tmp/repo/build/_deps/format.cmake-src/cmake-format.cmake ninja: build stopped: subcommand failed.

/tmp/repo/build (main)$

@ClausKlein
Copy link
Contributor

I think the python script in this repo is overriding it

I know, that's the problem with this cmake module!

Try:

git ls-files ::*.cpp ::*.json | xargs clang-format -i

@carun
Copy link
Author

carun commented Mar 13, 2025

I know how to run clang-format. The bug report is about this cmake module. So explicit clang-format invocation is not the solution.

@ClausKlein
Copy link
Contributor

see #41

The implementation is not as good as it should with an old local copy of the clang-format.py script.

That is the real problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants