blob: d09925d83aaec784e7a5a32c8a8d8a4a448bf744 [file] [log] [blame]
dbeam54c48b32016-12-22 21:12:041#!/bin/bash
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
4# found in the LICENSE file.
5
6if [[ -z "${@}" ]]; then
7 echo >&2 "Usage: `basename $0` <paths_to_clang_format...>";
8 exit 1;
9fi
10
11which clang-format >/dev/null 2>&1;
12if [[ $? -ne 0 ]]; then
13 echo >&2 "Sorry, but you need \`clang-format\` on your \$PATH to run this script";
14 exit 1;
15fi
16
17for arg in "${@}"; do
18 dir=`readlink -f "${arg}"`
19 while dir=`dirname ${dir}`; do
20 if [[ -f "${dir}/.clang-format" ]]; then
21 echo "Using style from: ${dir}/.clang-format";
22 break;
23 elif [[ "${dir}" == "/" ]]; then
24 echo >&2 "No .clang-format file found. Make one at or above ${arg}";
25 exit 1;
26 fi
27 done
28done
29
30find "${@}" -type f -iname '*.js' | xargs clang-format -i -style=file;