Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 2 | set -e |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 3 | |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 4 | # This script reformats source files using various formatters and linters. |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 5 | # |
| 6 | # Files are changed in-place, so make sure you don't have anything open in an |
| 7 | # editor, and you may want to commit before formatting in case of awryness. |
| 8 | # |
| 9 | # This must be run on a clean repository to succeed |
| 10 | # |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 11 | function display_help() |
| 12 | { |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 13 | echo "usage: format-code.sh [-h | --help] [--no-diff] [--disable <tool>]" |
| 14 | echo " [--list-tools] [<path>]" |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 15 | echo |
| 16 | echo "Format and lint a repository." |
| 17 | echo |
| 18 | echo "Arguments:" |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 19 | echo " --list-tools Display available linters and formatters" |
| 20 | echo " --no-diff Don't show final diff output" |
| 21 | echo " --disable <tool> Disable linter" |
Patrick Williams | 26d9d2c | 2022-12-05 15:03:07 -0600 | [diff] [blame^] | 22 | echo " --allow-missing Run even if linters are not all present" |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 23 | echo " path Path to git repository (default to pwd)" |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 24 | } |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 25 | |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 26 | LINTERS_ALL=( \ |
| 27 | commit_gitlint \ |
| 28 | commit_spelling \ |
| 29 | clang_format \ |
| 30 | eslint \ |
| 31 | pycodestyle \ |
| 32 | shellcheck \ |
| 33 | ) |
| 34 | LINTERS_DISABLED=() |
| 35 | LINTERS_ENABLED=() |
| 36 | |
Patrick Williams | 26d9d2c | 2022-12-05 15:03:07 -0600 | [diff] [blame^] | 37 | eval set -- "$(getopt -o 'h' --long 'help,list-tools,no-diff,disable:,allow-missing' -n 'format-code.sh' -- "$@")" |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 38 | while true; do |
| 39 | case "$1" in |
| 40 | '-h'|'--help') |
| 41 | display_help && exit 0 |
| 42 | ;; |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 43 | |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 44 | '--list-tools') |
| 45 | echo "Available tools:" |
| 46 | for t in "${LINTERS_ALL[@]}"; do |
| 47 | echo " $t" |
| 48 | done |
| 49 | exit 0 |
| 50 | ;; |
| 51 | |
Patrick Williams | d27ab4c | 2022-11-27 17:51:35 -0600 | [diff] [blame] | 52 | '--no-diff') |
| 53 | OPTION_NO_DIFF=1 |
| 54 | shift |
| 55 | ;; |
| 56 | |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 57 | '--disable') |
| 58 | LINTERS_DISABLED+=("$2") |
| 59 | shift && shift |
| 60 | ;; |
| 61 | |
Patrick Williams | 26d9d2c | 2022-12-05 15:03:07 -0600 | [diff] [blame^] | 62 | '--allow-missing') |
| 63 | ALLOW_MISSING=yes |
| 64 | shift |
| 65 | ;; |
| 66 | |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 67 | '--') |
| 68 | shift |
| 69 | break |
| 70 | ;; |
| 71 | |
| 72 | *) |
| 73 | echo "unknown option: $1" |
| 74 | display_help && exit 1 |
| 75 | ;; |
| 76 | esac |
| 77 | done |
| 78 | |
| 79 | # Detect tty and set nicer colors. |
| 80 | if [ -t 1 ]; then |
| 81 | BLUE="\e[34m" |
| 82 | GREEN="\e[32m" |
| 83 | NORMAL="\e[0m" |
| 84 | RED="\e[31m" |
| 85 | YELLOW="\e[33m" |
| 86 | else # non-tty, no escapes. |
| 87 | BLUE="" |
| 88 | GREEN="" |
| 89 | NORMAL="" |
| 90 | RED="" |
| 91 | YELLOW="" |
| 92 | fi |
| 93 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 94 | # Allow called scripts to know which clang format we are using |
| 95 | export CLANG_FORMAT="clang-format" |
| 96 | |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 97 | # Path to default config files for linters. |
| 98 | CONFIG_PATH="$(git -C "$(dirname "${BASH_SOURCE[0]}")" rev-parse --show-toplevel)/config" |
| 99 | |
| 100 | # Find repository root for `pwd` or $1. |
| 101 | if [ -z "$1" ]; then |
| 102 | DIR="$(git rev-parse --show-toplevel || pwd)" |
| 103 | else |
| 104 | DIR="$(git -C "$1" rev-parse --show-toplevel)" |
| 105 | fi |
Patrick Williams | bc85b71 | 2022-12-05 15:16:27 -0600 | [diff] [blame] | 106 | if [ ! -e "$DIR/.git" ]; then |
| 107 | echo -e "${RED}Error:${NORMAL} Directory ($DIR) does not appear to be a git repository" |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 108 | exit 1 |
| 109 | fi |
Andrew Jeffery | 0cce848 | 2018-04-30 11:37:01 +0930 | [diff] [blame] | 110 | |
Manojkiran Eda | e6f120a | 2021-03-20 11:13:43 +0530 | [diff] [blame] | 111 | cd "${DIR}" |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 112 | echo -e " ${BLUE}Formatting code under${NORMAL} $DIR" |
Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 113 | |
Patrick Williams | 3d29494 | 2022-12-05 14:58:15 -0600 | [diff] [blame] | 114 | # Config hashes: |
| 115 | # LINTER_REQUIRE - The requirements to run a linter, semi-colon separated. |
| 116 | # 1. Executable. |
| 117 | # 2. [optional] Configuration file. |
| 118 | # 3. [optional] Global fallback configuration file. |
| 119 | # |
| 120 | # LINTER_IGNORE - An optional set of semi-colon separated ignore-files |
| 121 | # specific to the linter. |
| 122 | # |
| 123 | # LINTER_TYPES - The file types supported by the linter, semi-colon separated. |
| 124 | # |
| 125 | # LINTER_CONFIG - The config (from LINTER_REQUIRE) chosen for the repository. |
| 126 | # |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 127 | declare -A LINTER_REQUIRE=() |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 128 | declare -A LINTER_IGNORE=() |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 129 | declare -A LINTER_TYPES=() |
Patrick Williams | 3d29494 | 2022-12-05 14:58:15 -0600 | [diff] [blame] | 130 | declare -A LINTER_CONFIG=() |
Manojkiran Eda | 87111bb | 2021-08-14 11:26:16 +0530 | [diff] [blame] | 131 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 132 | LINTER_REQUIRE+=([commit_spelling]="codespell") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 133 | LINTER_TYPES+=([commit_spelling]="commit") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 134 | function do_commit_spelling() { |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 135 | # Run the codespell with openbmc spcific spellings on the patchset |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 136 | echo -n "openbmc-dictionary - misspelling count >> " |
| 137 | sed "s/Signed-off-by.*//" "$@" | \ |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 138 | codespell -D "${CONFIG_PATH}/openbmc-spelling.txt" -d --count - |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 139 | |
| 140 | # Run the codespell with generic dictionary on the patchset |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 141 | echo -n "generic-dictionary - misspelling count >> " |
| 142 | sed "s/Signed-off-by.*//" "$@" | \ |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 143 | codespell --builtin clear,rare,en-GB_to_en-US -d --count - |
| 144 | } |
| 145 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 146 | LINTER_REQUIRE+=([commit_gitlint]="gitlint") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 147 | LINTER_TYPES+=([commit_gitlint]="commit") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 148 | function do_commit_gitlint() { |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 149 | gitlint --extra-path "${CONFIG_PATH}/gitlint/" \ |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 150 | --config "${CONFIG_PATH}/.gitlint" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 151 | } |
| 152 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 153 | LINTER_REQUIRE+=([eslint]="eslint;.eslintrc.json;${CONFIG_PATH}/eslint-global-config.json") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 154 | LINTER_IGNORE+=([eslint]=".eslintignore") |
| 155 | LINTER_TYPES+=([eslint]="json") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 156 | function do_eslint() { |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 157 | eslint --no-eslintrc -c "${LINTER_CONFIG[eslint]}" \ |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 158 | --ext .json --format=stylish \ |
| 159 | --resolve-plugins-relative-to /usr/local/lib/node_modules \ |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 160 | --no-error-on-unmatched-pattern "$@" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 161 | } |
Manojkiran Eda | 87111bb | 2021-08-14 11:26:16 +0530 | [diff] [blame] | 162 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 163 | LINTER_REQUIRE+=([pycodestyle]="pycodestyle;setup.cfg") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 164 | LINTER_TYPES+=([pycodestyle]="python") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 165 | function do_pycodestyle() { |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 166 | pycodestyle --show-source "$@" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 167 | } |
James Feist | f1665d6 | 2019-11-22 09:06:33 -0800 | [diff] [blame] | 168 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 169 | LINTER_REQUIRE+=([shellcheck]="shellcheck;.shellcheck") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 170 | LINTER_TYPES+=([shellcheck]="bash;sh") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 171 | function do_shellcheck() { |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 172 | shellcheck --color=never -x "$@" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 173 | } |
James Feist | f1665d6 | 2019-11-22 09:06:33 -0800 | [diff] [blame] | 174 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 175 | LINTER_REQUIRE+=([clang_format]="clang-format;.clang-format") |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 176 | LINTER_IGNORE+=([clang_format]=".clang-ignore;.clang-format-ignore") |
| 177 | LINTER_TYPES+=([clang_format]="c;cpp") |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 178 | do_clang_format() { |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 179 | "${CLANG_FORMAT}" -i "$@" |
| 180 | } |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 181 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 182 | function get_file_type() |
| 183 | { |
| 184 | case "$(basename "$1")" in |
| 185 | # First to early detect template files. |
| 186 | *.in | *.meson) echo "meson-template" && return ;; |
| 187 | *.mako | *.mako.*) echo "mako" && return ;; |
Patrick Williams | d535ecb | 2022-12-02 14:54:18 -0600 | [diff] [blame] | 188 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 189 | *.ac) echo "autoconf" && return ;; |
| 190 | *.[ch]) echo "c" && return ;; |
| 191 | *.[ch]pp) echo "cpp" && return ;; |
| 192 | *.json) echo "json" && return ;; |
| 193 | *.md) echo "markdown" && return ;; |
| 194 | *.py) echo "python" && return ;; |
| 195 | *.yaml | *.yml) echo "yaml" && return ;; |
Patrick Williams | d535ecb | 2022-12-02 14:54:18 -0600 | [diff] [blame] | 196 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 197 | # Special files. |
| 198 | .git/COMMIT_EDITMSG) echo "commit" && return ;; |
| 199 | meson.build) echo "meson" && return ;; |
| 200 | esac |
| 201 | |
| 202 | case "$(file "$1")" in |
| 203 | *Bourne-Again\ shell*) echo "bash" && return ;; |
| 204 | *C++\ source*) echo "cpp" && return ;; |
| 205 | *C\ source*) echo "c" && return ;; |
| 206 | *JSON\ data*) echo "json" && return ;; |
| 207 | *POSIX\ shell*) echo "sh" && return ;; |
| 208 | *Python\ script*) echo "python" && return ;; |
| 209 | *zsh\ shell*) echo "zsh" && return ;; |
| 210 | esac |
| 211 | |
| 212 | echo "unknown" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 213 | } |
| 214 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 215 | function check_linter() |
| 216 | { |
| 217 | TITLE="$1" |
| 218 | IFS=";" read -r -a ARGS <<< "$2" |
| 219 | |
Patrick Williams | 147f37a | 2022-12-04 14:57:10 -0600 | [diff] [blame] | 220 | if [[ "${LINTERS_DISABLED[*]}" =~ $1 ]]; then |
| 221 | return |
| 222 | fi |
| 223 | |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 224 | EXE="${ARGS[0]}" |
| 225 | if [ ! -x "${EXE}" ]; then |
| 226 | if ! which "${EXE}" > /dev/null 2>&1 ; then |
| 227 | echo -e " ${YELLOW}${TITLE}:${NORMAL} cannot find ${EXE}" |
Patrick Williams | 26d9d2c | 2022-12-05 15:03:07 -0600 | [diff] [blame^] | 228 | if [ -z "$ALLOW_MISSING" ]; then |
| 229 | exit 1 |
| 230 | fi |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 231 | return |
| 232 | fi |
| 233 | fi |
| 234 | |
| 235 | CONFIG="${ARGS[1]}" |
| 236 | FALLBACK="${ARGS[2]}" |
| 237 | |
| 238 | if [ -n "${CONFIG}" ]; then |
| 239 | if [ -e "${CONFIG}" ]; then |
| 240 | LINTER_CONFIG+=( [${TITLE}]="${CONFIG}" ) |
| 241 | elif [ -n "${FALLBACK}" ] && [ -e "${FALLBACK}" ]; then |
| 242 | echo -e " ${YELLOW}${TITLE}:${NORMAL} cannot find ${CONFIG}; using ${FALLBACK}" |
| 243 | LINTER_CONFIG+=( [${TITLE}]="${FALLBACK}" ) |
| 244 | else |
| 245 | echo -e " ${YELLOW}${TITLE}:${NORMAL} cannot find config ${CONFIG}" |
| 246 | return |
| 247 | fi |
| 248 | fi |
| 249 | |
| 250 | LINTERS_ENABLED+=( "${TITLE}" ) |
| 251 | } |
| 252 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 253 | # Check for a global .linter-ignore file. |
| 254 | GLOBAL_IGNORE=("cat") |
| 255 | if [ -e ".linter-ignore" ]; then |
| 256 | GLOBAL_IGNORE=("${CONFIG_PATH}/lib/ignore-filter" ".linter-ignore") |
| 257 | fi |
| 258 | |
| 259 | # Find all the files in the git repository and organize by type. |
| 260 | declare -A FILES=() |
| 261 | if [ -e .git/COMMIT_EDITMSG ]; then |
| 262 | FILES+=([commit]=".git/COMMIT_EDITMSG") |
| 263 | fi |
| 264 | while read -r file; do |
| 265 | ftype="$(get_file_type "$file")" |
| 266 | FILES+=([$ftype]="$(echo -ne "$file;${FILES[$ftype]:-}")") |
| 267 | done < <(git ls-files | "${GLOBAL_IGNORE[@]}") |
| 268 | |
| 269 | # For each linter, check if there are an applicable files and if it can |
| 270 | # be enabled. |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 271 | for op in "${LINTERS_ALL[@]}"; do |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 272 | for ftype in ${LINTER_TYPES[$op]//;/ }; do |
| 273 | if [[ -v FILES["$ftype"] ]]; then |
| 274 | check_linter "$op" "${LINTER_REQUIRE[${op}]}" |
| 275 | break |
| 276 | fi |
| 277 | done |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 278 | done |
| 279 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 280 | # Call each linter. |
Patrick Williams | dad9b7a | 2022-11-30 13:10:20 -0600 | [diff] [blame] | 281 | for op in "${LINTERS_ENABLED[@]}"; do |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 282 | |
| 283 | # Determine the linter-specific ignore file(s). |
| 284 | LOCAL_IGNORE=("${CONFIG_PATH}/lib/ignore-filter") |
| 285 | if [[ -v LINTER_IGNORE["$op"] ]]; then |
| 286 | for ignorefile in ${LINTER_IGNORE["$op"]//;/ } ; do |
| 287 | if [ -e "$ignorefile" ]; then |
| 288 | LOCAL_IGNORE+=("$ignorefile") |
| 289 | fi |
| 290 | done |
| 291 | fi |
| 292 | if [ 1 -eq ${#LOCAL_IGNORE[@]} ]; then |
| 293 | LOCAL_IGNORE=("cat") |
| 294 | fi |
| 295 | |
| 296 | # Find all the files for this linter, filtering out the ignores. |
| 297 | LINTER_FILES=() |
| 298 | while read -r file ; do |
| 299 | if [ -e "$file" ]; then |
| 300 | LINTER_FILES+=("$file") |
| 301 | fi |
| 302 | done < <(for ftype in ${LINTER_TYPES[$op]//;/ }; do |
| 303 | # shellcheck disable=SC2001 |
| 304 | echo "${FILES["$ftype"]:-}" | sed "s/;/\\n/g" |
| 305 | done | "${LOCAL_IGNORE[@]}") |
| 306 | |
| 307 | # Call the linter now with all the files. |
| 308 | echo -e " ${BLUE}Running $op${NORMAL}" |
| 309 | "do_$op" "${LINTER_FILES[@]}" |
Patrick Williams | 38515a3 | 2022-11-27 06:58:56 -0600 | [diff] [blame] | 310 | done |
Andrew Jeffery | 457b6d1 | 2018-03-09 15:28:14 +1030 | [diff] [blame] | 311 | |
Patrick Williams | 71b7324 | 2022-12-02 21:07:52 -0600 | [diff] [blame] | 312 | # Check for differences. |
Patrick Williams | d27ab4c | 2022-11-27 17:51:35 -0600 | [diff] [blame] | 313 | if [ -z "$OPTION_NO_DIFF" ]; then |
| 314 | echo -e " ${BLUE}Result differences...${NORMAL}" |
| 315 | if ! git --no-pager diff --exit-code ; then |
| 316 | echo -e "Format: ${RED}FAILED${NORMAL}" |
| 317 | exit 1 |
| 318 | else |
| 319 | echo -e "Format: ${GREEN}PASSED${NORMAL}" |
| 320 | fi |
Patrick Williams | c1513c8 | 2022-11-27 17:37:08 -0600 | [diff] [blame] | 321 | fi |
| 322 | |
Andrew Jeffery | 457b6d1 | 2018-03-09 15:28:14 +1030 | [diff] [blame] | 323 | # Sometimes your situation is terrible enough that you need the flexibility. |
| 324 | # For example, phosphor-mboxd. |
Patrick Williams | 330b077 | 2022-11-28 06:14:06 -0600 | [diff] [blame] | 325 | for formatter in "format-code.sh" "format-code"; do |
| 326 | if [[ -x "${formatter}" ]]; then |
| 327 | echo -e " ${BLUE}Calling secondary formatter:${NORMAL} ${formatter}" |
| 328 | "./${formatter}" |
| 329 | if [ -z "$OPTION_NO_DIFF" ]; then |
| 330 | git --no-pager diff --exit-code |
| 331 | fi |
Patrick Williams | d27ab4c | 2022-11-27 17:51:35 -0600 | [diff] [blame] | 332 | fi |
Patrick Williams | 330b077 | 2022-11-28 06:14:06 -0600 | [diff] [blame] | 333 | done |