Write full Jupyter notebook to stdout (#7748)

## Summary

When writing back notebooks via `stdout`, we need to write back the
entire JSON content, not _just_ the fixed source code. Otherwise,
writing the output _back_ to the file will yield an invalid notebook.

Closes https://github.com/astral-sh/ruff/issues/7747

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-10-02 10:20:13 -04:00 committed by GitHub
parent c71ff7eae1
commit ebdfcee87f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 190 additions and 6 deletions

View file

@ -402,7 +402,7 @@ pub(crate) fn lint_stdin(
match fix_mode {
flags::FixMode::Apply => {
// Write the contents to stdout, regardless of whether any errors were fixed.
io::stdout().write_all(transformed.source_code().as_bytes())?;
transformed.write(&mut io::stdout().lock())?;
}
flags::FixMode::Diff => {
// But only write a diff if it's non-empty.
@ -441,7 +441,7 @@ pub(crate) fn lint_stdin(
// Write the contents to stdout anyway.
if fix_mode.is_apply() {
io::stdout().write_all(source_kind.source_code().as_bytes())?;
source_kind.write(&mut io::stdout().lock())?;
}
(result, fixed)