formatters
ruff_sync.formatters ¶
Output formatters for CLI results.
ResultFormatter ¶
Bases: Protocol
Protocol for output formatters.
Streaming formatters (Text, GitHub, JSON) implement note / info /
success / error / warning / debug / diff and provide a
no-op finalize.
Accumulating formatters (GitLab, SARIF) collect issues during the run and
write their structured report in finalize. finalize is always
called by the CLI in a try...finally block, so all formatters receive
it unconditionally.
Source code in src/ruff_sync/formatters.py
note ¶
info ¶
success ¶
error ¶
Print an error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable description of the issue. |
required |
file_path
|
Path | None
|
Path to the file that contains the issue. |
None
|
logger
|
Logger | None
|
Optional logger to use instead of the module logger. |
None
|
check_name
|
str
|
Machine-readable rule ID (used by structured formatters). |
_DEFAULT_CHECK_NAME
|
drift_key
|
str | None
|
Dotted TOML key that drifted, e.g. |
None
|
Source code in src/ruff_sync/formatters.py
warning ¶
Print a warning message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable description of the issue. |
required |
file_path
|
Path | None
|
Path to the file that contains the issue. |
None
|
logger
|
Logger | None
|
Optional logger to use instead of the module logger. |
None
|
check_name
|
str
|
Machine-readable rule ID (used by structured formatters). |
_DEFAULT_CHECK_NAME
|
drift_key
|
str | None
|
Dotted TOML key that drifted, e.g. |
None
|
Source code in src/ruff_sync/formatters.py
debug ¶
diff ¶
Print a unified diff between configurations.
Note
Structured (accumulating) formatters intentionally ignore this method — diffs are not representable in JSON report schemas.
finalize ¶
Finalize and flush all output.
Streaming formatters (Text, GitHub, JSON) implement this as a no-op.
Accumulating formatters (GitLab, SARIF) write their collected report
here. The CLI calls this unconditionally inside a try...finally
block so it is always executed, even when an exception occurred.
Source code in src/ruff_sync/formatters.py
TextFormatter ¶
Standard text output formatter.
Delegates diagnostic messages (info, warning, error, debug) to the project logger to ensure they benefit from standard logging configuration (colors, streams). Primary command feedback (note, success) is printed to stdout.
Source code in src/ruff_sync/formatters.py
GithubIssue ¶
Bases: TypedDict
GitHub Action output issue.
Source code in src/ruff_sync/formatters.py
GithubFormatter ¶
GitHub Actions output formatter.
Emits ::error:: and ::warning:: workflow commands for inline
annotations, and writes a Markdown report to GITHUB_STEP_SUMMARY.
Source code in src/ruff_sync/formatters.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
__init__ ¶
note ¶
info ¶
success ¶
error ¶
Accumulate an error-level finding.
Source code in src/ruff_sync/formatters.py
warning ¶
Accumulate a warning-level finding.
Source code in src/ruff_sync/formatters.py
debug ¶
Print a debug message as a GitHub Action debug annotation.
Source code in src/ruff_sync/formatters.py
diff ¶
finalize ¶
Finalize and emit all accumulated issues as GitHub workflow commands.
If multiple issues exist for a single file/level, they are combined into a single multi-line annotation to reduce visual noise.
A Markdown summary is also written to GITHUB_STEP_SUMMARY if the
environment variable is set.
Source code in src/ruff_sync/formatters.py
JsonFormatter ¶
JSON output formatter (newline-delimited JSON, one record per line).
Source code in src/ruff_sync/formatters.py
note ¶
info ¶
Print an info message as JSON.
success ¶
error ¶
Print an error message as JSON.
Source code in src/ruff_sync/formatters.py
warning ¶
Print a warning message as JSON.
Source code in src/ruff_sync/formatters.py
debug ¶
Print a debug message as JSON.
diff ¶
GitlabLines ¶
GitlabLocation ¶
GitlabIssue ¶
Bases: TypedDict
GitLab Code Quality report issue.
Source code in src/ruff_sync/formatters.py
GitlabFormatter ¶
GitLab Code Quality report formatter.
Accumulates issues during the run and writes a single valid JSON array to
stdout in finalize(). The CI job redirects stdout to a file::
ruff-sync check --output-format gitlab > gl-code-quality-report.json
An empty array ([]) is emitted when no issues were collected, which
signals to GitLab that previously reported issues are now resolved.
Fingerprints are deterministic MD5 hashes so GitLab can track whether an issue was introduced or resolved between branches.
Source code in src/ruff_sync/formatters.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
__init__ ¶
note ¶
info ¶
success ¶
error ¶
Accumulate a major-severity Code Quality issue.
Source code in src/ruff_sync/formatters.py
warning ¶
Accumulate a minor-severity Code Quality issue.
Source code in src/ruff_sync/formatters.py
debug ¶
diff ¶
finalize ¶
Write the collected issues as a GitLab Code Quality JSON array to stdout.
Always produces valid JSON: an empty array [] when no issues were
collected (signals resolution of previously reported issues to GitLab).
Source code in src/ruff_sync/formatters.py
SarifResult ¶
Bases: TypedDict
A single SARIF result (finding).
Source code in src/ruff_sync/formatters.py
SarifFormatter ¶
SARIF v2.1.0 output formatter.
Accumulates results during the run and writes a complete SARIF document to
stdout in finalize(). The CI job redirects stdout to a file::
ruff-sync check --output-format sarif > results.sarif
An empty results list is emitted when no issues were found.
Schema: https://json.schemastore.org/sarif-2.1.0.json
Source code in src/ruff_sync/formatters.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
__init__ ¶
note ¶
info ¶
success ¶
error ¶
Accumulate an error-level SARIF result.
Source code in src/ruff_sync/formatters.py
warning ¶
Accumulate a warning-level SARIF result.
Source code in src/ruff_sync/formatters.py
debug ¶
diff ¶
finalize ¶
Write the collected results as a SARIF v2.1.0 document to stdout.
Rules are de-duplicated from the accumulated results so the rules
list contains one entry per unique ruleId seen across all findings.
Source code in src/ruff_sync/formatters.py
get_formatter ¶
Return the corresponding formatter for the given format.