Skip to content

Commit

Permalink
fix(code): Don't write sarif files when no results are found
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSchafer authored and j-luong committed Feb 12, 2025
1 parent d27681a commit 7adc2d2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ func runCodeTestCommand(cmd *cobra.Command, args []string) error {
// ensure legacy behavior, where sarif and json can be used interchangeably
globalConfiguration.AddAlternativeKeys(output_workflow.OUTPUT_CONFIG_KEY_SARIF, []string{output_workflow.OUTPUT_CONFIG_KEY_JSON})
globalConfiguration.AddAlternativeKeys(output_workflow.OUTPUT_CONFIG_KEY_SARIF_FILE, []string{output_workflow.OUTPUT_CONFIG_KEY_JSON_FILE})

// ensure legacy behavior, where sarif files with no findings are not written
globalConfiguration.Set(output_workflow.OUTPUT_CONFIG_WRITE_EMPTY_FILE, false)

return runCommand(cmd, args)
}

Expand Down
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/snyk/cli-extension-sbom v0.0.0-20241016065306-0df2be5b3b8f
github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7
github.com/snyk/error-catalog-golang-public v0.0.0-20250121101159-e6a61b2bfae6
github.com/snyk/go-application-framework v0.0.0-20250205081247-7a253efc2b0c
github.com/snyk/go-application-framework v0.0.0-20250210203133-5b0f3252d77d
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20250211120001-7122ee6defea
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7 h1:Zn5BcV76oFAb
github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20250121101159-e6a61b2bfae6 h1:qY954YMn/7TaapgatD1bn4hfGQSmu56W6EgS2m8c++I=
github.com/snyk/error-catalog-golang-public v0.0.0-20250121101159-e6a61b2bfae6/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20250205081247-7a253efc2b0c h1:FAZ18Wx6iqz0w5N1CfEFq4sjL5MiMbjaCQX7ogFwDfw=
github.com/snyk/go-application-framework v0.0.0-20250205081247-7a253efc2b0c/go.mod h1:ag3sCoHGCn534oDAnAXLcjZEZljW3oMOfKCzpmFX060=
github.com/snyk/go-application-framework v0.0.0-20250210203133-5b0f3252d77d h1:Qhe0N1em8naODCCTXU12UHC4Te9FgwYAS32pzyRIAi8=
github.com/snyk/go-application-framework v0.0.0-20250210203133-5b0f3252d77d/go.mod h1:ag3sCoHGCn534oDAnAXLcjZEZljW3oMOfKCzpmFX060=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.33.0 h1:nXH4LEVrYbEuSEq4RJBObRY2fduaXiovAJt3Kni1baY=
Expand Down
6 changes: 0 additions & 6 deletions test/jest/acceptance/cli-json-file-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ describe('test --json-file-output', () => {

const { code } = await runSnykCLI(
`code test --json-file-output=${outputFilename} ${project.path()}`,
{
env: {
...process.env,
INTERNAL_SNYK_CODE_IGNORES_ENABLED: 'false', // remove when CLI-711 is implemented
},
},
);

const fileExists = fs.existsSync(outputFilename);
Expand Down

0 comments on commit 7adc2d2

Please sign in to comment.