mojo-format

Format Mojo code using mojo format command. Use when preparing code for commit or when formatting checks fail.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

The Mojo Format skill is a specialized utility designed to automate the standardization of Mojo source code using the official 'mojo format' command. It ensures consistent indentation, line length, and operator spacing across individual files or entire directories, helping developers maintain professional code quality and adhere to Mojo syntax standards without manual effort.

Use Cases

  • Pre-commit Optimization: Automatically format Mojo code before committing to a repository to ensure clean diffs and prevent CI/CD pipeline failures due to style violations.
  • Code Review Efficiency: Quickly resolve formatting-related feedback in pull requests by applying consistent styling across the entire project codebase.
  • Legacy Code Refactoring: Standardize indentation and spacing in older Mojo files or inherited projects to improve readability and maintainability.
  • Automated Compliance Checks: Use the check-only mode to verify if files adhere to formatting standards within automated local scripts or pre-commit hooks.
namemojo-format
description"Format Mojo code using mojo format command. Use when preparing code for commit or when formatting checks fail."
mcp_fallbacknone
categorymojo

Mojo Format Skill

Format Mojo code files to ensure consistent style.

When to Use

  • Preparing code for commit
  • Pre-commit hook reports formatting issues
  • Code review requests formatting fixes
  • Verifying formatting compliance

Quick Reference

# Format single file
pixi run mojo format path/to/file.mojo

# Format directory
pixi run mojo format `find src/ -name "*.mojo"`

# Check without modifying
pixi run mojo format --check path/to/file.mojo

Workflow

  1. Identify files - Single file or directory
  2. Run formatter - pixi run mojo format <path>
  3. Verify changes - Review formatted output
  4. Commit - Stage and commit formatted code

Mojo-Specific Notes

  • Formats indentation (4 spaces), line length, spacing around operators
  • Does NOT change logic, variable names, or comment content
  • Preserves all comments, only adjusts spacing
  • Safe to run multiple times (idempotent)

Error Handling

Error Cause Solution
Syntax error Invalid Mojo syntax Fix syntax before formatting
File not found Wrong path Verify file exists
Permission denied File permissions Check chmod settings
Mojo not installed Missing Mojo Install via pixi or Magic

References

  • .claude/shared/mojo-guidelines.md - Mojo syntax standards
  • .pre-commit-config.yaml - Pre-commit hook configuration