Add SARIF (Static Analysis Results Interchange Format) output support

Đang mở
#21,840 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu trong mypy/error_formatter.py bằng cách đọc ErrorFormatter, MypyError, đường dẫn đầu ra JSON hiện có và OUTPUT_CHOICES. Sau đó xem xét đặc tả SARIF v2.1.0 và xác định cách tổng hợp đầu ra của formatter thành một tài liệu duy nhất. Hoàn thành khi mypy chấp nhận --output=sarif và xuất một báo cáo tương thích với SARIF chứa các dữ liệu chẩn đoán hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature

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

Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
56

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.