JUnit output for ty lints#22125
Conversation
|
Slowly working on this one Links back to astral-sh/ty#1476 |
Typing conformance resultsNo changes detected ✅ |
|
|
49c648f to
d32b2ed
Compare
crates/ruff/tests/cli/snapshots/cli__format__output_format_junit.snap
Outdated
Show resolved
Hide resolved
|
Thanks for working on this. For an initial version, I suggest focusing on just rendering the |
5ca12d6 to
b1b7686
Compare
|
I removed the code for handling sub diagnostics and snippets with the full renderer and instead just print out the concise message I changed how the output is formatted, making the XML a bit easier on human eyes for both ruff and ty junit formats, but it was done by specifying indents and newlines which may be brittle if the format is changed in future. I can squash these commits if needed. I left them as-is in case some of the history is useful in future |
0a8e2bd to
433b5a0
Compare
|
Is this PR ready for review ? |
|
Yes! |
MichaReiser
left a comment
There was a problem hiding this comment.
Thank you.
This requires some more work to remove the remaining mentions of ruff and we should add a CLI test demonstrating that the output format works in ty (which I'd expect to panic right now). See
ruff/crates/ty/tests/cli/main.rs
Lines 656 to 740 in 433b5a0
| <testsuites name="ruff" tests="1" failures="1" errors="0"> | ||
| <testsuite name="/call.py" tests="1" disabled="0" errors="0" failures="1" package="org.ruff"> | ||
| <testcase name="org.ruff.F821" classname="/call" line="1" column="1"> | ||
| <failure message="Undefined name `f`">line 1, col 1, Undefined name `f`</failure> |
There was a problem hiding this comment.
We need to parametrize the output format with the tool name so that it mentions ty here (when using in ty), similar to how it's done for the GithubEmitter
ruff/crates/ruff_db/src/diagnostic/render/github.rs
Lines 3 to 6 in 1644786
| .extra | ||
| .insert(XmlString::new("package"), XmlString::new("org.ruff")); | ||
|
|
||
| let classname = Path::new(filename).with_extension(""); |
There was a problem hiding this comment.
We need to make changes to group_diagnostics_by_filename to support both ruff and ty files (it calls expect_ruff_file).
| let classname = Path::new(filename).with_extension(""); | ||
| case.set_classname(classname.to_str().unwrap_or(filename)); | ||
| let msg = diagnostic.concise_message().to_str(); | ||
| case.status.set_message(msg.clone()); |
There was a problem hiding this comment.
Nit: I've a slight preference to keep status mutable as it was before and setting its fields before passing it to TestCase::new
| col = location.column, | ||
| )) | ||
| }) | ||
| .unwrap_or_default(); |
There was a problem hiding this comment.
I don't think we should use unwrap_or_default here. We're very intentional about omitting line/column information in some diagnostics if they apply to the entire file and we should preserve this here
433b5a0 to
aa3289e
Compare
This uses existing code from ruff and "just works". The test cases output are okay, but they are missing bits of data that would be useful, and would normally be present in the default output format. I'm not sure what approach I will take from here, but I think, if it's possible, it would be good to have the entire text message that would normally appear, in the failure message of the junit test cases. Any decent junit report parser should display these well, in places such as the results of a CI job.
Unsure if it's desired to have them formatted like this or whether they should be some kind of additional structure
Not sure if there are other sub diagnostic types that could end up here. Will need to look around and see if that's the case
Also added the severity as a prefix, to emulate what the default formatter looks like for these messages. Still haven't quite worked out how to get it to print out a snippet of the code with arrows/underlines. Maybe leave that for later. The amount of information in the junit report seems sufficient for a user to track down the issue, at the moment.
Rather than trying to do a full renderer, including code snippets.
fd0071e to
e6b7de6
Compare
Memory usage reportMemory usage unchanged ✅ |
Summary -- This is a follow-up to #22125, which added a `program` field to the shared `DisplayDiagnosticConfig` type. We can reuse this in the GitHub rendering too to avoid some of the special casing we had just for Ruff. The one wrinkle here is that we previously used capital `Ruff` for GitHub diagnostics, but we use `ruff` in the JUnit diagnostics. I think it's probably fine to change this in the GitHub diagnostics, but it felt worth calling out. Test Plan -- Existing tests with updated snapshots showing the case change
) Summary -- This is a follow-up to #22125, which added a `program` field to the shared `DisplayDiagnosticConfig` type. We can reuse this in the GitHub rendering too to avoid some of the special casing we had just for Ruff. The one wrinkle here is that we previously used capital `Ruff` for GitHub diagnostics, but we use `ruff` in the JUnit diagnostics. I think it's probably fine to change this in the GitHub diagnostics, but it felt worth calling out. Test Plan -- Existing tests with updated snapshots showing the case change
| TestEnvironment { | ||
| db: TestDb::new(), | ||
| config: DisplayDiagnosticConfig::default(), | ||
| config: DisplayDiagnosticConfig::new("ty"), |
There was a problem hiding this comment.
better for avoid snapshot modifications (ruff lint codes after ty name) in this PR:
| config: DisplayDiagnosticConfig::new("ty"), | |
| config: DisplayDiagnosticConfig::new("ruff"), |
Summary
Adding JUnit XML output for
tyTest Plan
Reusing existing tests, still working this out, will amend this description later when I figure out how to specifically test
tylints, it seems they already are but will verify