From 6b63f3f9634c63f00d97b17681fa489b8daefadc Mon Sep 17 00:00:00 2001 From: Chris McGehee Date: Mon, 24 May 2021 11:34:33 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20Fix=20lint=20issues:=20Replace?= =?UTF-8?q?=20golint=20with=20revive=20(#493)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix lint issues: Replace golint with revive golint is deprecated and recommended to be replaced with revive * Updating comments to be more accurate * Updating comments again Co-authored-by: Azeem Shaikh --- .golangci.yml | 2 +- checker/check_result.go | 1 + checker/check_runner.go | 4 ++-- checks/all_checks.go | 1 + checks/checkforcontent.go | 1 + checks/code_review.go | 1 + checks/sast.go | 8 +++++--- checks/signed_releases.go | 1 + checks/signed_tags.go | 3 ++- cmd/root.go | 13 +++++++------ cron/config/config.go | 5 ++++- cron/controller/main.go | 2 +- cron/pubsub/subscriber.go | 1 + repos/repo_url.go | 7 +++++-- roundtripper/roundtripper.go | 26 +++++++++++++++++--------- stats/measures.go | 4 +++- stats/tags.go | 7 +++++-- stats/views.go | 2 ++ 18 files changed, 60 insertions(+), 29 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f367136c..46a466d7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -31,7 +31,6 @@ linters: - gofumpt - goheader - goimports - # - golint - gomnd - gomodguard - goprintffuncname @@ -49,6 +48,7 @@ linters: - paralleltest - prealloc - predeclared + - revive - rowserrcheck - sqlclosecheck - staticcheck diff --git a/checker/check_result.go b/checker/check_result.go index e797e59e..1be9874c 100644 --- a/checker/check_result.go +++ b/checker/check_result.go @@ -18,6 +18,7 @@ import "errors" const MaxResultConfidence = 10 +// ErrorDemoninatorZero indicates the denominator for a proportional result is 0. var ErrorDemoninatorZero = errors.New("internal error: denominator is 0") type CheckResult struct { diff --git a/checker/check_runner.go b/checker/check_runner.go index fa43a3ba..19e7657b 100644 --- a/checker/check_runner.go +++ b/checker/check_runner.go @@ -81,7 +81,7 @@ func Bool2int(b bool) int { return 0 } -// Returns the best check result out of several ones performed. +// MultiCheckOr returns the best check result out of several ones performed. func MultiCheckOr(fns ...CheckFn) CheckFn { return func(c *CheckRequest) CheckResult { var maxResult CheckResult @@ -102,7 +102,7 @@ func MultiCheckOr(fns ...CheckFn) CheckFn { } } -// All checks must succeed. This returns a conservative result +// MultiCheckAnd means all checks must succeed. This returns a conservative result // where the worst result is returned. func MultiCheckAnd(fns ...CheckFn) CheckFn { return func(c *CheckRequest) CheckResult { diff --git a/checks/all_checks.go b/checks/all_checks.go index 345c4792..ccd7c814 100644 --- a/checks/all_checks.go +++ b/checks/all_checks.go @@ -16,6 +16,7 @@ package checks import "github.com/ossf/scorecard/checker" +// AllChecks is the list of all security checks that will be run. var AllChecks = checker.CheckNameToFnMap{} func registerCheck(name string, fn checker.CheckFn) { diff --git a/checks/checkforcontent.go b/checks/checkforcontent.go index c14145dc..3e477010 100644 --- a/checks/checkforcontent.go +++ b/checks/checkforcontent.go @@ -27,6 +27,7 @@ import ( "github.com/ossf/scorecard/checker" ) +// ErrReadFile indicates the header size does not match the size of the file. var ErrReadFile = errors.New("could not read entire file") // IsMatchingPath uses 'pattern' to shell-match the 'path' and its filename diff --git a/checks/code_review.go b/checks/code_review.go index c0285676..14825c61 100644 --- a/checks/code_review.go +++ b/checks/code_review.go @@ -25,6 +25,7 @@ import ( const codeReviewStr = "Code-Review" +// ErrorNoReviews indicates no reviews were found for this repo. var ErrorNoReviews = errors.New("no reviews found") //nolint:gochecknoinits diff --git a/checks/sast.go b/checks/sast.go index 90ba9590..691ef642 100644 --- a/checks/sast.go +++ b/checks/sast.go @@ -25,9 +25,11 @@ import ( const sastStr = "SAST" var ( - sastTools map[string]bool = map[string]bool{"github-code-scanning": true, "sonarcloud": true} - ErrorNoChecks = errors.New("no check runs found") - ErrorNoMerges = errors.New("no merges found") + sastTools = map[string]bool{"github-code-scanning": true, "sonarcloud": true} + // ErrorNoChecks indicates no GitHub Check runs were found for this repo. + ErrorNoChecks = errors.New("no check runs found") + // ErrorNoMerges indicates no merges with SAST tool runs were found for this repo. + ErrorNoMerges = errors.New("no merges found") ) //nolint:gochecknoinits diff --git a/checks/signed_releases.go b/checks/signed_releases.go index 95c8e15e..d9de9826 100644 --- a/checks/signed_releases.go +++ b/checks/signed_releases.go @@ -28,6 +28,7 @@ const ( releaseLookBackDays = 5 ) +// ErrorNoReleases indicates no releases were found for this repo. var ErrorNoReleases = errors.New("no releases found") //nolint:gochecknoinits diff --git a/checks/signed_tags.go b/checks/signed_tags.go index f121008a..e2084ba8 100644 --- a/checks/signed_tags.go +++ b/checks/signed_tags.go @@ -27,7 +27,8 @@ const ( tagLookBack = 5 ) -var ErrorNoTags = errors.New("no signed tags found") +// ErrorNoTags indicates no tags were found for this repo. +var ErrorNoTags = errors.New("no tags found") //nolint:gochecknoinits func init() { diff --git a/cmd/root.go b/cmd/root.go index 97961935..fa6e12ea 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -44,12 +44,13 @@ var ( checksToRun []string metaData []string // This one has to use goflag instead of pflag because it's defined by zap. - logLevel = zap.LevelFlag("verbosity", zap.InfoLevel, "override the default log level") - format string - npm string - pypi string - rubygems string - showDetails bool + logLevel = zap.LevelFlag("verbosity", zap.InfoLevel, "override the default log level") + format string + npm string + pypi string + rubygems string + showDetails bool + // ErrorInvalidFormatFlag indicates an invalid option was passed for the 'format' argument. ErrorInvalidFormatFlag = errors.New("invalid format flag") ) diff --git a/cron/config/config.go b/cron/config/config.go index fa0aeaa8..8e305e72 100644 --- a/cron/config/config.go +++ b/cron/config/config.go @@ -28,6 +28,7 @@ import ( ) const ( + // ShardNumFilename is the name of the file that stores the number of shards. ShardNumFilename string = ".shard_num" projectID string = "SCORECARD_PROJECT_ID" resultDataBucketURL string = "SCORECARD_DATA_BUCKET_URL" @@ -39,8 +40,10 @@ const ( ) var ( + // ErrorEmptyConfigValue indicates the value for the configuration option was empty. ErrorEmptyConfigValue = errors.New("config value set to empty") - ErrorValueConversion = errors.New("unexpected type, cannot convert value") + // ErrorValueConversion indicates an unexpected type was found for the value of the config option. + ErrorValueConversion = errors.New("unexpected type, cannot convert value") //go:embed config.yaml configYAML []byte ) diff --git a/cron/controller/main.go b/cron/controller/main.go index cf191994..b1f4c7f5 100644 --- a/cron/controller/main.go +++ b/cron/controller/main.go @@ -28,7 +28,7 @@ import ( ) func PublishToRepoRequestTopic(ctx context.Context, iter data.Iterator, datetime time.Time) (int32, error) { - var shardNum int32 = 0 + var shardNum int32 request := data.ScorecardBatchRequest{ JobTime: timestamppb.New(datetime), ShardNum: &shardNum, diff --git a/cron/pubsub/subscriber.go b/cron/pubsub/subscriber.go index 3ee5f7dd..77291c4d 100644 --- a/cron/pubsub/subscriber.go +++ b/cron/pubsub/subscriber.go @@ -28,6 +28,7 @@ import ( "github.com/ossf/scorecard/cron/data" ) +// ErrorInParse indicates there was an error while unmarshalling the protocol buffer message. var ErrorInParse = errors.New("error during protojson.Unmarshal") type Subscriber interface { diff --git a/repos/repo_url.go b/repos/repo_url.go index cb343921..72d7ca36 100644 --- a/repos/repo_url.go +++ b/repos/repo_url.go @@ -22,9 +22,12 @@ import ( ) var ( - ErrorUnsupportedHost = errors.New("unsupported host") + // ErrorUnsupportedHost indicates the repo's host is unsupported. + ErrorUnsupportedHost = errors.New("unsupported host") + // ErrorInvalidGithubURL indicates the repo's GitHub URL is not in the proper format. ErrorInvalidGithubURL = errors.New("invalid GitHub repo URL") - ErrorInvalidURL = errors.New("invalid repo flag") + // ErrorInvalidURL indicates the repo's full GitHub URL was not passed. + ErrorInvalidURL = errors.New("invalid repo flag") ) type RepoURL struct { diff --git a/roundtripper/roundtripper.go b/roundtripper/roundtripper.go index 38c76d87..c0079749 100644 --- a/roundtripper/roundtripper.go +++ b/roundtripper/roundtripper.go @@ -27,15 +27,23 @@ import ( ) const ( - GithubAuthToken = "GITHUB_AUTH_TOKEN" // #nosec G101 - GithubAppKeyPath = "GITHUB_APP_KEY_PATH" - GithubAppID = "GITHUB_APP_ID" - GithubAppInstallationID = "GITHUB_APP_INSTALLATION_ID" - UseDiskCache = "USE_DISK_CACHE" - DiskCachePath = "DISK_CACHE_PATH" - UseBlobCache = "USE_BLOB_CACHE" - BucketURL = "BLOB_URL" - cacheSize uint64 = 10000 * 1024 * 1024 // 10gb + // GithubAuthToken is for making requests to GiHub's API. + GithubAuthToken = "GITHUB_AUTH_TOKEN" // #nosec G101 + // GithubAppKeyPath is the path to file for GitHub App key. + GithubAppKeyPath = "GITHUB_APP_KEY_PATH" + // GithubAppID is the app ID for the GitHub App. + GithubAppID = "GITHUB_APP_ID" + // GithubAppInstallationID is the installation ID for the GitHub App. + GithubAppInstallationID = "GITHUB_APP_INSTALLATION_ID" + // UseDiskCache will cache results on disk for subsequent runs if set to true. + UseDiskCache = "USE_DISK_CACHE" + // DiskCachePath is the path to where the results will be cached on disk if UseDiskCache is true. + DiskCachePath = "DISK_CACHE_PATH" + // UseBlobCache will cache results into a blob store for subsequent runs if set to true. + UseBlobCache = "USE_BLOB_CACHE" + // BucketURL is the URL for blob store cache if UseBlobCache is true. + BucketURL = "BLOB_URL" + cacheSize uint64 = 10000 * 1024 * 1024 // 10gb ) // NewTransport returns a configured http.Transport for use with GitHub. diff --git a/stats/measures.go b/stats/measures.go index c7978d8d..fad45251 100644 --- a/stats/measures.go +++ b/stats/measures.go @@ -17,6 +17,8 @@ package stats import "go.opencensus.io/stats" var ( + // CPURuntimeInSec measures the CPU runtime in seconds. CPURuntimeInSec = stats.Int64("CPURuntimeInSec", "Measures the CPU runtime in seconds", stats.UnitSeconds) - HTTPRequests = stats.Int64("HTTPRequests", "Measures the count of HTTP requests", stats.UnitDimensionless) + // HTTPRequests measures the count of HTTP requests. + HTTPRequests = stats.Int64("HTTPRequests", "Measures the count of HTTP requests", stats.UnitDimensionless) ) diff --git a/stats/tags.go b/stats/tags.go index b716215b..9cd268ae 100644 --- a/stats/tags.go +++ b/stats/tags.go @@ -17,7 +17,10 @@ package stats import "go.opencensus.io/tag" var ( - CheckName = tag.MustNewKey("checkName") - Repo = tag.MustNewKey("repo") + // CheckName is the tag key for the check name. + CheckName = tag.MustNewKey("checkName") + // Repo is the tag key for the repo name. + Repo = tag.MustNewKey("repo") + // RequestTag is the tag key for the request type. RequestTag = tag.MustNewKey("requestTag") ) diff --git a/stats/views.go b/stats/views.go index 3c38d3db..83ed16be 100644 --- a/stats/views.go +++ b/stats/views.go @@ -21,6 +21,7 @@ import ( ) var ( + // CheckRuntime tracks CPU runtime stats. CheckRuntime = view.View{ Name: "CheckRuntime", Description: "CPU runtime stats per repo per check", @@ -45,6 +46,7 @@ var ( 1<<16), } + // OutgoingHTTPRequests tracks HTTPRequests made. OutgoingHTTPRequests = view.View{ Name: "OutgoingHTTPRequests", Description: "HTTPRequests made per repo per check per URL path",