Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Implement d2 fmt --check #2253

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nwalters512
Copy link

@nwalters512 nwalters512 commented Dec 16, 2024

This PR implements a --check flag as described in #1180. I followed what Prettier does: it logs a warning for each unformatted file, and if any were found, it prints the number of unformatted files and a "run XYZ to fix" message.

Closes #1180.

@nwalters512 nwalters512 marked this pull request as ready for review December 16, 2024 23:38
Copy link
Collaborator

@alixander alixander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 thorough PR!

gotFoo := readFile(t, dir, "foo.d2")
gotBar := readFile(t, dir, "bar.d2")
assert.Equal(t, "a ---> b", string(gotFoo))
assert.Equal(t, "x ---> y", string(gotBar))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extend this to have d2 fmt --check run on formatted files?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7cb58fc. I added a formatted file to this first test case, and also added another one where all the files are already formatted correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

d2 fmt --check
2 participants