-
Notifications
You must be signed in to change notification settings - Fork 926
Implemented rough draft of check
write mode.
#2539
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
Changes from 6 commits
2b258f7
533df58
b0ece6b
bda78f8
d5944ee
7412ff6
0fb92c6
4860852
a3006b9
257715a
8755d1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ fn make_opts() -> Options { | |
"", | ||
"write-mode", | ||
"How to write output (not usable when piping from stdin)", | ||
"[replace|overwrite|display|plain|diff|coverage|checkstyle]", | ||
"[replace|overwrite|display|plain|diff|check|coverage|checkstyle]", | ||
); | ||
|
||
opts | ||
|
@@ -287,6 +287,10 @@ fn execute(opts: &Options) -> FmtResult<Summary> { | |
} | ||
|
||
let mut error_summary = Summary::default(); | ||
if let Some(mode) = options.write_mode { | ||
error_summary.add_write_mode(mode) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I suggested a refactoring to avoid saving the write mode in the error summary, but maybe that was on another PR since I can't find any trace of it. I think that by moving some code around in the main function so that we know the write mode (i.e., process the opts outside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No worries.
I think that's a good idea. I wanted to introduce a minimally invasive change with this PR, but if exit codes are gonna change, so should this. |
||
for file in files { | ||
if !file.exists() { | ||
eprintln!("Error: file `{}` does not exist", file.to_str().unwrap()); | ||
|
@@ -342,13 +346,12 @@ fn main() { | |
Ok(summary) => { | ||
if summary.has_operational_errors() { | ||
1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is a bit wrong. IIRC in check mode, the exit code should be either 0 or 1, but this change does not seem to respect it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I haven't gotten around to implementing #1977 (comment), but when I do later today, this the exit code handling should be far nicer and correct, wheras with my PR, it is not. |
||
} else if summary.has_diff && summary.write_mode == WriteMode::Check { | ||
1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will probably be easier to change the other exit codes now, rather than later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alrighty! I'll implement the stuff suggested in this comment: #1977 (comment) |
||
} else if summary.has_parsing_errors() { | ||
2 | ||
1 | ||
} else if summary.has_formatting_errors() { | ||
3 | ||
} else if summary.has_diff { | ||
// should only happen in diff mode | ||
4 | ||
1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will update later today. |
||
} else { | ||
assert!(summary.has_no_errors()); | ||
0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would re-word, something like: "Checks if the program's formatting matches what rustfmt would do. Silently exits with code 0 if so, emits a diff and exits with code 1 if not. This option is designed to be run in CI-like where a non-zero exit signifies incorrect formatting."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that; can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.