36 个版本

0.6.5 2024 年 8 月 6 日
0.6.0 2024 年 7 月 30 日
0.4.2 2023 年 9 月 7 日
0.4.1 2023 年 7 月 30 日
0.2.15 2021 年 7 月 6 日

#9 in 命令行工具

Download history 8633/week @ 2024-05-03 8337/week @ 2024-05-10 7008/week @ 2024-05-17 5997/week @ 2024-05-24 6057/week @ 2024-05-31 7366/week @ 2024-06-07 8705/week @ 2024-06-14 5504/week @ 2024-06-21 6837/week @ 2024-06-28 6818/week @ 2024-07-05 8313/week @ 2024-07-12 6974/week @ 2024-07-19 7412/week @ 2024-07-26 12059/week @ 2024-08-02 8595/week @ 2024-08-09 7287/week @ 2024-08-16

每月 36,833 次下载

MIT 许可证

85KB
1.5K SLoC

Workflow Status

sarif-fmt

此包提供了一个命令行工具,用于美化打印 SARIF 文件,使其易于阅读。

最新的文档可以在这里找到。

SARIF 或静态分析结果交换格式是静态分析工具输出的一种行业标准格式。更多信息可以在官方网站上找到:https://sarifweb.azurewebsites.net/

安装

sarif-fmt 可以通过 cargo 安装

cargo install sarif-fmt

via cargo-binstall

cargo binstall sarif-fmt

或直接从 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/sarif-fmt-latest/sarif-fmt-x86_64-unknown-linux-gnu -o sarif-fmt

用法

在大多数情况下,只需将 SARIF 文件通过管道传递给 sarif-fmt 即可(cat .sarif | sarif-fmt

示例

$ cargo clippy --message-format=json | clippy-sarif | sarif-fmt
$ warning: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`
    ┌─ sarif-fmt/src/bin.rs:423:13
    
423 │ ╭             the_rule
424 │ │               .full_description
425 │ │               .as_ref()
426 │ │               .and_then(|mfms| Some(mfms.text.clone()))
     ╰───────────────────────────────────────────────────────^
    
    = `#[warn(clippy::bind_instead_of_map)]` on by default
      for further information visit https://rust-lang.github.io/rust-clippy/master#bind_instead_of_map

通常,记录 SARIF 文件以供机器处理的同时,也打印美观的格式化结果到标准输出是有用的。这可以使用 tee 命令来完成

$ clang-tidy -checks=cert-* cpp.cpp -- | clang-tidy-sarif | tee clang-tidy.sarif | sarif-fmt
$ 2 warnings generated.
warning: 'atoi' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c]
  ┌─ /home/psastras/repos/sarif-rs/sarif-fmt/tests/data/cpp.cpp:4:10
  
4 │   return atoi(num);
            ^^^^^^^^^^

warning: calling 'system' uses a command processor [cert-env33-c]
  ┌─ /home/psastras/repos/sarif-rs/sarif-fmt/tests/data/cpp.cpp:8:3
  
8 │   system("ls");
     ^^^^^^^^^^^^^

$ cat clang-tidy.sarif
{
  "runs": [
    {
      "results": [
        {
          "level": "warning",
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "cpp.cpp"
                },
                "region": {
                  "startColumn": 10,
                  "startLine": 4
                }
              }
            }
          ],
          "message": {
            "text": "'atoi' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c]"
          }
        },
        {
          "level": "warning",
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "cpp.cpp"
                },
                "region": {
                  "startColumn": 3,
                  "startLine": 8
                }
              }
            }
          ],
          "message": {
            "text": "calling 'system' uses a command processor [cert-env33-c]"
          }
        }
      ],
      "tool": {
        "driver": {
          "name": "clang-tidy"
        }
      }
    }
  ],
  "version": "2.1.0"
}

许可证:MIT

依赖

~2–10MB
~96K SLoC