Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: --outputsarif support #6566

Closed
tusharsadhwani opened this issue Nov 28, 2023 · 3 comments
Closed

Feature request: --outputsarif support #6566

tusharsadhwani opened this issue Nov 28, 2023 · 3 comments
Labels
enhancement request New feature or request

Comments

@tusharsadhwani
Copy link

tusharsadhwani commented Nov 28, 2023

Is your feature request related to a problem? Please describe.

SARIF is a well supported output format for linters, there exist integrations (eg. to view issues in a web browser), and I think it is really easy to convert the current json output into SARIF:

Current output

{
    "version": "1.1.337",
    "time": "1701179145050",
    "generalDiagnostics": [
        {
            "file": "/tmp/asd.py",
            "severity": "error",
            "message": "Expression of type \"Literal['42']\" cannot be assigned to return type \"int\"\n  \"Literal['42']\" is incompatible with \"int\"",
            "range": {
                "start": {
                    "line": 1,
                    "character": 11
                },
                "end": {
                    "line": 1,
                    "character": 15
                }
            },
            "rule": "reportGeneralTypeIssues"
        }
    ],
    "summary": {
        "filesAnalyzed": 1,
        "errorCount": 1,
        "warningCount": 0,
        "informationCount": 0,
        "timeInSec": 0.224
    }
}

Equivalent SARIF

{
  "version": "2.1.0",
  "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "pyright",
          "version": "1.1.337"
        }
      },
      "results": [
        {
          "ruleId": "reportGeneralTypeIssues",
          "level": "error",
          "message": {
            "text": "Expression of type \"Literal['42']\" cannot be assigned to return type \"int\"\n  \"Literal['42']\" is incompatible with \"int\""
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "/tmp/asd.py"
                },
                "region": {
                  "startLine": 1,
                  "startColumn": 11,
                  "endLine": 1,
                  "endColumn": 15
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

Describe the solution you’d like

An --outputsarif option, or adding a new --output enum flag with text/json/sarif options, whichever is preferrable.

@tusharsadhwani tusharsadhwani added the enhancement request New feature or request label Nov 28, 2023
@erictraut
Copy link
Collaborator

Pyright already outputs a JSON output option. From this, you can transform to any output format you'd prefer with a short script. We have no plans to support alternative formats at this time.

@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@VIKTORVAV99
Copy link

Is this still the case?

Having SARIF outputs would allow it to plug into the GitHub code scanning tool and allow people to run CI pipelines that only block new type errors (which would allow legacy codebases to enable pyright and gradually fix issues).

Seems like something that should be built into the tool itself, especially since it seems like the current output has all the needed values so no change in how this is collected would be needed?

I would even argue that this could and should be the standard output format in v2.

@dgutson
Copy link

dgutson commented May 10, 2024

Pyright already outputs a JSON output option. From this, you can transform to any output format you'd prefer with a short script. We have no plans to support alternative formats at this time.

yet another "short script" to convert from XXX to a well stablished standard with plenty of tools to support it. This "short script" will require maintenance, running it, downloading, will present yet another attack surface, will require dependencies to be regularly updated...
Not using stablished standards incur in isolation and artificial bridges to the rest of the industry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants