blob: 30087e31c25d8ece27f20799e5e22ecfe38a5994 [file] [log] [blame]
Philip Zeyliger8b00db12025-04-25 18:41:38 +00001#!/bin/bash
2set -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
16# 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
34
35# Webui formatting with Prettier
36echo "Checking webui formatting..."
37if [ -d "./webui" ]; then
38 cd webui
39 if [ "$CHECK_MODE" = true ]; then
40 echo "Checking webui formatting with Prettier"
41 if ! npx prettier --check .; then
42 echo "Webui files need formatting"
43 exit 1
44 fi
45 else
46 echo "Fixing webui formatting with Prettier"
47 npx prettier --write .
48 echo "Webui formatting complete"
49 fi
50else
51 echo "No webui directory found, skipping Prettier check"
52fi
53
54if [ "$CHECK_MODE" = true ]; then
55 echo "All formatting checks passed"
56else
57 echo "All formatting has been fixed"
58fi