Skip to content

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Aug 29, 2025

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 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

ntBre added 6 commits August 29, 2025 12:37
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
@ntBre ntBre added cli Related to the command-line interface ty Multi-file analysis & type inference labels Aug 29, 2025
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Comment on lines +641 to +642
"check_name": "unresolved-reference",
"description": "unresolved-reference: Name `x` used when not defined",
Copy link
Contributor Author

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).

Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@ntBre ntBre marked this pull request as ready for review August 29, 2025 17:14
Comment on lines +325 to +331
if is_human_readable {
writeln!(
self.printer.stream_for_success_summary(),
"{}",
"All checks passed!".green().bold()
)?;
}
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 assuming that we do the same thing for Ruff as well?

Copy link
Contributor Author

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.

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)."
)?;

@ntBre ntBre merged commit aee9350 into main Sep 3, 2025
40 checks passed
@ntBre ntBre deleted the brent/ty-gitlab branch September 3, 2025 13:08
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
## 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
ntBre added a commit that referenced this pull request Sep 17, 2025
## 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"'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the command-line interface ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants