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

Add report flag to CLI tool #119

Merged
merged 8 commits into from
Oct 16, 2023
Merged

Add report flag to CLI tool #119

merged 8 commits into from
Oct 16, 2023

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Oct 12, 2023

Fixes #110.

The result sarif looks like:

{
  "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json",
  "version": "2.1.0",
  "runs": [
    {
      "results": [
        {
          "ruleId": "GRA-STRING-001",
          "ruleIndex": 0,
          "message": {
            "text": "The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload."
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///C:/Users/nojaf/Projects/graph-sample/B.fs"
                },
                "region": {
                  "startLine": 3,
                  "endLine": 3,
                  "endColumn": 17
                }
              }
            }
          ]
        },
        {
          "ruleId": "GRA-STRING-001",
          "ruleIndex": 0,
          "message": {
            "text": "The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload."
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///C:/Users/nojaf/Projects/graph-sample/B.fs"
                },
                "region": {
                  "startLine": 4,
                  "endLine": 4,
                  "endColumn": 17
                }
              }
            }
          ]
        },
        {
          "ruleId": "GRA-STRING-002",
          "ruleIndex": 1,
          "message": {
            "text": "The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload."
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///C:/Users/nojaf/Projects/graph-sample/B.fs"
                },
                "region": {
                  "startLine": 5,
                  "endLine": 5,
                  "endColumn": 19
                }
              }
            }
          ]
        }
      ],
      "tool": {
        "driver": {
          "name": "Ionide.Analyzers.Cli",
          "version": "0.16.0.0",
          "informationUri": "https://ionide.io/FSharp.Analyzers.SDK/",
          "rules": [
            {
              "id": "GRA-STRING-001",
              "name": "The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.",
              "shortDescription": {
                "text": "Verifies the correct usage of System.String.EndsWith",
                "markdown": "Verifies the correct usage of System.String.EndsWith"
              },
              "helpUri": "https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings"
            },
            {
              "id": "GRA-STRING-002",
              "name": "The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.",
              "shortDescription": {
                "text": "Verifies the correct usage of System.String.StartsWith",
                "markdown": "Verifies the correct usage of System.String.StartsWith"
              },
              "helpUri": "https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings"
            }
          ]
        }
      },
      "invocations": [
        {
          "startTimeUtc": "2023-10-16T11:55:34.837Z",
          "endTimeUtc": "2023-10-16T11:55:34.914Z",
          "executionSuccessful": true
        }
      ],
      "columnKind": "utf16CodeUnits"
    }
  ]
}

@nojaf
Copy link
Contributor Author

nojaf commented Oct 12, 2023

This is pretty easy to integrate into GitHub:
https://github.com/fsprojects/fantomas/blob/2395c2f4af96ddca12624544b9b9df342e34d118/.github/workflows/main.yml#L32-L80

image

@Numpsy
Copy link
Contributor

Numpsy commented Oct 12, 2023

At a risk of jumping into the middle of a discussion without having looked at the details:

There is an old issue on FSharpLint to support the generation of Sarif format reports: fsprojects/FSharpLint#554 and that mentions integration with github code scanning, so I wonder if there is cross over with that here?

(I was looking at that one recently as the powers that be at work like code analysis results to be published into Sonar and I believe that you're supposed to be able to make that consume Sarif format reports as well)

@nojaf
Copy link
Contributor Author

nojaf commented Oct 12, 2023

Hi @Numpsy, thanks for bringing this up, the sarif format is worth exploring. I'll take a look at this next week.

src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsi Outdated Show resolved Hide resolved
src/FSharp.Analyzers.Cli/Program.fs Outdated Show resolved Hide resolved
@nojaf nojaf merged commit 6108442 into ionide:master Oct 16, 2023
2 checks passed
@dawedawe
Copy link
Contributor

Could you change the linked issue to #110

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

Successfully merging this pull request may close these issues.

Analyzer report
3 participants