Repository: astral-sh/ruff
File: crates/ty_test/src/lib.rs (Rust)

Code before:

                    let absolute_line_number_value = absolute_line_number.map(OneIndexed::get);
                    let cli_line_info = match absolute_line_number_value {
                        Some(line) => format!("{relative_fixture_path}:{line}"),
                        None => format!("{relative_fixture_path}:?"),
                    };

                    match output_format {
                        OutputFormat::Cli => {
                            for failure in failures {
                                println!("  {} {failure}", cli_line_info.as_str().cyan());
                            }
                            if let Some(err) = line_number_error.as_deref() {
                                println!("  {} {err}", cli_line_info.as_str().cyan());
                            }
                        }
                        OutputFormat::GitHub => {
                            for failure in failures {
                                if let Some(line) = absolute_line_number_value {
                                    println!(
                                        "::error file={absolute_fixture_path},line={line}::{failure}"
                                    );
                                } else {
                                    println!("::error file={absolute_fixture_path}::{failure}");
                                }
                            }
                            if let Some(err) = line_number_error.as_deref() {
                                if let Some(line) = absolute_line_number_value {
                                    println!(
                                        "::error file={absolute_fixture_path},line={line}::{err}"
                                    );
                                } else {
                                    println!("::error file={absolute_fixture_path}::{err}");
                                }
                            }
                        }
                    }
                }
            }
        }
        if let Err(inconsistencies) = inconsistencies {
            any_failures = true;
            for inconsistency in inconsistencies {
                match output_format {
                    OutputFormat::Cli => {
                        let info = relative_fixture_path.to_string().cyan();
                        println!("  {info} {inconsistency}");
                    }
                    OutputFormat::GitHub => {
                        println!("::error file={absolute_fixture_path}::{inconsistency}");
                    }

Review comment (bug):
I'm slightly leaning towards skipping the `failures` if the line number can't be mapped because I suspect it leads to slightly simpler code but I'm curious to hear why you decide to emit them even if the file mapping failed.

Code after:
                        Ok(line_number) => line_number,
                        Err(last_line_number) => {
                            print!("{}",
                                output_format.display_error(
                                    file,
                                    last_line_number,
                                    "Found a trailing assertion comment (e.g., `# revealed:` or `# error:`) \
                                    not followed by any statement."
                                )
                            );

                            continue;
                        }
                    };

                    for failure in failures {
                        print!(
                            "{}",
                            output_format.display_error(file, absolute_line_number, failure)
                        );
                    }
                }
            }
        }
        if let Err(inconsistencies) = inconsistencies {
            any_failures = true;
            for inconsistency in inconsistencies {
                match output_format {
                    OutputFormat::Cli => {
                        let info = relative_fixture_path.to_string().cyan();
                        println!("  {info} {inconsistency}");
                    }
                    OutputFormat::GitHub => {
                        println!("::error file={absolute_fixture_path}::{inconsistency}");
                    }
                }
            }
        }

        if this_test_failed && output_format.is_cli() {
            let escaped_test_name = test.name().replace('\'', "\\'");
            println!(
                "\nTo rerun this specific test, set the environment variable: {}='{escaped_test_name}'",
                EnvVars::MDTEST_TEST_FILTER,
            );
            println!(
                "{}='{escaped_test_name}' cargo test -p ty_python_semantic --test mdtest -- {test_name}",
                EnvVars::MDTEST_TEST_FILTER,
            );
        }
    }