From bb74c9e670d56e23e61d043dac7f41da0843b40d Mon Sep 17 00:00:00 2001 From: Sean Egan Date: Mon, 2 May 2022 12:06:06 -0600 Subject: [PATCH] Add linting for extraneous blank lines (#558) --- .golangci.yaml | 1 + cmd/registry/cmd/compute/lintstats.go | 3 --- cmd/registry/cmd/list/list.go | 1 - cmd/registry/cmd/resolve/resolve.go | 1 - cmd/registry/cmd/upload/manifest.go | 1 - cmd/registry/cmd/upload/manifest_test.go | 2 -- cmd/registry/cmd/upload/styleguide.go | 1 - cmd/registry/cmd/upload/styleguide_test.go | 2 -- cmd/registry/conformance/conformance-task.go | 3 --- cmd/registry/conformance/conformance-task_test.go | 1 - cmd/registry/conformance/linter.go | 2 -- cmd/registry/conformance/linter_test.go | 1 - cmd/registry/controller/controller.go | 6 ------ cmd/registry/controller/controller_test.go | 6 ------ cmd/registry/controller/local-tasks_test.go | 1 - cmd/registry/controller/parser.go | 2 -- cmd/registry/controller/parser_test.go | 2 -- cmd/registry/core/tasks.go | 2 -- cmd/registry/diff/differ.go | 1 - cmd/registry/metrics/metrics.go | 1 - cmd/registry/patterns/parser.go | 3 --- cmd/registry/patterns/parser_test.go | 2 -- cmd/registry/plugins/registry-lint-api-linter/main.go | 1 - cmd/registry/scoring/parser.go | 2 -- cmd/registry/scoring/parser_test.go | 2 -- tools/registry-decode-spec/main.go | 1 - tools/registry-encode-spec/main.go | 1 - 27 files changed, 1 insertion(+), 51 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 0ad2bb78c..9bf8ad2d5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -29,3 +29,4 @@ linters: enable: - goimports - gofmt + - whitespace diff --git a/cmd/registry/cmd/compute/lintstats.go b/cmd/registry/cmd/compute/lintstats.go index b44821ce5..66de1148a 100644 --- a/cmd/registry/cmd/compute/lintstats.go +++ b/cmd/registry/cmd/compute/lintstats.go @@ -104,7 +104,6 @@ func computeLintStatsSpecs(ctx context.Context, spec names.Spec, filter string, linter string) error { - return core.ListSpecs(ctx, client, spec, filter, func(spec *rpc.ApiSpec) error { // Iterate through a collection of specs and evaluate each. log.Debug(ctx, spec.GetName()) @@ -187,7 +186,6 @@ func computeLintStatsAPIs(ctx context.Context, apiName names.Api, filter string, linter string) error { - return core.ListAPIs(ctx, client, apiName, filter, func(api *rpc.Api) error { api_stats := &rpc.LintStats{} @@ -272,7 +270,6 @@ func matchAndHandleLintStatsCmd( filter string, linter string, ) error { - // First try to match collection names, then try to match resource names. if project, err := names.ParseProjectCollection(name); err == nil { return computeLintStatsProjects(ctx, client, adminClient, project, filter, linter) diff --git a/cmd/registry/cmd/list/list.go b/cmd/registry/cmd/list/list.go index 75356ae87..fe0aa5cd8 100644 --- a/cmd/registry/cmd/list/list.go +++ b/cmd/registry/cmd/list/list.go @@ -60,7 +60,6 @@ func matchAndHandleListCmd( name string, filter string, ) error { - // First try to match collection names. if project, err := names.ParseProjectCollection(name); err == nil { return core.ListProjects(ctx, adminClient, project, filter, core.PrintProject) diff --git a/cmd/registry/cmd/resolve/resolve.go b/cmd/registry/cmd/resolve/resolve.go index 116bb40ae..49e9920aa 100644 --- a/cmd/registry/cmd/resolve/resolve.go +++ b/cmd/registry/cmd/resolve/resolve.go @@ -33,7 +33,6 @@ func fetchManifest( ctx context.Context, client connection.Client, manifestName string) (*rpc.Manifest, error) { - manifest := &rpc.Manifest{} body, err := client.GetArtifactContents( ctx, diff --git a/cmd/registry/cmd/upload/manifest.go b/cmd/registry/cmd/upload/manifest.go index a05c2485f..6a5ef89c5 100644 --- a/cmd/registry/cmd/upload/manifest.go +++ b/cmd/registry/cmd/upload/manifest.go @@ -30,7 +30,6 @@ import ( ) func readManifestProto(filename string) (*rpc.Manifest, error) { - yamlBytes, err := ioutil.ReadFile(filename) if err != nil { return nil, err diff --git a/cmd/registry/cmd/upload/manifest_test.go b/cmd/registry/cmd/upload/manifest_test.go index 63f150402..3b5e62cca 100644 --- a/cmd/registry/cmd/upload/manifest_test.go +++ b/cmd/registry/cmd/upload/manifest_test.go @@ -29,7 +29,6 @@ import ( ) func TestManifestUpload(t *testing.T) { - tests := []struct { desc string project string @@ -116,5 +115,4 @@ func TestManifestUpload(t *testing.T) { } }) } - } diff --git a/cmd/registry/cmd/upload/styleguide.go b/cmd/registry/cmd/upload/styleguide.go index b103cfb91..51fed18d5 100644 --- a/cmd/registry/cmd/upload/styleguide.go +++ b/cmd/registry/cmd/upload/styleguide.go @@ -29,7 +29,6 @@ import ( ) func readStyleGuideProto(filename string) (*rpc.StyleGuide, error) { - yamlBytes, err := ioutil.ReadFile(filename) if err != nil { return nil, err diff --git a/cmd/registry/cmd/upload/styleguide_test.go b/cmd/registry/cmd/upload/styleguide_test.go index 2b6835f41..e27991d12 100644 --- a/cmd/registry/cmd/upload/styleguide_test.go +++ b/cmd/registry/cmd/upload/styleguide_test.go @@ -29,7 +29,6 @@ import ( ) func TestStyleGuideUpload(t *testing.T) { - tests := []struct { desc string project string @@ -134,5 +133,4 @@ func TestStyleGuideUpload(t *testing.T) { } }) } - } diff --git a/cmd/registry/conformance/conformance-task.go b/cmd/registry/conformance/conformance-task.go index b0a06ddb3..d225b3440 100644 --- a/cmd/registry/conformance/conformance-task.go +++ b/cmd/registry/conformance/conformance-task.go @@ -114,7 +114,6 @@ func (task *ComputeConformanceTask) Run(ctx context.Context) error { conformanceReport := initializeConformanceReport(task.Spec.GetName(), task.StyleguideId) guidelineReportsMap := make(map[string]int) for _, metadata := range task.LintersMetadata { - linterResponse, err := task.invokeLinter(ctx, root, metadata) // If a linter returned an error, we shouldn't stop linting completely across all linters and // discard the conformance report for this spec. We should log but still continue, because there @@ -134,7 +133,6 @@ func (task *ComputeConformanceTask) invokeLinter( ctx context.Context, specDirectory string, metadata *linterMetadata) (*rpc.LinterResponse, error) { - // Formulate the request. requestBytes, err := proto.Marshal(&rpc.LinterRequest{ SpecDirectory: specDirectory, @@ -181,7 +179,6 @@ func (task *ComputeConformanceTask) computeConformanceReport( linterResponse *rpc.LinterResponse, linterMetadata *linterMetadata, ) { - // Process linterResponse to generate conformance report lintFiles := linterResponse.Lint.GetFiles() diff --git a/cmd/registry/conformance/conformance-task_test.go b/cmd/registry/conformance/conformance-task_test.go index c22fc1446..466d9a721 100644 --- a/cmd/registry/conformance/conformance-task_test.go +++ b/cmd/registry/conformance/conformance-task_test.go @@ -594,5 +594,4 @@ func TestPreExistingConformanceReport(t *testing.T) { if !cmp.Equal(wantReport, preexistingReport, opts) { t.Errorf("GetDiff returned unexpected diff (-want +got):\n%s", cmp.Diff(wantReport, preexistingReport, opts)) } - } diff --git a/cmd/registry/conformance/linter.go b/cmd/registry/conformance/linter.go index 09fb4c5c6..9450f7967 100644 --- a/cmd/registry/conformance/linter.go +++ b/cmd/registry/conformance/linter.go @@ -36,12 +36,10 @@ func getLinterBinaryName(linterName string) string { } func GenerateLinterMetadata(styleguide *rpc.StyleGuide) (map[string]*linterMetadata, error) { - linterNameToMetadata := make(map[string]*linterMetadata) // Iterate through all the guidelines of the style guide. for _, guideline := range styleguide.GetGuidelines() { - // Iterate through all the rules of the style guide. for _, rule := range guideline.GetRules() { // Get the name of the linter associated with the rule. diff --git a/cmd/registry/conformance/linter_test.go b/cmd/registry/conformance/linter_test.go index 27b2160be..b469a0ee0 100644 --- a/cmd/registry/conformance/linter_test.go +++ b/cmd/registry/conformance/linter_test.go @@ -268,7 +268,6 @@ func TestGenerateLinterMetadata(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - got, err := GenerateLinterMetadata(test.styleguide) if test.wantErr && err == nil { diff --git a/cmd/registry/controller/controller.go b/cmd/registry/controller/controller.go index 87500207d..1996d58a4 100644 --- a/cmd/registry/controller/controller.go +++ b/cmd/registry/controller/controller.go @@ -37,7 +37,6 @@ func ProcessManifest( client connection.Client, projectID string, manifest *rpc.Manifest) []*Action { - var actions []*Action //Check for errors in manifest errs := ValidateManifest(ctx, fmt.Sprintf("projects/%s", projectID), manifest) @@ -142,7 +141,6 @@ func generateDependencyMap( } return sourceMap, nil - } func generateActions( @@ -170,7 +168,6 @@ func generateActions( } return actions - } // Go over the list of existing target resources to figure out which ones need an update. @@ -181,7 +178,6 @@ func generateUpdateActions( filter string, dependencyMaps []map[string]time.Time, generatedResource *rpc.GeneratedResource) ([]*Action, map[string]bool, error) { - // Visited tracks the parents of target resources which were already generated. visited := make(map[string]bool) actions := make([]*Action, 0) @@ -221,7 +217,6 @@ func generateUpdateActions( } actions = append(actions, a) } - } return actions, visited, nil @@ -259,7 +254,6 @@ func generateCreateActions( dependencyMaps []map[string]time.Time, generatedResource *rpc.GeneratedResource, visited map[string]bool) ([]*Action, error) { - var parentList []patterns.ResourceInstance parsedResourcePattern, err := patterns.ParseResourcePattern(resourcePattern) diff --git a/cmd/registry/controller/controller_test.go b/cmd/registry/controller/controller_test.go index 71bb353f9..d0a320869 100644 --- a/cmd/registry/controller/controller_test.go +++ b/cmd/registry/controller/controller_test.go @@ -335,7 +335,6 @@ func TestAggregateArtifacts(t *testing.T) { deleteProject(ctx, adminClient, t, "controller-test") }) } - } // Tests for derived artifacts with artifacts as dependencies @@ -515,7 +514,6 @@ func TestDerivedArtifacts(t *testing.T) { deleteProject(ctx, adminClient, t, "controller-test") }) } - } // Tests for receipt artifacts as generated resource @@ -605,7 +603,6 @@ func TestReceiptArtifacts(t *testing.T) { deleteProject(ctx, adminClient, t, "controller-test") }) } - } // Tests for receipt aggregate artifacts as generated resource @@ -713,7 +710,6 @@ func TestReceiptAggArtifacts(t *testing.T) { deleteProject(ctx, adminClient, t, "controller-test") }) } - } // Tests for manifest with multiple entity references @@ -818,7 +814,6 @@ func TestMultipleEntitiesArtifacts(t *testing.T) { // Version 1.1.0 createVersion(ctx, client, t, "projects/controller-test/locations/global/apis/petstore", "1.1.0") createSpec(ctx, client, t, "projects/controller-test/locations/global/apis/petstore/versions/1.1.0", "openapi.yaml", gzipOpenAPIv3) - }, want: []*Action{ { @@ -881,5 +876,4 @@ func TestMultipleEntitiesArtifacts(t *testing.T) { deleteProject(ctx, adminClient, t, "controller-test") }) } - } diff --git a/cmd/registry/controller/local-tasks_test.go b/cmd/registry/controller/local-tasks_test.go index 7ea0b850d..b4bc09df5 100644 --- a/cmd/registry/controller/local-tasks_test.go +++ b/cmd/registry/controller/local-tasks_test.go @@ -21,7 +21,6 @@ import ( // Test the error scenario func TestErrorCases(t *testing.T) { - task := &ExecCommandTask{ Action: &Action{ Command: "resolve projects/demo/artifacts/test-manifest", diff --git a/cmd/registry/controller/parser.go b/cmd/registry/controller/parser.go index 658b24130..465f80bd9 100644 --- a/cmd/registry/controller/parser.go +++ b/cmd/registry/controller/parser.go @@ -82,7 +82,6 @@ func validateGeneratedResourceEntry(parent string, generatedResource *rpc.Genera if !validateEntityReference(parsedTargetResource, entityType) { errs = append(errs, fmt.Errorf("invalid reference in dependency pattern: %s", dependency.Pattern)) } - } //Validate that all the action References are valid @@ -138,7 +137,6 @@ func getReferencesFromAction(action string) ([]*reference, error) { } func generateCommand(action string, resourceName string) (string, error) { - references, err := getReferencesFromAction(action) if err != nil { return "", err diff --git a/cmd/registry/controller/parser_test.go b/cmd/registry/controller/parser_test.go index 7f1524b5d..f45a473ff 100644 --- a/cmd/registry/controller/parser_test.go +++ b/cmd/registry/controller/parser_test.go @@ -73,7 +73,6 @@ func TestGenerateCommand(t *testing.T) { } }) } - } func TestGenerateCommandError(t *testing.T) { @@ -107,7 +106,6 @@ func TestGenerateCommandError(t *testing.T) { } }) } - } func TestValidateGeneratedResourceEntry(t *testing.T) { diff --git a/cmd/registry/core/tasks.go b/cmd/registry/core/tasks.go index a138ea64c..33c97a3f7 100644 --- a/cmd/registry/core/tasks.go +++ b/cmd/registry/core/tasks.go @@ -47,7 +47,6 @@ func WorkerPool(ctx context.Context, n int) (chan<- Task, func()) { } return taskQueue, wait - } // Similar to WorkerPool except it creates workers which log task errors as "Warnings" @@ -65,7 +64,6 @@ func WorkerPoolWithWarnings(ctx context.Context, n int) (chan<- Task, func()) { } return taskQueue, wait - } // A worker which pulls tasks from the taskQueue, executes them and logs errors if any. diff --git a/cmd/registry/diff/differ.go b/cmd/registry/diff/differ.go index 8d12ab4ee..51e8517c3 100644 --- a/cmd/registry/diff/differ.go +++ b/cmd/registry/diff/differ.go @@ -167,7 +167,6 @@ func searchMapType(mapNode reflect.Value, diffProto *rpc.Diff, changePath *chang default: return fmt.Errorf("map node key %v is not supported", childNodeKey) } - } return nil } diff --git a/cmd/registry/metrics/metrics.go b/cmd/registry/metrics/metrics.go index 1d081e7d6..d90b7275f 100644 --- a/cmd/registry/metrics/metrics.go +++ b/cmd/registry/metrics/metrics.go @@ -24,7 +24,6 @@ func ComputeStats(diffs ...*rpc.ChangeDetails) *rpc.ChangeStats { var nonbreaking int64 = 0 var unknown int64 = 0 for _, diff := range diffs { - breaking += int64(len(diff.BreakingChanges.Additions)) breaking += int64(len(diff.BreakingChanges.Deletions)) breaking += int64(len(diff.BreakingChanges.Modifications)) diff --git a/cmd/registry/patterns/parser.go b/cmd/registry/patterns/parser.go index 5e53927d2..375672c1d 100644 --- a/cmd/registry/patterns/parser.go +++ b/cmd/registry/patterns/parser.go @@ -45,7 +45,6 @@ func parseResource(resourcePattern string) (ResourceName, error) { } func ParseResourcePattern(resourcePattern string) (ResourceName, error) { - // First try to match resource collections. resource, err := parseResourceCollection(resourcePattern) if err == nil { @@ -97,7 +96,6 @@ func SubstituteReferenceEntity(resourcePattern string, referred ResourceName) (R return nil, err } return extendedName, nil - } func GetReferenceEntityType(resourcePattern string) (entity, entityType string, err error) { @@ -172,7 +170,6 @@ func GetReferenceEntityValue(resourcePattern string, referred ResourceName) (str default: return "", fmt.Errorf("invalid combination referred: %q resourcePattern: %q", referred, resourcePattern) } - } func FullResourceNameFromParent(resourcePattern string, parent string) (ResourceName, error) { diff --git a/cmd/registry/patterns/parser_test.go b/cmd/registry/patterns/parser_test.go index eee265337..89fcb0856 100644 --- a/cmd/registry/patterns/parser_test.go +++ b/cmd/registry/patterns/parser_test.go @@ -165,7 +165,6 @@ func TestFullResourceNameFromParent(t *testing.T) { } }) } - } func TestFullResourceNameFromParentError(t *testing.T) { @@ -194,7 +193,6 @@ func TestFullResourceNameFromParentError(t *testing.T) { } }) } - } func TestGetReferenceEntityValue(t *testing.T) { diff --git a/cmd/registry/plugins/registry-lint-api-linter/main.go b/cmd/registry/plugins/registry-lint-api-linter/main.go index 7d435303b..b32ad349d 100644 --- a/cmd/registry/plugins/registry-lint-api-linter/main.go +++ b/cmd/registry/plugins/registry-lint-api-linter/main.go @@ -40,7 +40,6 @@ func (linter *apiLinterRunner) RunImpl( req *rpc.LinterRequest, runLinter runLinter, ) (*rpc.LinterResponse, error) { - lintFiles := make([]*rpc.LintFile, 0) // Traverse the files in the directory diff --git a/cmd/registry/scoring/parser.go b/cmd/registry/scoring/parser.go index 85e76a654..ef69bbd4d 100644 --- a/cmd/registry/scoring/parser.go +++ b/cmd/registry/scoring/parser.go @@ -95,7 +95,6 @@ func ValidateScoreCardDefinition(ctx context.Context, parent string, scoreCardDe if strings.HasSuffix(pattern, "/-") { totalErrs = append(totalErrs, fmt.Errorf("invalid score_pattern : %q, it should end with a resourceID and not a \"-\"", pattern)) } - } } @@ -139,7 +138,6 @@ func validateScoreFormula(targetName patterns.ResourceName, scoreFormula *rpc.Sc } func validateNumberThresholds(thresholds []*rpc.NumberThreshold, minValue, maxValue int32) []error { - if len(thresholds) == 0 { // no error returned since thresholds are optional return []error{} diff --git a/cmd/registry/scoring/parser_test.go b/cmd/registry/scoring/parser_test.go index 0e6896608..d87cbfc10 100644 --- a/cmd/registry/scoring/parser_test.go +++ b/cmd/registry/scoring/parser_test.go @@ -1308,7 +1308,6 @@ func TestValidateNumberThresholds(t *testing.T) { } }) } - } func TestValidateBooleanThresholds(t *testing.T) { @@ -1541,5 +1540,4 @@ func TestValidateScoreCardDefinition(t *testing.T) { } }) } - } diff --git a/tools/registry-decode-spec/main.go b/tools/registry-decode-spec/main.go index b05099e49..609f03247 100644 --- a/tools/registry-decode-spec/main.go +++ b/tools/registry-decode-spec/main.go @@ -30,7 +30,6 @@ import ( // to decode specs returned by the apg tool, with an additional effort to // handle the hex-encoded inputs produced by registry-encode-spec. func main() { - // decode the spec reader := bufio.NewReader(os.Stdin) s, _ := reader.ReadString('\n') diff --git a/tools/registry-encode-spec/main.go b/tools/registry-encode-spec/main.go index 01cced683..605a1f236 100644 --- a/tools/registry-encode-spec/main.go +++ b/tools/registry-encode-spec/main.go @@ -28,7 +28,6 @@ import ( // gzip --stdout | xxd -p | tr -d '\n' // but with a platform-independent gzip encoding to provide more stable results. func main() { - // gzip the spec var buf bytes.Buffer zw, _ := gzip.NewWriterLevel(&buf, gzip.BestCompression)