Skip to content

Commit

Permalink
Fix golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gordon-klotho committed Nov 29, 2023
1 parent 08d758f commit 12f0781
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 121 deletions.
4 changes: 4 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ tab-width = 2
# there's currently no way to only log violations in golangci-lint
# https://github.com/golangci/golangci-lint/issues/1981
# enable = ["lll"]

[run]
# Don't bother linting test files
skip-files = ["pkg/.*_test.go"]
2 changes: 1 addition & 1 deletion cmd/ast/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
defer z.Sync() // nolint:errcheck
defer z.Sync() //nolint:errcheck
defer zap.ReplaceGlobals(z)()

if cfg.file == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func ReadConfig(fpath string) (Application, error) {
if err != nil {
return appCfg, err
}
defer f.Close() // nolint:errcheck
defer f.Close() //nolint:errcheck

return ReadConfigReader(fpath, f)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/engine2/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ func (em *EngineMain) RunEngine(cmd *cobra.Command, args []string) error {
pprof.StopCPUProfile()
profileF.Close()
}()
pprof.StartCPUProfile(profileF)
err = pprof.StartCPUProfile(profileF)
if err != nil {
return fmt.Errorf("failed to start profile: %w", err)
}
}

// Set up analytics, and hook them up to the logs
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine2/constraints/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func LoadConstraintsFromFile(path string) (Constraints, error) {
if err != nil {
return Constraints{}, err
}
defer f.Close() // nolint:errcheck
defer f.Close() //nolint:errcheck

err = yaml.NewDecoder(f).Decode(&input)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/engine2/operational_eval/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ func newChanges() graphChanges {
}

// addNode is a convenient lower-level add for [graphChanges.nodes]
//
//nolint:unused
func (changes graphChanges) addNode(v Vertex) {
changes.nodes[v.Key()] = v
}
Expand Down Expand Up @@ -434,7 +436,11 @@ func (eval *Evaluator) UpdateId(oldId, newId construct.ResourceId) error {
replaceVertex(key, vertex)
// because the temp graph contains the src and target as nodes, we need to update it if it exists
if vertex.TempGraph != nil {
construct.ReplaceResource(vertex.TempGraph, oldId, &construct.Resource{ID: newId})
err := construct.ReplaceResource(vertex.TempGraph, oldId, &construct.Resource{ID: newId})
if err != nil {
errs = errors.Join(errs, err)
continue
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/engine2/operational_eval/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ func (eval *Evaluator) pathVertices(source, target construct.ResourceId) (graphC
generateAndAddVertex := func(
edge construct.SimpleEdge,
kb knowledgebase.TemplateKB,
satisfication knowledgebase.EdgePathSatisfaction) error {
satisfication knowledgebase.EdgePathSatisfaction,
) error {
if satisfication.Classification == "" {
return fmt.Errorf("edge %s has no classification to expand", edge)
}

buildTempGraph := true
// We are checking to see if either of the source or target nodes will change due to property references,
Expand Down
19 changes: 0 additions & 19 deletions pkg/engine2/operational_eval/vertex_internal.go

This file was deleted.

8 changes: 0 additions & 8 deletions pkg/engine2/operational_eval/vertex_path_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ type (
TempGraph construct.Graph
Satisfication knowledgebase.EdgePathSatisfaction
}

// pathSatisfication is a wrapper around [EdgePathSatisfaction] that makes unset distinguishable
// from expanding on an empty classification. Once all expansions have classification, this can
// be removed and use [EdgePathSatisfaction] directly (`.valid` becomes `.Classification != ""`)
pathSatisfication struct {
knowledgebase.EdgePathSatisfaction
valid bool
}
)

func (v *pathExpandVertex) Key() Key {
Expand Down
12 changes: 0 additions & 12 deletions pkg/engine2/operational_rule/operational_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

"github.com/dominikbraun/graph"
"github.com/iancoleman/strcase"
construct "github.com/klothoplatform/klotho/pkg/construct2"
"github.com/klothoplatform/klotho/pkg/engine2/reconciler"
"github.com/klothoplatform/klotho/pkg/engine2/solution_context"
Expand Down Expand Up @@ -243,17 +242,6 @@ func (ctx OperationalRuleContext) removeDependencyForDirection(direction knowled
}
}

func (ctx OperationalRuleContext) addResourceName(partialId construct.ResourceId) construct.ResourceId {
// TODO handle cases when multiple resources want to use the same ID, such as `aws:subnet:myvpc:public` by adding an
// incrementing number to them.
if ctx.Property != nil {
partialId.Name = strcase.ToSnake(ctx.Property.Name)
return partialId
}
partialId.Name = fmt.Sprintf("%s_%s", ctx.Data.Edge.Source.Name, ctx.Data.Edge.Target.Name)
return partialId
}

func (ctx OperationalRuleContext) SetField(resource, fieldResource *construct.Resource, step knowledgebase.OperationalStep) error {
if ctx.Property == nil {
return nil
Expand Down
14 changes: 2 additions & 12 deletions pkg/engine2/path_selection/candidate_validity.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ import (
)

type (
// validityChecker defines methods for checking validity of a candidate based on the operation specified in the
// path satisfaction route. The validityChecker has the ability to both check if a candidate is valid
// and mutate a candidate to be valid
validityChecker interface {
isValid(resourceToCheck, targetResource construct.ResourceId) (bool, error)
makeValid(resource, operationResource construct.ResourceId) error
}

// downstreamChecker is a validityChecker that checks if a candidate is valid based on what is downstream of the specified
// resources
downstreamChecker struct {
Expand Down Expand Up @@ -279,11 +271,9 @@ func (d downstreamChecker) makeValid(resource, operationResource *construct.Reso
}
}
if p.IsPropertyTypeScalar() {
currRes.SetProperty(property, downstream)
return true, errs
return true, errors.Join(errs, currRes.SetProperty(property, downstream))
} else {
currRes.AppendProperty(property, downstream)
return true, errs
return true, errors.Join(errs, currRes.AppendProperty(property, downstream))
}
}
return false, errs
Expand Down
50 changes: 0 additions & 50 deletions pkg/engine2/path_selection/path_expansion.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,56 +433,6 @@ func ExpandPath(
return nil
}

func runOnNamespaces(src, target *construct.Resource, ctx solution_context.SolutionContext, result ExpansionResult) error {
if src.ID.Namespace != "" && target.ID.Namespace != "" {
kb := ctx.KnowledgeBase()
targetNamespaceResourceId, err := kb.GetResourcesNamespaceResource(target)
if targetNamespaceResourceId.IsZero() {
return fmt.Errorf("could not find namespace resource for %s", target)
}
if err != nil {
return err
}

srcNamespaceResourceId, err := kb.GetResourcesNamespaceResource(src)
if srcNamespaceResourceId.IsZero() {
return fmt.Errorf("could not find namespace resource for %s", src)
}
if err != nil {
return err
}
srcNamespaceResource, err := ctx.RawView().Vertex(srcNamespaceResourceId)
if err != nil {
return err
}
targetNamespaceResource, err := ctx.RawView().Vertex(targetNamespaceResourceId)
if err != nil {
return err
}
// if we have a namespace resource that is not the same as the target namespace resource
tg, err := BuildPathSelectionGraph(
construct.SimpleEdge{Source: srcNamespaceResourceId, Target: targetNamespaceResourceId},
kb,
"",
)
if err != nil {
return fmt.Errorf("could not build path selection graph: %w", err)
}
// TODO: We should get all of the as source and as targets here to ensure we have all paths required
input := ExpansionInput{
Dep: construct.ResourceEdge{Source: srcNamespaceResource, Target: targetNamespaceResource},
Classification: "",
TempGraph: tg,
}
edges, err := expandEdge(ctx, input, result.Graph)
if err != nil {
return err
}
result.Edges = append(result.Edges, edges...)
}
return nil
}

func connectThroughNamespace(src, target *construct.Resource, ctx solution_context.SolutionContext, result ExpansionResult) (
connected bool,
errs error,
Expand Down
4 changes: 2 additions & 2 deletions pkg/graph_loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func LoadConstructGraphFromFile(path string) (*construct.ConstructGraph, error)
if err != nil {
return graph, err
}
defer f.Close() // nolint:errcheck
defer f.Close() //nolint:errcheck
err = yaml.NewDecoder(f).Decode(&input)
if err != nil {
return graph, err
Expand Down Expand Up @@ -95,7 +95,7 @@ func LoadResourceGraphFromFile(path string) (*construct.ResourceGraph, error) {
if err != nil {
return graph, err
}
defer f.Close() // nolint:errcheck
defer f.Close() //nolint:errcheck
err = yaml.NewDecoder(f).Decode(&input)
if err != nil {
return graph, err
Expand Down
5 changes: 4 additions & 1 deletion pkg/infra/cli2.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func GenerateIac(cmd *cobra.Command, args []string) error {
pprof.StopCPUProfile()
profileF.Close()
}()
pprof.StartCPUProfile(profileF)
err = pprof.StartCPUProfile(profileF)
if err != nil {
return fmt.Errorf("failed to start profile: %w", err)
}
}

var files []io.File
Expand Down
11 changes: 0 additions & 11 deletions pkg/infra/iac3/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,8 @@ type (
}

appliedOutputs []appliedOutput

// undefinedT is a helper type to represent the `undefined` value in a template. It is needed over just using
// "undefined" because the string is not false-y.
undefinedT string
)

// undefined is false-y in a template (if used in an `if`), but resolves to `undefined` when rendered.
var undefined = undefinedT("")

func (undefinedT) String() string {
return "undefined"
}

func (tc TemplatesCompiler) NewAppliedOutput(ref construct.PropertyRef, name string) appliedOutput {
ao := appliedOutput{Name: name}
if ao.Name == "" {
Expand Down

0 comments on commit 12f0781

Please sign in to comment.