[PDNCF] Python 3.12 compatibility
[platform/framework/web/chromium-efl.git] / tools / clang-format-js
1 #!/bin/bash
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.
5
6 if [[ -z "$@" || "$1" == "-h" || "$1" == "--help" ]]; then
7   echo >&2 "Usage: `basename $0` <paths_to_clang_format...>"
8   exit 1
9 fi
10
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"
14   exit 1
15 fi
16
17 for arg in ${@}; do
18   echo "Processing ${arg}"
19
20   dir=`readlink -f "${arg}"`
21   if [[ -d "${dir}" ]]; then
22     dir="${dir}/stripped-by-dirname-on-next-line"
23   fi
24   while dir=`dirname ${dir}`; do
25     if [[ -f "${dir}/.clang-format" ]]; then
26       echo "Using style from: ${dir}/.clang-format"
27       break
28     elif [[ "${dir}" == "/" ]]; then
29       echo >&2 "No .clang-format file found. Make one at or above ${arg}"
30       exit 1
31     fi
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
40 done