Skip to content

API ignores the "check" option #524

@LordFckHelmchen

Description

@LordFckHelmchen

Describe the bug

context
When I format a file via mdformat.file and pass the check option.

expectation
I expect the call to error-out if the file is not formatted similar to what the CLI does.

bug
Instead the file is always reformatted.

It would be great to have the API behave the same as the CLI to work in Python-based tooling w/o having to subprocess-call mdformat.

On a side-note, one can also specify arbitrary options that get silently ignored.

Reproduce the bug

from pathlib import Path
import mdformat

file = Path("ill_formatted.md")
file.write_text("   # TITLE WITH LEADING SPACES")
print(f"Before\n{file.read_text()}")
mdformat.file(file, options={"check": True})
print(f"After\n{file.read_text()}")
file.unlink()

Output:

Before
   # TITLE WITH LEADING SPACES
After
# TITLE WITH LEADING SPACES

List your environment

Python 3.13.2 & mdformat 0.7.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions