Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap out golint for staticcheck and appease it #82

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:

- name: Install dependencies
run: |
go get -u golang.org/x/lint/golint
go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Lint
run: |
golint -set_exit_status ./...
staticcheck ./...
go vet ./...
go vet -tags=func_test ./...

Expand Down
6 changes: 3 additions & 3 deletions cft/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
func (b builder) newResource(resourceType string) (map[string]interface{}, []*cft.Comment) {
defer func() {
if r := recover(); r != nil {
panic(fmt.Errorf("error building resource type '%s': %w", resourceType, r))
panic(fmt.Errorf("error building resource type '%s': %v", resourceType, r))
}
}()

Expand Down Expand Up @@ -75,7 +75,7 @@ func (b builder) newResource(resourceType string) (map[string]interface{}, []*cf
func (b builder) newProperty(resourceType, propertyName string, pSpec *spec.Property) (interface{}, []*cft.Comment) {
defer func() {
if r := recover(); r != nil {
panic(fmt.Errorf("error building property %s.%s: %w", resourceType, propertyName, r))
panic(fmt.Errorf("error building property %s.%s: %v", resourceType, propertyName, r))
}
}()

Expand Down Expand Up @@ -164,7 +164,7 @@ func (b builder) newPrimitive(primitiveType string) interface{} {
func (b builder) newPropertyType(resourceType, propertyType string) (interface{}, []*cft.Comment) {
defer func() {
if r := recover(); r != nil {
panic(fmt.Errorf("error building property type '%s.%s': %w", resourceType, propertyType, r))
panic(fmt.Errorf("error building property type '%s.%s': %v", resourceType, propertyType, r))
}
}()

Expand Down
2 changes: 1 addition & 1 deletion cft/cft.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (t Template) Map() map[string]interface{} {

err := t.Decode(&out)
if err != nil {
panic(fmt.Errorf("Error converting template to map: %s", err))
panic(fmt.Errorf("error converting template to map: %s", err))
}

return out
Expand Down
6 changes: 3 additions & 3 deletions cft/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (t Template) AddComments(comments []*Comment) error {
}

if len(n.Content) == 0 {
return fmt.Errorf("Unable to set head at node root")
return fmt.Errorf("unable to set head at node root")
}

n.Content[0].HeadComment = comment.Value
Expand All @@ -51,7 +51,7 @@ func (t Template) AddComments(comments []*Comment) error {
case string:
key, value := s11n.GetMapValue(n, v)
if value == nil {
return fmt.Errorf("Can't find map key: '%s'", v)
return fmt.Errorf("can't find map key: '%s'", v)
}

switch value.Kind {
Expand All @@ -76,7 +76,7 @@ func (t Template) AddComments(comments []*Comment) error {
n.HeadComment = comment.Value
}
default:
return fmt.Errorf("Unexpected path element '%#v'", v)
return fmt.Errorf("unexpected path element '%#v'", v)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cft/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s slice) String() string {
parts := make([]string, len(s))

for i, v := range s {
parts[i] = fmt.Sprintf("%s", v)
parts[i] = v.String()
}

return fmt.Sprintf("%s[%s]", s.Mode(), strings.Join(parts, " "))
Expand Down
2 changes: 1 addition & 1 deletion cft/diff/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func formatDiff(d Diff, path []interface{}, long bool) string {
case value:
return v.Format(long)
default:
panic(fmt.Errorf("Unexpected type '%T'", d))
panic(fmt.Errorf("unexpected type '%T'", d))
}
}

Expand Down
8 changes: 4 additions & 4 deletions cft/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func Reader(r io.Reader) (cft.Template, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return cft.Template{}, fmt.Errorf("Unable to read input: %s", err)
return cft.Template{}, fmt.Errorf("unable to read input: %s", err)
}

return String(string(data))
Expand All @@ -27,7 +27,7 @@ func Reader(r io.Reader) (cft.Template, error) {
func File(fileName string) (cft.Template, error) {
source, err := ioutil.ReadFile(fileName)
if err != nil {
return cft.Template{}, fmt.Errorf("Unable to read file: %s", err)
return cft.Template{}, fmt.Errorf("unable to read file: %s", err)
}

return String(string(source))
Expand All @@ -49,7 +49,7 @@ func String(input string) (cft.Template, error) {
var node yaml.Node
err := yaml.Unmarshal([]byte(input), &node)
if err != nil {
return cft.Template{}, fmt.Errorf("Invalid YAML: %s", err)
return cft.Template{}, fmt.Errorf("invalid YAML: %s", err)
}

return Node(&node)
Expand All @@ -74,7 +74,7 @@ func Verify(source cft.Template, output string) error {

d := diff.New(source, validate)
if d.Mode() != diff.Unchanged {
return fmt.Errorf("Semantic difference after formatting:\n%s", d.Format(false))
return fmt.Errorf("semantic difference after formatting:\n%s", d.Format(false))
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions cft/pkg/rain.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func handleS3(root string, options s3Options) (*yaml.Node, error) {
switch options.Format {
case s3Object:
if options.BucketProperty == "" || options.KeyProperty == "" {
return nil, errors.New("Missing BucketProperty or KeyProperty")
return nil, errors.New("missing BucketProperty or KeyProperty")
}

out := map[string]string{
Expand All @@ -105,15 +105,15 @@ func handleS3(root string, options s3Options) (*yaml.Node, error) {
case s3Http:
n.Encode(s.HTTP())
default:
return nil, fmt.Errorf("Unexpected S3 output format: %s", options.Format)
return nil, fmt.Errorf("unexpected S3 output format: %s", options.Format)
}

return &n, nil
}

func includeS3Object(n *yaml.Node, root string) (bool, error) {
if n.Kind != yaml.MappingNode || len(n.Content) != 2 {
return false, errors.New("Expected a map")
return false, errors.New("expected a map")
}

// Parse the options
Expand Down Expand Up @@ -176,7 +176,7 @@ func includeS3URI(n *yaml.Node, root string) (bool, error) {
func includeS3(n *yaml.Node, root string) (bool, error) {
// Figure out if we're a string or an object
if len(n.Content) != 2 {
return false, errors.New("Expected exactly one key")
return false, errors.New("expected exactly one key")
}

if n.Content[1].Kind == yaml.ScalarNode {
Expand Down
6 changes: 4 additions & 2 deletions cft/pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ func upload(root, path string, force bool) (*s3Path, error) {

func expectString(n *yaml.Node) (string, error) {
if len(n.Content) != 2 {
return "", fmt.Errorf("Expected a mapping node")
return "", fmt.Errorf("expected a mapping node")
}

if n.Content[1].Kind != yaml.ScalarNode {
return "", fmt.Errorf("Expected a scalar value")
return "", fmt.Errorf("expected a scalar value")
}

return n.Content[1].Value, nil
Expand Down Expand Up @@ -197,6 +197,7 @@ func expectFile(n *yaml.Node, root string) ([]byte, string, error) {
return content, path, err
}

/*
func expectProps(n *yaml.Node, names ...string) (map[string]string, bool) {
if len(n.Content) != 2 {
return nil, false
Expand Down Expand Up @@ -231,3 +232,4 @@ func expectProps(n *yaml.Node, names ...string) (map[string]string, bool) {

return props, true
}
*/
2 changes: 1 addition & 1 deletion docs/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
// Generate README
buf := bytes.Buffer{}
err = tmpl.Execute(&buf, map[string]string{
"Usage": string(usage.Bytes()),
"Usage": usage.String(),
})
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func WaitUntilStackCreateComplete(stackName string) error {
}

if len(res.Stacks) != 1 {
return errors.New("Stack not found")
return errors.New("stack not found")
}

stack := res.Stacks[0]
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/cfn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func checkTemplate(template cft.Template) (string, error) {
templateBody := format.String(template, format.Options{})

if len(templateBody) > 460800 {
return "", fmt.Errorf("Template is too large to deploy")
return "", fmt.Errorf("template is too large to deploy")
}

if len(templateBody) > 51200 {
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func getSigninToken(userName string) (string, error) {

token, ok := out["SigninToken"]
if !ok {
return "", errors.New("No token present in the response")
return "", errors.New("no token present in the response")
}

return token, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func CreateBucket(bucketName string) error {
// Upload an artefact to the bucket with a unique name
func Upload(bucketName string, content []byte) (string, error) {
if !BucketExists(bucketName) {
return "", fmt.Errorf("Bucket does not exist: '%s'", bucketName)
return "", fmt.Errorf("bucket does not exist: '%s'", bucketName)
}

key := fmt.Sprintf("%x", sha256.Sum256(content))
Expand Down
2 changes: 1 addition & 1 deletion internal/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Ask(prompt string) string {

answer, err := rl.Readline()
if err != nil {
panic(fmt.Errorf("Unable to get user input: %w", err))
panic(fmt.Errorf("unable to get user input: %w", err))
}

return strings.TrimSpace(answer)
Expand Down
3 changes: 1 addition & 2 deletions internal/console/spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

var spin = []string{"˙", "·", ".", " "}
var drops = 3

var hasTimer = false

Expand Down Expand Up @@ -52,7 +51,7 @@ func update() {
console.Cyan(spin[count]),
console.Cyan(spin[(count+3)%len(spin)]),
console.Cyan(spin[(count+5)%len(spin)]),
time.Now().Sub(startTime).Truncate(time.Second),
time.Since(startTime).Truncate(time.Second),
status,
)
} else {
Expand Down
14 changes: 8 additions & 6 deletions internal/s11n/s11n.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ func GetPath(node *yaml.Node, path []interface{}) (*yaml.Node, error) {
case string:
_, value := GetMapValue(node, v)
if value == nil {
return nil, fmt.Errorf("Could not find map key: '%s'", v)
return nil, fmt.Errorf("could not find map key: '%s'", v)
}

return GetPath(value, path)
case int:
if node.Kind != yaml.SequenceNode {
return nil, fmt.Errorf("Attempt to index non-sequence node with '%d'", v)
return nil, fmt.Errorf("attempt to index non-sequence node with '%d'", v)
}

return GetPath(node.Content[v], path)
default:
return nil, fmt.Errorf("Unexpected path entry '%#v'", next)
return nil, fmt.Errorf("unexpected path entry '%#v'", next)
}
}

/*
func setPath(node *yaml.Node, path []interface{}, value *yaml.Node) error {
if len(path) == 0 {
*node = *value
Expand All @@ -72,7 +73,7 @@ func setPath(node *yaml.Node, path []interface{}, value *yaml.Node) error {
switch v := last.(type) {
case string:
if node.Kind != yaml.MappingNode {
return fmt.Errorf("Attempt to set index of non-mapping node with '%s'", v)
return fmt.Errorf("attempt to set index of non-mapping node with '%s'", v)
}

if _, mapValue := GetMapValue(node, v); mapValue != nil {
Expand All @@ -88,7 +89,7 @@ func setPath(node *yaml.Node, path []interface{}, value *yaml.Node) error {
return nil
case int:
if node.Kind != yaml.SequenceNode {
return fmt.Errorf("Attempt to set index of non-sequence node with '%d'", v)
return fmt.Errorf("attempt to set index of non-sequence node with '%d'", v)
}

if v < len(node.Content) {
Expand All @@ -99,6 +100,7 @@ func setPath(node *yaml.Node, path []interface{}, value *yaml.Node) error {

return nil
default:
return fmt.Errorf("Unexpected path entry '%#v'", last)
return fmt.Errorf("unexpected path entry '%#v'", last)
}
}
*/
4 changes: 0 additions & 4 deletions internal/ui/colourise.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const (
pending
)

var statusOrder = []statusCategory{
pending, inProgress, failed, complete,
}

var statusColour = map[statusCategory]func(...interface{}) string{
pending: console.Plain,
inProgress: console.Blue,
Expand Down
4 changes: 0 additions & 4 deletions internal/ui/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func StackHasSettled(stack types.Stack) bool {
return statusIsSettled(string(stack.StackStatus))
}

func resourceHasSettled(resource *types.StackResource) bool {
return statusIsSettled(string(resource.ResourceStatus))
}

func stackResourceStatuses(stack types.Stack) (string, []string) {
stackName := ptr.ToString(stack.StackName)

Expand Down