blob: 4b04d8dc79809dc5d5b1404edc5c2fa5ca048c9a [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}"`
dbeame6533f52016-12-23 01:28:2319 if [[ -d "${dir}" ]]; then
20 dir="${dir}/stripped-by-dirname-on-next-line"
21 fi
dbeam54c48b32016-12-22 21:12:0422 while dir=`dirname ${dir}`; do
23 if [[ -f "${dir}/.clang-format" ]]; then
24 echo "Using style from: ${dir}/.clang-format";
25 break;
26 elif [[ "${dir}" == "/" ]]; then
27 echo >&2 "No .clang-format file found. Make one at or above ${arg}";
28 exit 1;
29 fi
30 done
31done
32
33find "${@}" -type f -iname '*.js' | xargs clang-format -i -style=file;