OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 if [[ -z "${@}" ]]; then | 6 if [[ -z "${@}" ]]; then |
7 echo >&2 "Usage: `basename $0` <paths_to_clang_format...>"; | 7 echo >&2 "Usage: `basename $0` <paths_to_clang_format...>" |
8 exit 1; | 8 exit 1 |
9 fi | 9 fi |
10 | 10 |
11 which clang-format >/dev/null 2>&1; | 11 which clang-format >/dev/null 2>&1 |
12 if [[ $? -ne 0 ]]; then | 12 if [[ $? -ne 0 ]]; then |
13 echo >&2 "Sorry, but you need \`clang-format\` on your \$PATH to run this scri
pt"; | 13 echo >&2 "Sorry, but you need \`clang-format\` on your \$PATH to run this scri
pt" |
14 exit 1; | 14 exit 1 |
15 fi | 15 fi |
16 | 16 |
17 for arg in "${@}"; do | 17 for arg in ${@}; do |
| 18 echo "Processing ${arg}" |
| 19 |
18 dir=`readlink -f "${arg}"` | 20 dir=`readlink -f "${arg}"` |
19 if [[ -d "${dir}" ]]; then | 21 if [[ -d "${dir}" ]]; then |
20 dir="${dir}/stripped-by-dirname-on-next-line" | 22 dir="${dir}/stripped-by-dirname-on-next-line" |
21 fi | 23 fi |
22 while dir=`dirname ${dir}`; do | 24 while dir=`dirname ${dir}`; do |
23 if [[ -f "${dir}/.clang-format" ]]; then | 25 if [[ -f "${dir}/.clang-format" ]]; then |
24 echo "Using style from: ${dir}/.clang-format"; | 26 echo "Using style from: ${dir}/.clang-format" |
25 break; | 27 break |
26 elif [[ "${dir}" == "/" ]]; then | 28 elif [[ "${dir}" == "/" ]]; then |
27 echo >&2 "No .clang-format file found. Make one at or above ${arg}"; | 29 echo >&2 "No .clang-format file found. Make one at or above ${arg}" |
28 exit 1; | 30 exit 1 |
29 fi | 31 fi |
30 done | 32 done |
| 33 |
| 34 js_files=$(git ls-tree -r --name-only HEAD -- "${arg}" | grep '\.js$') |
| 35 |
| 36 for js_file in ${js_files}; do |
| 37 echo "Formatting ${js_file}" |
| 38 clang-format -i -style=file "$js_file" |
| 39 done |
31 done | 40 done |
32 | |
33 find "${@}" -type f -iname '*.js' | xargs clang-format -i -style=file; | |
OLD | NEW |