Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Jul 10, 2025

Summary

See #19133 (comment) for recent discussion. This PR moves to using structs for the types in our JSON output format instead of the json! macro.

I didn't rename any of the message references because that should be handled when rebasing #19133 onto this.

My plan for handling the preview behavior with the new diagnostics is to use a wrapper enum. Something like:

#[derive(Serialize)]
#[serde(untagged)]
pub(crate) enum JsonDiagnostic<'a> {
    Old(OldJsonDiagnostic<'a>),
}

#[derive(Serialize)]
pub(crate) struct OldJsonDiagnostic<'a> {
    // ...
}

Initially I thought I could use a &dyn Serialize for the affected fields, but I see that Serialize isn't dyn-compatible in testing this now.

Test Plan

Existing tests. One quirk of the new types is that their fields are in alphabetical order. I guess json! sorts the fields alphabetically? The tests were failing before I sorted the struct fields.

Other formats

It looks like the rdjson, sarif, and gitlab formats also use json!, so if we decide to merge this, I can do something similar for those before moving them to the new diagnostic format.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 10, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre marked this pull request as ready for review July 10, 2025 22:59
@ntBre ntBre requested a review from MichaReiser July 10, 2025 22:59
@ntBre ntBre added internal An internal refactor or improvement diagnostics Related to reporting of diagnostics. labels Jul 10, 2025
url: Option<String>,
}

struct ExpandedEdits<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

I'm leaning towards reverting the last commit. The old implementation carefully avoided allocating a new vector for the edits. I also don't think that changing this is necessary for making this more typed. We can just replace the

           let value = json!({
                "content": edit.content().unwrap_or_default(),
                "location": location_to_json(location),
                "end_location": location_to_json(end_location)
            });

and initialize and then serialize said struct instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, reverted!

This reverts commit 4733e0a.
@ntBre ntBre merged commit f14ee9e into main Jul 11, 2025
35 checks passed
@ntBre ntBre deleted the brent/json-types branch July 11, 2025 13:37
ntBre added a commit that referenced this pull request Jul 15, 2025
## Summary

Another output format like #19133. This is the
[reviewdog](https://github.com/reviewdog/reviewdog) output format, which
is somewhat similar to regular JSON. Like #19270, in the first commit I
converted from using `json!` to `Serialize` structs, then in the second
commit I moved the module to `ruff_db`.

The reviewdog
[schema](https://github.com/reviewdog/reviewdog/blob/320a8e73a94a09248044314d8ca326a6cd710692/proto/rdf/jsonschema/DiagnosticResult.json)
seems a bit more flexible than our JSON schema, so I'm not sure if we
need any preview checks here. I'll flag the places I wasn't sure about
as review comments.

## Test Plan

New tests in `rdjson.rs`, ported from the old `rjdson.rs` module, as
well as the new CLI output tests.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants