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
GithubFormatter ¶
GitHub Actions output formatter.
Emits ::error:: and ::warning:: workflow commands for inline
annotations.
Source code in src/ruff_sync/formatters.py
153 154 155 156 157 158 159 160 161 162 163 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 | |
note ¶
info ¶
success ¶
error ¶
Print an error message as a GitHub Action error annotation.
Source code in src/ruff_sync/formatters.py
warning ¶
Print a warning message as a GitHub Action warning annotation.
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 ¶
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
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 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 | |
__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
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 560 561 562 563 564 565 566 567 568 569 570 571 572 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 | |
__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.