-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Add GitLab output format #20155
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
Conversation
clap was rendering the backslashes too: ``` --output-format <OUTPUT_FORMAT> The format to use for printing diagnostic messages Possible values: - full: Print diagnostics verbosely, with context and helpful hints \[default\] - concise: Print diagnostics concisely, one per line - gitlab: Print diagnostics in the JSON format expected by GitLab Code Quality reports ```
this is necessary for every JSON-based output format so that the diagnostics render as one JSON array instead of a sequence of one-element arrays
based formats (only gitlab for now)
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
"check_name": "unresolved-reference", | ||
"description": "unresolved-reference: Name `x` used when not defined", |
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.
One minor note, I know this looks redundant, but GitLab doesn't render the check_name
anywhere, so we manually prepend this to the description now (#19881).
|
if is_human_readable { | ||
writeln!( | ||
self.printer.stream_for_success_summary(), | ||
"{}", | ||
"All checks passed!".green().bold() | ||
)?; | ||
} |
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'm assuming that we do the same thing for Ruff as well?
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.
Yep, pretty similar. Ruff has some Flags
for the Printer
that toggle showing these messages.
ruff/crates/ruff/src/printer.rs
Lines 85 to 93 in bbfcf6e
if self.flags.intersects(Flags::SHOW_VIOLATIONS) { | |
let remaining = diagnostics.inner.len(); | |
let total = fixed + remaining; | |
if fixed > 0 { | |
let s = if total == 1 { "" } else { "s" }; | |
writeln!( | |
writer, | |
"Found {total} error{s} ({fixed} fixed, {remaining} remaining)." | |
)?; |
## Summary This wires up the GitLab output format moved into `ruff_db` in astral-sh#20117 to the ty CLI. While I was here, I made one unrelated change to the CLI docs. Clap was rendering the escapes around the `\[default\]` brackets for the `full` output, so I just switched those to parentheses: ``` --output-format <OUTPUT_FORMAT> The format to use for printing diagnostic messages Possible values: - full: Print diagnostics verbosely, with context and helpful hints \[default\] - concise: Print diagnostics concisely, one per line - gitlab: Print diagnostics in the JSON format expected by GitLab Code Quality reports ``` ## Test Plan New CLI test, and a manual test with `--config 'terminal.output-format = "gitlab"'` to make sure this works as a configuration option too. I also tried piping the output through jq to make sure it's at least valid JSON
## Summary This PR wires up the GitHub output format moved to `ruff_db` in #20320 to the ty CLI. It's a bit smaller than the GitLab version (#20155) because some of the helpers were already in place, but I did factor out a few `DisplayDiagnosticConfig` constructor calls in Ruff. I also exposed the `GithubRenderer` and a wrapper `DisplayGithubDiagnostics` type because we needed a way to configure the program name displayed in the GitHub diagnostics. This was previously hard-coded to `Ruff`: <img width="675" height="247" alt="image" src="https://github.com/user-attachments/assets/592da860-d2f5-4abd-bc5a-66071d742509" /> Another option would be to drop the program name in the output format, but I think it can be helpful in workflows with multiple programs emitting annotations (such as Ruff and ty!) ## Test Plan New CLI test, and a manual test with `--config 'terminal.output-format = "github"'`
Summary
This wires up the GitLab output format moved into
ruff_db
in #20117 to the ty CLI.While I was here, I made one unrelated change to the CLI docs. Clap was rendering the escapes around the
\[default\]
brackets for thefull
output, so I just switched those to parentheses:Test Plan
New CLI test, and a manual test with
--config 'terminal.output-format = "gitlab"'
to make sure this works as a configuration option too. I also tried piping the output through jq to make sure it's at least valid JSON