Skip to content

[Feature Request] Add non-mutating mojo format --check mode #6885

Open

Description

@yablokolabs

Summary

Please expose a non-mutating --check mode on mojo format for CI and pre-commit use.

This is the still-unresolved use case from #1249. That issue was closed with an explicit invitation to open a new issue if detecting formatting changes remained important.

Reproduction

Verified on both:

  • Mojo 1.0.0 (ed45d567)
  • Mojo 1.1.0.dev2026081105 (e929a99e)

mojo format --help exposes only --line-length and --quiet. Running mojo format rewrites files and returns exit code 0 when formatting changes were required, so CI cannot distinguish an already-formatted tree without modifying the workspace and adding shell/script logic.

Requested behavior

mojo format --check <sources...>
  • do not modify source files;
  • exit 0 when every source is already formatted;
  • exit 1 when formatting changes would be required;
  • use a distinct nonzero status for parse/internal formatter failures;
  • report which files require formatting.

An optional future --diff mode would also be useful, but is not required for the core request.

Motivation

This enables a direct, race-free CI task such as:

format-check = "mojo format --check src tests examples"

The public repository already invokes the underlying mblack formatter with --check --diff in bazel/lint/mblack-wrapper.py, so this appears to be an existing formatter capability that is not exposed by the mojo format CLI.

Related: #1249

Assisted-by: AI

Activity

  1. added
    good first issue
    and removed on Aug 13, 2026
  2. AmrDeveloper commented on Aug 20, 2026

    @AmrDeveloper

    I created a draft PR to introduce the check subcommand, but I can't create valid and invalid lit tests with the pinned Mojo version

    #6938

    Once it changes, I will convert the draft to active

    Note: Not sure if there is currently a workaround to test it. What I did locally was intercepting and printing the args and using them with mblack

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions