python / python/mypy

Add SARIF (Static Analysis Results Interchange Format) output support

オープン
#21,840 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Feature

Add support for SARIF (Static Analysis Results Interchange Format) output format to mypy, similar to the existing --output=json option.

Pitch

SARIF is an OASIS standard format for static analysis results that is widely supported by modern CI/CD platforms and security tools:

  • GitHub Advanced Security natively ingests SARIF files for code scanning alerts
  • Azure DevOps supports SARIF for displaying security and code quality results
  • GitLab can process SARIF reports for vulnerability tracking
  • Many other security and code quality platforms (SonarQube, CodeQL, etc.) support SARIF

Other Python type checkers like Pyre already support SARIF output. Adding this to mypy would:

  1. Improve integration with GitHub/Azure/GitLab security features
  2. Make it easier to use mypy in enterprise CI/CD pipelines
  3. Provide a standardized foundation for richer diagnostics supported by SARIF
  4. Enable consumption by security tools that require standardized formats

Example Usage

# Generate SARIF output
mypy myproject/ --output=sarif > results.sarif

# Upload to GitHub Code Scanning (requires gzip + base64 encoding)
gzip -c results.sarif | base64 -w0 > results.sarif.gz.b64
gh api /repos/owner/repo/code-scanning/sarifs --method POST \
  --field commit_sha="$(git rev-parse HEAD)" \
  --field ref="refs/heads/main" \
  --field sarif="@results.sarif.gz.b64"

Implementation Notes

The implementation could likely build on the existing output formatter infrastructure:

  1. Add a new SARIFFormatter class in mypy/error_formatter.py extending ErrorFormatter
  2. Add "sarif" to the OUTPUT_CHOICES dictionary
  3. Implement the SARIF v2.1.0 JSON schema

The MypyError class already provides the necessary diagnostic data (file path, line, column, error code, message, severity). Note that SARIF requires aggregating results into a single document structure rather than line-by-line output like JSON, which may require some adjustments to the formatter interface.

Related Issues

  • #10816 (closed) - discussed multiple output formats including SARIF in comments
  • #17612 - GitHub Actions workflow commands format (similar motivation)
  • #20212 - Include summary in JSON output

References

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

mypy/error_formatter.py から始め、ErrorFormatter、MypyError、既存の JSON 出力パス、OUTPUT_CHOICES を読みます。次に SARIF v2.1.0 仕様を確認し、formatter の出力を 1 つのドキュメントに集約する方法を判断します。mypy が --output=sarif を受け付け、利用可能な診断データを含む SARIF 互換レポートを出力すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。