Skip to content

Commit

Permalink
Add linting for extraneous blank lines (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
seaneganx authored May 2, 2022
1 parent e50abec commit bb74c9e
Show file tree
Hide file tree
Showing 27 changed files with 1 addition and 51 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ linters:
enable:
- goimports
- gofmt
- whitespace
3 changes: 0 additions & 3 deletions cmd/registry/cmd/compute/lintstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/cmd/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/cmd/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/cmd/upload/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
)

func readManifestProto(filename string) (*rpc.Manifest, error) {

yamlBytes, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/cmd/upload/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
)

func TestManifestUpload(t *testing.T) {

tests := []struct {
desc string
project string
Expand Down Expand Up @@ -116,5 +115,4 @@ func TestManifestUpload(t *testing.T) {
}
})
}

}
1 change: 0 additions & 1 deletion cmd/registry/cmd/upload/styleguide.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
)

func readStyleGuideProto(filename string) (*rpc.StyleGuide, error) {

yamlBytes, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/cmd/upload/styleguide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
)

func TestStyleGuideUpload(t *testing.T) {

tests := []struct {
desc string
project string
Expand Down Expand Up @@ -134,5 +133,4 @@ func TestStyleGuideUpload(t *testing.T) {
}
})
}

}
3 changes: 0 additions & 3 deletions cmd/registry/conformance/conformance-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -181,7 +179,6 @@ func (task *ComputeConformanceTask) computeConformanceReport(
linterResponse *rpc.LinterResponse,
linterMetadata *linterMetadata,
) {

// Process linterResponse to generate conformance report
lintFiles := linterResponse.Lint.GetFiles()

Expand Down
1 change: 0 additions & 1 deletion cmd/registry/conformance/conformance-task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
2 changes: 0 additions & 2 deletions cmd/registry/conformance/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/conformance/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions cmd/registry/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -142,7 +141,6 @@ func generateDependencyMap(
}

return sourceMap, nil

}

func generateActions(
Expand Down Expand Up @@ -170,7 +168,6 @@ func generateActions(
}

return actions

}

// Go over the list of existing target resources to figure out which ones need an update.
Expand All @@ -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)
Expand Down Expand Up @@ -221,7 +217,6 @@ func generateUpdateActions(
}
actions = append(actions, a)
}

}

return actions, visited, nil
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions cmd/registry/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ func TestAggregateArtifacts(t *testing.T) {
deleteProject(ctx, adminClient, t, "controller-test")
})
}

}

// Tests for derived artifacts with artifacts as dependencies
Expand Down Expand Up @@ -515,7 +514,6 @@ func TestDerivedArtifacts(t *testing.T) {
deleteProject(ctx, adminClient, t, "controller-test")
})
}

}

// Tests for receipt artifacts as generated resource
Expand Down Expand Up @@ -605,7 +603,6 @@ func TestReceiptArtifacts(t *testing.T) {
deleteProject(ctx, adminClient, t, "controller-test")
})
}

}

// Tests for receipt aggregate artifacts as generated resource
Expand Down Expand Up @@ -713,7 +710,6 @@ func TestReceiptAggArtifacts(t *testing.T) {
deleteProject(ctx, adminClient, t, "controller-test")
})
}

}

// Tests for manifest with multiple entity references
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -881,5 +876,4 @@ func TestMultipleEntitiesArtifacts(t *testing.T) {
deleteProject(ctx, adminClient, t, "controller-test")
})
}

}
1 change: 0 additions & 1 deletion cmd/registry/controller/local-tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/controller/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/controller/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestGenerateCommand(t *testing.T) {
}
})
}

}

func TestGenerateCommandError(t *testing.T) {
Expand Down Expand Up @@ -107,7 +106,6 @@ func TestGenerateCommandError(t *testing.T) {
}
})
}

}

func TestValidateGeneratedResourceEntry(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/core/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/diff/differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions cmd/registry/patterns/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/patterns/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func TestFullResourceNameFromParent(t *testing.T) {
}
})
}

}

func TestFullResourceNameFromParentError(t *testing.T) {
Expand Down Expand Up @@ -194,7 +193,6 @@ func TestFullResourceNameFromParentError(t *testing.T) {
}
})
}

}

func TestGetReferenceEntityValue(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/plugins/registry-lint-api-linter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/scoring/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
}

Expand Down Expand Up @@ -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{}
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/scoring/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,6 @@ func TestValidateNumberThresholds(t *testing.T) {
}
})
}

}

func TestValidateBooleanThresholds(t *testing.T) {
Expand Down Expand Up @@ -1541,5 +1540,4 @@ func TestValidateScoreCardDefinition(t *testing.T) {
}
})
}

}
1 change: 0 additions & 1 deletion tools/registry-decode-spec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion tools/registry-encode-spec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bb74c9e

Please sign in to comment.