exclude directory clang format

跟風遠走 提交于 2020-01-04 02:53:08

问题


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.


回答1:


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.




回答2:


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. 

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



来源:https://stackoverflow.com/questions/51326844/exclude-directory-clang-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!