17 releases

0.4.2 Sep 7, 2023
0.4.1 Jul 30, 2023
0.4.0 Jun 21, 2023
0.3.7 Feb 28, 2023
0.2.20 Nov 1, 2021

#944 in Command line utilities

Download history 2/week @ 2024-01-08 13/week @ 2024-01-22 9/week @ 2024-02-19 7/week @ 2024-02-26 4/week @ 2024-03-11 209/week @ 2024-04-01

213 downloads per month

MIT license

56KB
1K SLoC

Workflow Status

clang-tidy-sarif

This crate provides a command line tool to convert clang-tidy diagnostic output into SARIF.

The latest documentation can be found here.

clang-tidy is a popular linter / static analysis tool for C++. More information can be found on the official page: https://clang.llvm.org/extra/clang-tidy/

SARIF or the Static Analysis Results Interchange Format is an industry standard format for the output of static analysis tools. More information can be found on the official website: https://sarifweb.azurewebsites.net/.

Installation

clang-tidy-sarif may be installed via cargo

cargo install clang-tidy-sarif

via cargo-binstall

cargo binstall clang-tidy-sarif

or downloaded directly from Github Releases

# make sure to adjust the target and version (you may also want to pin to a specific version)
curl -sSL https://github.com/psastras/sarif-rs/releases/download/clang-tidy-sarif-latest/clang-tidy-sarif-x86_64-unknown-linux-gnu -o clang-tidy-sarif

Usage

For most cases, simply run clang-tidy and pipe the results into clang-tidy-sarif.

Example

 clang-tidy -checks=cert-* -warnings-as-errors=* main.cpp -- | clang-tidy-sarif

If you are using Github Actions, SARIF is useful for integrating with Github Advanced Security (GHAS), which can show code alerts in the "Security" tab of your repository.

After uploading clang-tidy-sarif output to Github, clang-tidy diagnostics are available in GHAS.

Example

on:
  workflow_run:
    workflows: ["main"]
    branches: [main]
    types: [completed]

name: sarif

jobs:
  upload-sarif:
    runs-on: ubuntu-latest
    if: ${{ github.ref == 'refs/heads/main' }}
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - uses: Swatinem/rust-cache@v1
      - run: cargo install clang-tidy-sarif sarif-fmt
      - run: clang-tidy -checks=cert-* -warnings-as-errors=* main.cpp -- | tee
          results.sarif | sarif-fmt
      - name: Upload SARIF file
        uses: github/codeql-action/upload-sarif@v1
        with:
          sarif_file: results.sarif

License: MIT

Dependencies

~5–16MB
~182K SLoC