mirror of https://github.com/pulumi/pulumi.git
1c00e9f990
11857: pkg/codegen: Add types for typeTokenKind values r=abhinav a=abhinav string constants don't behave like iota. With, type something string const ( foo something = "foo" bar = "bar" ) Only `foo` will have the type `something`. `bar` will be an untyped string literal. The type is copied over only when there's no rhs, e.g. type something int const ( foo something = iota bar ) This adds types for constants that were intended to have the type `typeTokenKind`. Issue found by staticcheck: ``` codegen/testing/tstypes/tstypes.go:157:2: SA9004: only the first constant in this group has an explicit type (staticcheck) ``` Refs #11808 11858: codgen/go/test: Replace ineffective sort r=abhinav a=abhinav `sort.StringSlice` is a type wrapper, not a function. type StringSlice []string So `ordering = sort.StringSlice(ordering)` has no effect. This replaces that with use of `sort.Strings`, whic has the desired effect of sorting the slice in place. Also drops the unnecesary index tracking to append into the slice in favor of appends. Issue caught by staticcheck: ``` codegen/go/gen_test.go:220:4: SA4029: sort.StringSlice is a type, not a function, and sort.StringSlice(ordering) doesn't sort your values; consider using sort.Strings instead (staticcheck) ``` Refs #11808 11859: sdk/go/generate: Replace incorrect TrimRight with TrimSuffix r=abhinav a=abhinav Code in go/pulumi/generate that determines the destination file path based on the name of the template incorrectly used TrimRight instead of TrimSuffix. TrimRight removes all instances of *any* of the provided characters (referred to as the cutset) from the provided string instead of removing just a fixed suffix. So if we tried to generate say, a .tmpl file, it would have stripped that from the destination file path too. This switches to TrimSuffix, which is what was intended here, and adds a test to verify the desired behavior. Issue caught by staticcheck: ``` go/pulumi/generate/main.go:343:54: SA1024: cutset contains duplicate characters (staticcheck) ``` Refs #11808 Co-authored-by: Abhinav Gupta <abhinav@pulumi.com> |
||
---|---|---|
.. | ||
test | ||
tstypes | ||
utils |