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