buildifier: add SARIF output (--format=sarif) (#1529)

Adds SARIF 2.1.0 as a third diagnostics format next to `text` and
`json`. SARIF is understood by many CI, IDE and code-quality tools.
Fixes #1528.

## Usage

```
buildifier --mode=check --lint=warn --format=sarif -r . > buildifier.sarif
```

As with `json`, `--format=sarif` only works with `--mode=check`, and
`-v` indents the output.

## Mapping

- Each lint warning becomes a result at level `warning`. Its `ruleId` is
the warning category, `helpUri` is the WARNINGS.md link, and the region
is the start and end line and column.
- A file that needs reformatting becomes a file-level result (no region)
with rule `format`, level `warning`.
- A file that can't be parsed becomes a file-level result with rule
`parse-error`, level `error`.
- Rules are deduplicated per category.
- With no findings, the output is still a valid log with empty `rules`
and `results`.

## Design notes

- The serializer is a small in-tree struct set, so it adds no
dependency.
- Findings carry no severity today (only `actionable`, which `warn.go`
always sets to `true`). So every lint finding is a `warning`.
- `autoFixable` is not mapped. It would need SARIF `fixes` with
replacement text, which can come in a follow-up.
- A `format` finding has no region, because buildifier doesn't track
where the formatting differs.
- `artifactLocation.uri` is the path as passed on the command line, so
run from the repo root with relative paths for repo-relative URIs.

## Commits

1. Serializer (`utils/sarif.go`), unit tests, and the `Format` hook-up.
2. Accept `--format=sarif` in `--mode=check` and update the help text.
3. README section.
4. Integration tests with goldens, covering many files, a single file,
stdin and an invalid file.

## Additional testing

- Sample outputs validate against the official OASIS SARIF 2.1.0 schema.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9 files changed
tree: 82f5efdab38f1f91162dcdcd0ada1b5981c349da
  1. .bazelci/
  2. .github/
  3. api_proto/
  4. build/
  5. build_proto/
  6. buildifier/
  7. buildozer/
  8. bzlenv/
  9. config/
  10. convertast/
  11. deps_proto/
  12. differ/
  13. edit/
  14. extra_actions_base_proto/
  15. file/
  16. generatetables/
  17. labels/
  18. lang/
  19. release/
  20. tables/
  21. testutils/
  22. unused_deps/
  23. warn/
  24. wspace/
  25. .bazelrc
  26. .bazelversion
  27. .gitignore
  28. .mailmap
  29. .pre-commit-config.yaml
  30. AGENTS.md
  31. BUILD.bazel
  32. CODEOWNERS
  33. CONTRIBUTING.md
  34. CONTRIBUTORS
  35. go.mod
  36. go.sum
  37. launcher.js
  38. LICENSE
  39. MODULE.bazel
  40. README.md
  41. status.py
  42. update_generated.sh
  43. WARNINGS.md
  44. WORKSPACE
  45. WORKSPACE.bzlmod
README.md

Buildtools for bazel

This repository contains developer tools for working with Google's bazel buildtool.

Build status

Setup

See instructions in each tool's directory.