Add --check flag to smithy format#3094
Draft
yasmewad wants to merge 2 commits into
Draft
Conversation
The `smithy format` command previously only supported in-place formatting, with no way to verify formatting without modifying files. This made CI enforcement impossible without risking unintended writes in read-only pipelines. Add a `--check` mode that compares each file's current content against its formatted output and exits with code 2 if any files differ. Refactor the file-walking logic into a shared `walkSmithyFiles` helper used by both `formatFile` and the new `checkFile`, fixing a `Files.find` stream leak with try-with-resources in the process.
b12d5a5 to
bb7f32c
Compare
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
kstich
reviewed
May 7, 2026
| @Test | ||
| public void checkUnformattedFile() { | ||
| IntegUtils.run("bad-formatting", ListUtils.of("format", "--check", "model"), result -> { | ||
| assertThat(result.getExitCode(), equalTo(2)); |
Contributor
There was a problem hiding this comment.
Suggested change
| assertThat(result.getExitCode(), equalTo(2)); | |
| assertThat(result.getExitCode(), equalTo(1)); |
The CliError thrown for this will get turned into an exit 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
smithy formatcommand previously only supported in-place formatting, with no way to verify formatting without modifying files. This made CI enforcement impossible without risking unintended writes in read-only pipelines.Add a
--checkmode that compares each file's current content against its formatted output and exits with code 2 if any files differ. Refactor the file-walking logic into a sharedwalkSmithyFileshelper used by bothformatFileand the newcheckFile, fixing aFiles.findstream leak with try-with-resources in the process.Fixes #2317
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.