diff --git a/crates/ruff/tests/cli/snapshots/cli__format__output_format_github.snap b/crates/ruff/tests/cli/snapshots/cli__format__output_format_github.snap index 92086762b5..6faab6bd86 100644 --- a/crates/ruff/tests/cli/snapshots/cli__format__output_format_github.snap +++ b/crates/ruff/tests/cli/snapshots/cli__format__output_format_github.snap @@ -14,6 +14,6 @@ info: success: false exit_code: 1 ----- stdout ----- -::error title=Ruff (unformatted),file=[TMP]/input.py,line=1,col=1,endLine=2,endColumn=1::input.py:1:1: unformatted: File would be reformatted +::error title=Ruff (unformatted),file=[TMP]/input.py,line=1,endLine=2::input.py:1:1: unformatted: File would be reformatted ----- stderr ----- diff --git a/crates/ruff_db/src/diagnostic/render/github.rs b/crates/ruff_db/src/diagnostic/render/github.rs index 77bae347af..161f371f8a 100644 --- a/crates/ruff_db/src/diagnostic/render/github.rs +++ b/crates/ruff_db/src/diagnostic/render/github.rs @@ -49,14 +49,26 @@ impl<'a> GithubRenderer<'a> { } .unwrap_or_default(); - write!( - f, - ",line={row},col={column},endLine={end_row},endColumn={end_column}::", - row = start_location.line, - column = start_location.column, - end_row = end_location.line, - end_column = end_location.column, - )?; + // GitHub Actions workflow commands have constraints on error annotations: + // - `col` and `endColumn` cannot be set if `line` and `endLine` are different + // See: https://github.com/astral-sh/ruff/issues/22074 + if start_location.line == end_location.line { + write!( + f, + ",line={row},col={column},endLine={end_row},endColumn={end_column}::", + row = start_location.line, + column = start_location.column, + end_row = end_location.line, + end_column = end_location.column, + )?; + } else { + write!( + f, + ",line={row},endLine={end_row}::", + row = start_location.line, + end_row = end_location.line, + )?; + } write!( f, diff --git a/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__github__tests__syntax_errors.snap b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__github__tests__syntax_errors.snap index 227bb0c699..87d92d3859 100644 --- a/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__github__tests__syntax_errors.snap +++ b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__github__tests__syntax_errors.snap @@ -2,5 +2,5 @@ source: crates/ruff_db/src/diagnostic/render/github.rs expression: env.render_diagnostics(&diagnostics) --- -::error title=ty (invalid-syntax),file=/syntax_errors.py,line=1,col=15,endLine=2,endColumn=1::syntax_errors.py:1:15: invalid-syntax: Expected one or more symbol names after import -::error title=ty (invalid-syntax),file=/syntax_errors.py,line=3,col=12,endLine=4,endColumn=1::syntax_errors.py:3:12: invalid-syntax: Expected ')', found newline +::error title=ty (invalid-syntax),file=/syntax_errors.py,line=1,endLine=2::syntax_errors.py:1:15: invalid-syntax: Expected one or more symbol names after import +::error title=ty (invalid-syntax),file=/syntax_errors.py,line=3,endLine=4::syntax_errors.py:3:12: invalid-syntax: Expected ')', found newline