Andrey
Andrey

Reputation: 119

exclude directory clang format

Is there any official directive in .clang-format file to exclude directory for applying?

Projects sometimes use git submodule, but it is not useful to run clang-format over all directory and then use git checkout to undo changes in submodule folder.

I have found some related links:

But they don't seem official.

Upvotes: 10

Views: 11777

Answers (3)

jotrocken
jotrocken

Reputation: 2333

Starting from version 18 which has been released in March 2024, clang-format allows exclusion of directories and files using .clang-format-ignore file.

Upvotes: 1

Pato Sandaña
Pato Sandaña

Reputation: 659

So far, I don't know of any option of clang-format to exclude files or directories. But what I do, is to create the list of files I want to process in a bash script and then call clang-format for them:

#!/bin/bash
folder=.
exclude_folder=./submodule
format_files=`find "${folder}" -type f -path "${exclude_folder}" -prune`

for file in $format_files
do
  clang-format -i "$file"
done

Here the magic is done by the prune option in find. (How do I exclude a directory when using `find`?).

Hope this help you at least.

Upvotes: 6

Fatlad
Fatlad

Reputation: 334

If you can add new _clang-format files (though in this case it looks like you can't?) you can create a new one with

DisableFormat: true
SortIncludes: false

Obviously this doesn't work if you can't add new _clang-format files :)

Upvotes: 14

Related Questions