blob: 75895ceac5e99c990656169d28d94dfa06c684d8 [file] [log] [blame]
Euan Kempaabca2e2025-07-21 05:44:44 +00001#!/usr/bin/env bash
Philip Zeyliger8b00db12025-04-25 18:41:38 +00002set -e
3
4# Script to run formatters for both Go and webui files
5# Usage: bin/run-formatters.sh [check]
6# If 'check' is provided, only checks formatting without making changes
7
8CHECK_MODE=false
9if [ "$1" = "check" ]; then
10 CHECK_MODE=true
11 echo "Running in check mode (formatting will not be modified)"
12else
13 echo "Running in fix mode (formatting will be modified)"
14fi
15
Philip Zeyligerbb020f52025-07-28 19:41:55 -070016# Go formatting with gofumpt
17echo "Checking Go formatting..."
18if [ "$CHECK_MODE" = true ]; then
19 # In check mode, we want to display the files that need formatting and exit with error if any
20 FILES_TO_FORMAT=$(gofumpt -l .)
21 if [ -n "$FILES_TO_FORMAT" ]; then
22 echo "The following Go files need formatting:"
23 echo "$FILES_TO_FORMAT"
24 exit 1
25 else
26 echo "Go formatting check passed"
27 fi
28else
29 # In fix mode, we apply the formatting
30 echo "Fixing Go formatting with gofumpt"
31 gofumpt -w .
32 echo "Go formatting complete"
33fi
Philip Zeyliger8b00db12025-04-25 18:41:38 +000034
Philip Zeyligerbb020f52025-07-28 19:41:55 -070035# Webui formatting with Prettier
36echo "Checking webui formatting..."
37if [ -d "./webui" ]; then
38 cd webui
Philip Zeyliger8b00db12025-04-25 18:41:38 +000039 if [ "$CHECK_MODE" = true ]; then
Philip Zeyligerbb020f52025-07-28 19:41:55 -070040 echo "Checking webui formatting with Prettier"
41 if ! npx prettier@3.5.3 --check .; then
42 echo "Webui files need formatting"
Philip Zeyliger8b00db12025-04-25 18:41:38 +000043 exit 1
44 fi
45 else
Philip Zeyligerbb020f52025-07-28 19:41:55 -070046 echo "Fixing webui formatting with Prettier"
47 npx prettier@3.5.3 --write .
48 echo "Webui formatting complete"
Philip Zeyliger8b00db12025-04-25 18:41:38 +000049 fi
Philip Zeyligerbb020f52025-07-28 19:41:55 -070050else
51 echo "No webui directory found, skipping Prettier check"
Philip Zeyliger8b00db12025-04-25 18:41:38 +000052fi
53
54if [ "$CHECK_MODE" = true ]; then
55 echo "All formatting checks passed"
56else
57 echo "All formatting has been fixed"
58fi