Skip to content

Commit 4a20d2e

Browse files
committed
fix(git): refine deno formatting hook with config and update options
Key Changes Made: * Removed --ext flag - Now uses deno fmt without extensions to respect deno.json * Expanded file detection - Checks for .ts .js .tsx .jsx .md .json .jsonc (what Deno actually formats) * Skip duplicate markdown formatting - Deno projects don't need separate Prettier for markdown since deno fmt handles it * Better logging - More accurate messages about what was formatted No deno.json Changes Needed! The hook will now: * Respect exclude patterns * Use existing fmt and lint configurations * Work with existing deno task fmt and deno task lint commands
1 parent 43a39c9 commit 4a20d2e

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

adhoc/git/hooks/10-format-code

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ files_changed=false
1010
# Format TypeScript/JavaScript with Deno
1111
if command -v deno >/dev/null 2>&1; then
1212
log_info "Formatting with deno fmt..."
13-
if deno fmt --ext=ts,js,tsx,jsx; then
14-
if files_modified '*.ts *.js *.tsx *.jsx'; then
13+
# Use deno fmt without --ext to respect deno.json configuration
14+
if deno fmt; then
15+
# Check if any supported files were modified (deno handles exclusions)
16+
if files_modified '*.ts *.js *.tsx *.jsx *.md *.json *.jsonc'; then
1517
files_changed=true
16-
log_success "TypeScript/JavaScript formatted"
18+
log_success "Files formatted with Deno"
1719
else
18-
log_info "TypeScript/JavaScript already formatted"
20+
log_info "Files already formatted"
1921
fi
2022
else
2123
log_error "deno fmt failed"
@@ -32,19 +34,23 @@ elif [ -f "package.json" ] && command -v prettier >/dev/null 2>&1; then
3234
fi
3335
fi
3436

35-
# Format Markdown with Prettier
36-
if command -v prettier >/dev/null 2>&1; then
37-
log_info "Formatting Markdown..."
38-
if prettier --write '**/*.md' --print-width=100 --prose-wrap=preserve; then
39-
if files_modified '*.md'; then
40-
files_changed=true
41-
log_success "Markdown formatted"
42-
else
43-
log_info "Markdown already formatted"
37+
# For Deno projects, skip separate markdown formatting since deno fmt handles it
38+
# Only do separate markdown formatting for non-Deno projects
39+
if ! command -v deno >/dev/null 2>&1; then
40+
# Format Markdown with Prettier (only if not a Deno project)
41+
if command -v prettier >/dev/null 2>&1; then
42+
log_info "Formatting Markdown..."
43+
if prettier --write '**/*.md' --print-width=100 --prose-wrap=preserve; then
44+
if files_modified '*.md'; then
45+
files_changed=true
46+
log_success "Markdown formatted"
47+
else
48+
log_info "Markdown already formatted"
49+
fi
4450
fi
51+
else
52+
log_warn "prettier not found - install with: brew install prettier"
4553
fi
46-
else
47-
log_warn "prettier not found - install with: brew install prettier"
4854
fi
4955

5056
# Format other languages based on project type

0 commit comments

Comments
 (0)