Skip to content

[Feature Request] Add --check option to mojo format #1249

Closed

Description

@guidorice

Review Mojo's priorities

What is your request?

Please consider adding a --check option, which returns an exit code of

  • code 0 if nothing would change;
  • code 1 if some files would be reformatted; or
  • code 123 if there was an internal error

Here is the equivalent feature for black: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#check

What is your motivation for this change?

Then it would be nice to add/enforce mojo formatting in CI workflows.

Any other details?

No response

Activity

  1. added
    enhancement
    mojo
    on Nov 8, 2023
  2. guidorice commented on Dec 5, 2023

    @guidorice
    Author

    In mojo 0.6 mojo format returns a non-zero exit code when some files could not be reformatted. I think this is a change from 0.5 but did not see it in the 0.6 release notes. However this seems sufficient for CI/CD like purposes, it would be fine to close this issue.

  3. guidorice commented on Dec 16, 2023

    @guidorice
    Author

    I just revisited this, and it appears that occurrence of formatting changes cannot be detected without additional shell scripting/workarounds. For example, this reformatted 1 file, but returned a zero exit code (success). So I think a --check option would be helpful.

    $ mojo format .
    reformatted geo_features/test/geom/test_line_string.mojo
    
    All done! ✨ 🍰 ✨
    1 file reformatted, 41 files left unchanged.
    $ echo $?
    0
  4. added
    mojo-repo
    on Apr 29, 2024
  5. conorbronsdon commented on Mar 28, 2026

    @conorbronsdon
    Contributor

    mojo format now returns a non-zero exit code when files can't be reformatted, as @guidorice noted. However, @guidorice also found it returns zero when files are reformatted (just different, not broken) — so a dedicated --check flag for CI (detect any changes) may still be useful. Closing the original request as the exit-code behavior covers the core ask, but if the "detect any formatting changes" use case matters to you, please open a new issue. 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

    enhancementmojomojo-repo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions