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

indentation_linter reports "startColumn": 0 -> invalid SARIF file #2550

Closed
pascalgulikers opened this issue Apr 5, 2024 · 3 comments · Fixed by #2551
Closed

indentation_linter reports "startColumn": 0 -> invalid SARIF file #2550

pascalgulikers opened this issue Apr 5, 2024 · 3 comments · Fixed by #2551
Labels
bug an unexpected problem or unintended behavior

Comments

@pascalgulikers
Copy link

pascalgulikers commented Apr 5, 2024

When using:
lintr::sarif_output(lintr::lint_dir("."), "lintr-results.sarif")

The following is put in the SARIF file:

{
  "ruleId": "indentation_linter",
  "ruleIndex": 12,
  "message": {
    "text": "Indentation should be 2 spaces but is 0 spaces."
  },
  "locations": [
    {
    "physicalLocation": {
      "artifactLocation": {
          "uri": "testfile.R",
          "uriBaseId": "ROOTPATH"
        },
        "region": {
          "startLine": 26,
          "startColumn": 0,
          "snippet": {
          "text": "sometext"
          }
        }
      }
    }
  ]
}

Resulting in the following error in github/codeql-action/upload-sarif@v3

Unable to upload "lintr-results.sarif" as it is not valid SARIF:
instance.runs[0].results[12].locations[0].physicalLocation.region.startColumn must be greater than or equal to 1

Reference: https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/sarif-v2.1.0-cs01.pdf

3.30.6 startColumn property
When a region object represents a text region specified by line/column properties, it MAY contain a 
property named startColumn whose value is a positive integer equal to the column number of the first 
character in the region.
If startColumn is absent, it SHALL default to 1.
@MichaelChirico
Copy link
Collaborator

Could you point to the directory where you ran lint_dir() if it's on GitHub? Or provide a reprex file that generates the issue?

@MichaelChirico MichaelChirico added the bug an unexpected problem or unintended behavior label Apr 5, 2024
@MichaelChirico
Copy link
Collaborator

@AshesITR is this an off-by-one error? Shouldn't ranges be 1:2?

dput(lintr::lint("if (a) {
b
}", lintr::indentation_linter()))
structure(list(structure(list(filename = "<text>", line_number = 2L, 
    column_number = 0L, type = "style", message = "Indentation should be 2 spaces but is 0 spaces.", 
    line = "b", ranges = list(c(0L, 2L)), linter = "indentation_linter"), class = c("lint", 
"list"))), class = c("lints", "list"))

@MichaelChirico
Copy link
Collaborator

Looks like 0 is the only case I'd fix here:

lintr::lint(text = sprintf("if (TRUE) {\n%sFALSE\n}", strrep(" ", 0:5)), linters = lintr::indentation_linter())
<text>:2:0: style: [indentation_linter] Indentation should be 2 spaces but is 0 spaces.
FALSE
^~
<text>:5:1: style: [indentation_linter] Indentation should be 2 spaces but is 1 spaces.
 FALSE
^~
<text>:11:3: style: [indentation_linter] Indentation should be 2 spaces but is 3 spaces.
   FALSE
  ^
<text>:14:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces.
    FALSE
  ~^
<text>:17:5: style: [indentation_linter] Indentation should be 2 spaces but is 5 spaces.
     FALSE
  ~~^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants