Skip to content

Commit

Permalink
⚠️ remove experimental gate from probe format (#4026)
Browse files Browse the repository at this point in the history
* remove experimental gate from probe format

Also delete finding and structured results formats as they weren't used

Signed-off-by: Spencer Schrock <[email protected]>

* rename method which writes probe format

Signed-off-by: Spencer Schrock <[email protected]>

* remove unused code for linter

Signed-off-by: Spencer Schrock <[email protected]>

---------

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock authored Apr 12, 2024
1 parent f4c3025 commit d4c5b18
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 49 deletions.
41 changes: 8 additions & 33 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,8 @@ const (
// Formats.
// FormatJSON specifies that results should be output in JSON format.
FormatJSON = "json"
// FormatFJSON specifies that results should be output in JSON format,
// but with structured findings.
FormatFJSON = "finding"
// FormatPJSON specifies that results should be output in probe JSON format.
FormatPJSON = "probe"
// FormatSJSON specifies that results should be output in structured JSON format.
FormatSJSON = "structured"
// FormatProbe specifies that results should be output in probe JSON format.
FormatProbe = "probe"
// FormatSarif specifies that results should be output in SARIF format.
FormatSarif = "sarif"
// FormatDefault specifies that results should be output in default format.
Expand All @@ -109,12 +104,11 @@ var (
// DefaultLogLevel retrieves the default log level.
DefaultLogLevel = sclog.DefaultLevel.String()

errCommitIsEmpty = errors.New("commit should be non-empty")
errFormatNotSupported = errors.New("unsupported format")
errFormatSupportedWithExperimental = errors.New("format supported only with SCORECARD_EXPERIMENTAL=1")
errPolicyFileNotSupported = errors.New("policy file is not supported yet")
errRawOptionNotSupported = errors.New("raw option is not supported yet")
errRepoOptionMustBeSet = errors.New(
errCommitIsEmpty = errors.New("commit should be non-empty")
errFormatNotSupported = errors.New("unsupported format")
errPolicyFileNotSupported = errors.New("policy file is not supported yet")
errRawOptionNotSupported = errors.New("raw option is not supported yet")
errRepoOptionMustBeSet = errors.New(
"exactly one of `repo`, `npm`, `pypi`, `rubygems`, `nuget` or `local` must be set",
)
errSARIFNotSupported = errors.New("SARIF format is not supported yet")
Expand Down Expand Up @@ -165,17 +159,6 @@ func (o *Options) Validate() error {
}
}

if !o.isExperimentalEnabled() {
if o.Format == FormatSJSON ||
o.Format == FormatFJSON ||
o.Format == FormatPJSON {
errs = append(
errs,
errFormatSupportedWithExperimental,
)
}
}

// Validate format.
if !validateFormat(o.Format) {
errs = append(
Expand Down Expand Up @@ -245,13 +228,6 @@ func (o *Options) Probes() []string {
return o.ProbesToRun
}

// isExperimentalEnabled returns true if experimental features were enabled via
// environment variable.
func (o *Options) isExperimentalEnabled() bool {
value, _ := os.LookupEnv(EnvVarScorecardExperimental)
return value == "1"
}

// isSarifEnabled returns true if SARIF format was specified in options or via
// environment variable.
func (o *Options) isSarifEnabled() bool {
Expand All @@ -269,8 +245,7 @@ func (o *Options) isV6Enabled() bool {

func validateFormat(format string) bool {
switch format {
case FormatJSON, FormatSJSON, FormatFJSON,
FormatPJSON, FormatSarif, FormatDefault, FormatRaw:
case FormatJSON, FormatProbe, FormatSarif, FormatDefault, FormatRaw:
return true
default:
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type ProbeResultOption struct {
Indent string
}

// AsPJSON writes results as JSON for flat findings without checks.
// AsProbe writes results as JSON for flat findings without checks.
// It accepts an optional argument to configure the output.
func (r *ScorecardResult) AsPJSON(writer io.Writer, o *ProbeResultOption) error {
func (r *ScorecardResult) AsProbe(writer io.Writer, o *ProbeResultOption) error {
encoder := json.NewEncoder(writer)
out := JSONScorecardProbeResult{
Repo: jsonRepoV2{
Expand Down
6 changes: 3 additions & 3 deletions pkg/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/ossf/scorecard/v4/finding"
)

func Test_AsPJSON(t *testing.T) {
func TestAsProbe(t *testing.T) {
t.Parallel()
tests := []struct {
name string
Expand Down Expand Up @@ -76,8 +76,8 @@ func Test_AsPJSON(t *testing.T) {
}

var result bytes.Buffer
if err = tt.result.AsPJSON(&result, opt); err != nil {
t.Fatalf("AsPJSON: %v", err)
if err = tt.result.AsProbe(&result, opt); err != nil {
t.Fatalf("AsProbe: %v", err)
}

if diff := cmp.Diff(expected, result.Bytes()); diff != "" {
Expand Down
8 changes: 1 addition & 7 deletions pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"errors"
"fmt"
"os"
"strings"
"sync"
"time"
Expand All @@ -31,7 +30,6 @@ import (
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/finding"
proberegistration "github.com/ossf/scorecard/v4/internal/probes"
"github.com/ossf/scorecard/v4/options"
)

// errEmptyRepository indicates the repository is empty.
Expand Down Expand Up @@ -162,13 +160,9 @@ func runScorecard(ctx context.Context,
// If the user runs checks
go runEnabledChecks(ctx, repo, request, checksToRun, resultsCh)

exposeFindings := os.Getenv(options.EnvVarScorecardExperimental) == "1"
for result := range resultsCh {
ret.Checks = append(ret.Checks, result)

if exposeFindings {
ret.Findings = append(ret.Findings, result.Findings...)
}
ret.Findings = append(ret.Findings, result.Findings...)
}
return ret, nil
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/scorecard_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ func FormatResults(
err = results.AsSARIF(opts.ShowDetails, log.ParseLevel(opts.LogLevel), output, doc, policy, opts)
case options.FormatJSON:
err = results.AsJSON2(opts.ShowDetails, log.ParseLevel(opts.LogLevel), doc, output)
case options.FormatFJSON:
err = results.AsFJSON(opts.ShowDetails, log.ParseLevel(opts.LogLevel), doc, output)
case options.FormatPJSON:
case options.FormatProbe:
var opts *ProbeResultOption
err = results.AsPJSON(output, opts)
err = results.AsProbe(output, opts)
case options.FormatRaw:
err = results.AsRawJSON(output)
default:
Expand Down

0 comments on commit d4c5b18

Please sign in to comment.