Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Mozilla Source

  • Github Repo

But they don't seem official.

like image 437
Andrey Avatar asked Jul 13 '18 13:07

Andrey


People also ask

How do you customize your clang-format?

clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.

How do I get rid of clang-format?

There is no functionality in clang-format for undoing a format operation.

Where is clang-format file located?

Standalone Tool clang-format is located in clang/tools/clang-format and can be used to format C/C++/Obj-C code.

How do I run a clang-format in a folder?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.


2 Answers

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 :)

like image 129
Fatlad Avatar answered Sep 17 '22 23:09

Fatlad


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 to exclude a directory in find . command).

Hope this help you at least.

like image 26
Pato Sandaña Avatar answered Sep 19 '22 23:09

Pato Sandaña