Skip to content

Conversation

@stuartc
Copy link
Member

@stuartc stuartc commented Oct 22, 2025

Description

This PR adds automatic code formatting on commit using elixir_git_hooks.

When you commit code, git hooks now automatically format your staged files:

  • Elixir/Phoenix files (.ex, .exs, .heex) with mix format
  • JavaScript/TypeScript files (.js, .ts, .tsx, .jsx) with prettier
  • Markdown files (.md) with prettier

The hooks format the files and re-stage them, so your commit always contains properly formatted code. If the formatter removes your only changes (like a blank line that violated formatting rules), the commit is blocked with a clear message.

Re #269

Validation steps

  1. Make a change to an Elixir file with bad formatting (e.g., remove spaces around operators)
  2. Stage and commit the file
  3. Verify the pre-commit hook formats it automatically
  4. Check the committed file is properly formatted
  5. Try committing a file where the only change is a formatting error that gets auto-fixed
  6. Verify the commit is blocked with "No changes to commit after formatting"

Additional notes for the reviewer

The hooks run on pre-commit (not pre-push as suggested in #269). This catches formatting issues earlier in the workflow. The hooks are configured in config/dev.exs and only run in development mode.

The git_hooks package auto-installs hooks when you run mix compile, so developers don't need to manually set anything up.

AI Usage

  • Code generation (copilot but not intellisense)
  • Strategy / design
  • Optimisation / refactoring
  • Learning or fact checking
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Configure git_hooks to automatically format staged files before commit:
- Run mix format on .ex, .exs, and .heex files
- Run prettier on .js, .ts, .tsx, .jsx, and .md files
- Auto-stage formatted files to include in commit
@github-project-automation github-project-automation bot moved this to New Issues in v2 Oct 22, 2025
@stuartc stuartc requested a review from midigofrank October 22, 2025 10:02
[ci skip]
@stuartc stuartc self-assigned this Oct 22, 2025
@taylordowns2000 taylordowns2000 merged commit 334fb9a into main Oct 22, 2025
@taylordowns2000 taylordowns2000 deleted the git-hooks branch October 22, 2025 11:35
@github-project-automation github-project-automation bot moved this from New Issues to Done in v2 Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants