How to call clang-format over a cpp project folder?

后端 未结 9 2135
眼角桃花
眼角桃花 2021-01-29 21:43

Is there a way to call something like clang-format --style=Webkit for an entire cpp project folder, rather than running it separately for each file?

I am us

9条回答
  •  借酒劲吻你
    2021-01-29 22:00

    In modern bash you can recursively crawl the file tree

    for file_name in ./src/**/*.{cpp,h,hpp}; do
        if [ -f "$file_name" ]; then
            printf '%s\n' "$file_name"
            clang-format -i $file_name
        fi
    done
    

    Here the source is assumed to be located in ./src and the .clang-format contains the formatting information.

提交回复
热议问题