2 # Copyright 2016 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 if [[ -z "$@" || "$1" == "-h" || "$1" == "--help" ]]; then
7 echo >&2 "Usage: `basename $0` <paths_to_clang_format...>"
11 which clang-format >/dev/null 2>&1
12 if [[ $? -ne 0 ]]; then
13 echo >&2 "Sorry, but you need \`clang-format\` on your \$PATH to run this script"
18 echo "Processing ${arg}"
20 dir=`readlink -f "${arg}"`
21 if [[ -d "${dir}" ]]; then
22 dir="${dir}/stripped-by-dirname-on-next-line"
24 while dir=`dirname ${dir}`; do
25 if [[ -f "${dir}/.clang-format" ]]; then
26 echo "Using style from: ${dir}/.clang-format"
28 elif [[ "${dir}" == "/" ]]; then
29 echo >&2 "No .clang-format file found. Make one at or above ${arg}"
34 js_files=$(git ls-tree -r --name-only HEAD -- "${arg}" | grep '\.js$')
36 for js_file in ${js_files}; do
37 echo "Formatting ${js_file}"
38 clang-format -i -style=file "$js_file"