Skip to content

Commit 0066cb0

Browse files
authored
🤖 Fix fmt/fmt-check parity with clean Makefile design (#172)
## Problem `make fmt` and `make fmt-check` had different behaviors: - Different patterns (Makefile vs scripts/fmt.sh) - `make fmt` only ran Prettier, `make fmt-check` ran Prettier + Nix + shell - No single source of truth ## Solution Created `fmt.mk` that centralizes all formatting logic: - `make fmt` → `fmt-prettier` + `fmt-shell` + `fmt-nix` - `make fmt-check` → `fmt-prettier-check` + `fmt-shell-check` + `fmt-nix-check` Both use the same patterns and tools, guaranteed parity by construction. ## Changes - Add `fmt.mk`: All formatting rules in one place - Update `Makefile`: Include `fmt.mk`, remove duplicate logic - Format shell scripts with shfmt - Always use `bun x prettier` for reproducibility _Generated with `cmux`_
1 parent 6e0f0d5 commit 0066cb0

File tree

4 files changed

+90
-35
lines changed

4 files changed

+90
-35
lines changed

Makefile

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
# Adding New Targets:
1919
# Add `## Description` after the target to make it appear in `make help`
2020

21+
# Include formatting rules
22+
include fmt.mk
23+
2124
.PHONY: all build dev start clean help
2225
.PHONY: build-renderer version build-icons
23-
.PHONY: lint lint-fix fmt fmt-check fmt-shell fmt-nix fmt-nix-check fmt-shell-check typecheck static-check
26+
.PHONY: lint lint-fix typecheck static-check
2427
.PHONY: test test-unit test-integration test-watch test-coverage test-e2e
2528
.PHONY: dist dist-mac dist-win dist-linux
2629
.PHONY: docs docs-build docs-watch
2730
.PHONY: ensure-deps
2831

29-
# Prettier patterns for formatting
30-
PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'tests/**/*.{ts,json}' 'docs/**/*.{md,mdx}' '*.{json,md}'
3132
TS_SOURCES := $(shell find src -type f \( -name '*.ts' -o -name '*.tsx' \))
3233

3334
# Default target
@@ -124,23 +125,6 @@ lint: ## Run linter and typecheck
124125
lint-fix: ## Run linter with --fix
125126
@./scripts/lint.sh --fix
126127

127-
fmt: ## Format code with Prettier
128-
@echo "Formatting TypeScript/JSON/Markdown files..."
129-
@bun x prettier --write $(PRETTIER_PATTERNS)
130-
131-
fmt-check: ## Check code formatting
132-
@./scripts/fmt.sh --check
133-
@./scripts/fmt.sh --nix-check
134-
135-
fmt-shell: ## Format shell scripts with shfmt
136-
@./scripts/fmt.sh --shell
137-
138-
fmt-nix: ## Format flake.nix with nix fmt
139-
@./scripts/fmt.sh --nix
140-
141-
fmt-nix-check: ## Check flake.nix formatting
142-
@./scripts/fmt.sh --nix-check
143-
144128
typecheck: src/version.ts ## Run TypeScript type checking
145129
@./scripts/typecheck.sh
146130

@@ -196,10 +180,4 @@ clean: ## Clean build artifacts
196180
# Parallel build optimization - these can run concurrently
197181
.NOTPARALLEL: build-main # TypeScript can handle its own parallelism
198182

199-
fmt-shell-check: ## Check shell script formatting
200-
@if ! command -v shfmt &>/dev/null; then \
201-
echo "shfmt not found. Install with: brew install shfmt"; \
202-
exit 1; \
203-
fi
204-
@echo "Checking shell script formatting..."
205-
@shfmt -i 2 -ci -bn -d scripts
183+

fmt.mk

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Formatting Rules
2+
# ================
3+
# This file contains all code formatting logic.
4+
# Included by the main Makefile.
5+
6+
.PHONY: fmt fmt-check fmt-prettier fmt-prettier-check fmt-shell fmt-shell-check fmt-nix fmt-nix-check
7+
8+
# Centralized patterns - single source of truth
9+
PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'tests/**/*.ts' 'docs/**/*.md' 'package.json' 'tsconfig*.json' 'README.md'
10+
SHELL_SCRIPTS := scripts
11+
12+
# Always use bun x prettier for reproducibility (uses package.json version)
13+
PRETTIER := bun x prettier
14+
15+
# Tool availability checks
16+
SHFMT := $(shell command -v shfmt 2>/dev/null)
17+
NIX := $(shell command -v nix 2>/dev/null)
18+
19+
fmt: fmt-prettier fmt-shell fmt-nix
20+
@echo "==> All formatting complete!"
21+
22+
fmt-check: fmt-prettier-check fmt-shell-check fmt-nix-check
23+
@echo "==> All formatting checks passed!"
24+
25+
fmt-prettier:
26+
@echo "Formatting TypeScript/JSON/Markdown files..."
27+
@$(PRETTIER) --write $(PRETTIER_PATTERNS)
28+
29+
fmt-prettier-check:
30+
@echo "Checking TypeScript/JSON/Markdown formatting..."
31+
@$(PRETTIER) --check $(PRETTIER_PATTERNS)
32+
33+
fmt-shell:
34+
ifeq ($(SHFMT),)
35+
@echo "Error: shfmt not found. Install with: brew install shfmt"
36+
@exit 1
37+
else
38+
@echo "Formatting shell scripts..."
39+
@shfmt -i 2 -ci -bn -w $(SHELL_SCRIPTS)
40+
endif
41+
42+
fmt-shell-check:
43+
ifeq ($(SHFMT),)
44+
@echo "Error: shfmt not found. Install with: brew install shfmt"
45+
@exit 1
46+
else
47+
@echo "Checking shell script formatting..."
48+
@shfmt -i 2 -ci -bn -d $(SHELL_SCRIPTS)
49+
endif
50+
51+
fmt-nix:
52+
ifeq ($(NIX),)
53+
@echo "Nix not found; skipping Nix formatting"
54+
else ifeq ($(wildcard flake.nix),)
55+
@echo "flake.nix not found; skipping Nix formatting"
56+
else
57+
@echo "Formatting Nix flake..."
58+
@nix fmt -- flake.nix
59+
endif
60+
61+
fmt-nix-check:
62+
ifeq ($(NIX),)
63+
@echo "Nix not found; skipping Nix format check"
64+
else ifeq ($(wildcard flake.nix),)
65+
@echo "flake.nix not found; skipping Nix format check"
66+
else
67+
@echo "Checking flake.nix formatting..."
68+
@tmp_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/fmt-nix-check.XXXXXX"); \
69+
trap "rm -rf $$tmp_dir" EXIT; \
70+
cp flake.nix "$$tmp_dir/flake.nix"; \
71+
(cd "$$tmp_dir" && nix fmt -- flake.nix >/dev/null 2>&1); \
72+
if ! cmp -s flake.nix "$$tmp_dir/flake.nix"; then \
73+
echo "flake.nix is not formatted correctly. Run 'make fmt-nix' to fix."; \
74+
diff -u flake.nix "$$tmp_dir/flake.nix" || true; \
75+
exit 1; \
76+
fi
77+
endif

scripts/quick-cp-screenshot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ OUTPUT_FILE="$PROJECT_ROOT/docs/img/$FILENAME.webp"
3737

3838
# Convert PNG to WebP using cwebp (as suggested by lint)
3939
echo "Converting to WebP..."
40-
if ! command -v cwebp &> /dev/null; then
40+
if ! command -v cwebp &>/dev/null; then
4141
echo "❌ Error: cwebp not found. Install with: brew install webp"
4242
exit 1
4343
fi

scripts/setup-macos-signing.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ set -euo pipefail
1414
# Setup code signing certificate
1515
if [ -n "${MACOS_CERTIFICATE:-}" ]; then
1616
echo "Setting up code signing certificate..."
17-
echo "$MACOS_CERTIFICATE" | base64 -D > /tmp/certificate.p12
18-
echo "CSC_LINK=/tmp/certificate.p12" >> "$GITHUB_ENV"
19-
echo "CSC_KEY_PASSWORD=$MACOS_CERTIFICATE_PWD" >> "$GITHUB_ENV"
17+
echo "$MACOS_CERTIFICATE" | base64 -D >/tmp/certificate.p12
18+
echo "CSC_LINK=/tmp/certificate.p12" >>"$GITHUB_ENV"
19+
echo "CSC_KEY_PASSWORD=$MACOS_CERTIFICATE_PWD" >>"$GITHUB_ENV"
2020
else
2121
echo "⚠️ No code signing certificate provided - building unsigned"
2222
fi
2323

2424
# Setup notarization credentials
2525
if [ -n "${AC_APIKEY_ID:-}" ]; then
2626
echo "Setting up notarization credentials..."
27-
echo "$AC_APIKEY_P8_BASE64" | base64 -D > /tmp/AuthKey.p8
28-
echo "APPLE_API_KEY=/tmp/AuthKey.p8" >> "$GITHUB_ENV"
29-
echo "APPLE_API_KEY_ID=$AC_APIKEY_ID" >> "$GITHUB_ENV"
30-
echo "APPLE_API_ISSUER=$AC_APIKEY_ISSUER_ID" >> "$GITHUB_ENV"
27+
echo "$AC_APIKEY_P8_BASE64" | base64 -D >/tmp/AuthKey.p8
28+
echo "APPLE_API_KEY=/tmp/AuthKey.p8" >>"$GITHUB_ENV"
29+
echo "APPLE_API_KEY_ID=$AC_APIKEY_ID" >>"$GITHUB_ENV"
30+
echo "APPLE_API_ISSUER=$AC_APIKEY_ISSUER_ID" >>"$GITHUB_ENV"
3131
echo "✅ Notarization credentials configured"
3232
else
3333
echo "⚠️ No notarization credentials - skipping notarization"

0 commit comments

Comments
 (0)