diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ffa2bed2..0d9d5533 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,7 +15,13 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - + + - name: Setup golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest + args: --verbose + - name: Get dependencies run: | go get -v -t -d ./... diff --git a/.golangci.yml b/.golangci.yml index 7a9f27b7..c863e759 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,9 +8,16 @@ linters: - goimports - gosec - misspell + - revive issues: exclude-rules: - linters: - gosec text: "Implicit memory aliasing in for loop." path: _test\.go + - linters: + - revive + text: "unexported-return" + - linters: + - revive + text: "var-naming" diff --git a/pkg/yqlib/all_at_once_evaluator.go b/pkg/yqlib/all_at_once_evaluator.go index 9c79a035..d23c56c6 100644 --- a/pkg/yqlib/all_at_once_evaluator.go +++ b/pkg/yqlib/all_at_once_evaluator.go @@ -50,7 +50,7 @@ func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string fileIndex := 0 firstFileLeadingContent := "" - var allDocuments *list.List = list.New() + var allDocuments = list.New() for _, filename := range filenames { reader, leadingContent, err := readStream(filename, fileIndex == 0 && leadingContentPreProcessing) if err != nil { diff --git a/pkg/yqlib/candidate_node.go b/pkg/yqlib/candidate_node.go index 428bbeca..2bfbc586 100644 --- a/pkg/yqlib/candidate_node.go +++ b/pkg/yqlib/candidate_node.go @@ -56,7 +56,7 @@ func (n *CandidateNode) AsList() *list.List { } func (n *CandidateNode) CreateChildInMap(key *yaml.Node, node *yaml.Node) *CandidateNode { - var value interface{} = nil + var value interface{} if key != nil { value = key.Value } diff --git a/pkg/yqlib/operator_anchors_aliases.go b/pkg/yqlib/operator_anchors_aliases.go index c9ee4ca0..6e7ef987 100644 --- a/pkg/yqlib/operator_anchors_aliases.go +++ b/pkg/yqlib/operator_anchors_aliases.go @@ -220,22 +220,21 @@ func explodeNode(node *yaml.Node, context Context) error { if hasAlias { // this is a slow op, which is why we want to check before running it. return reconstructAliasedMap(node, context) - } else { - // this map has no aliases, but it's kids might - for index := 0; index < len(node.Content); index = index + 2 { - keyNode := node.Content[index] - valueNode := node.Content[index+1] - err := explodeNode(keyNode, context) - if err != nil { - return err - } - err = explodeNode(valueNode, context) - if err != nil { - return err - } - } - return nil } + // this map has no aliases, but it's kids might + for index := 0; index < len(node.Content); index = index + 2 { + keyNode := node.Content[index] + valueNode := node.Content[index+1] + err := explodeNode(keyNode, context) + if err != nil { + return err + } + err = explodeNode(valueNode, context) + if err != nil { + return err + } + } + return nil default: return nil } diff --git a/pkg/yqlib/operator_collect_object.go b/pkg/yqlib/operator_collect_object.go index 9cc6792d..6543fe11 100644 --- a/pkg/yqlib/operator_collect_object.go +++ b/pkg/yqlib/operator_collect_object.go @@ -28,7 +28,7 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, expres return context.SingleChildContext(candidate), nil } first := context.MatchingNodes.Front().Value.(*CandidateNode) - var rotated []*list.List = make([]*list.List, len(first.Node.Content)) + var rotated = make([]*list.List, len(first.Node.Content)) for i := 0; i < len(first.Node.Content); i++ { rotated[i] = list.New() diff --git a/pkg/yqlib/operator_create_map.go b/pkg/yqlib/operator_create_map.go index cac23356..d5ca9954 100644 --- a/pkg/yqlib/operator_create_map.go +++ b/pkg/yqlib/operator_create_map.go @@ -14,7 +14,7 @@ func createMapOperator(d *dataTreeNavigator, context Context, expressionNode *Ex var path []interface{} - var document uint = 0 + var document uint sequences := list.New() @@ -42,7 +42,7 @@ func createMapOperator(d *dataTreeNavigator, context Context, expressionNode *Ex func sequenceFor(d *dataTreeNavigator, context Context, matchingNode *CandidateNode, expressionNode *ExpressionNode) (*CandidateNode, error) { var path []interface{} - var document uint = 0 + var document uint var matches = list.New() if matchingNode != nil { diff --git a/pkg/yqlib/operator_multiply.go b/pkg/yqlib/operator_multiply.go index ff0410e9..2602b7a6 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -114,7 +114,7 @@ func mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs return nil, err } - var pathIndexToStartFrom int = 0 + var pathIndexToStartFrom int if results.Front() != nil { pathIndexToStartFrom = len(results.Front().Value.(*CandidateNode).Path) } diff --git a/pkg/yqlib/operator_split_document.go b/pkg/yqlib/operator_split_document.go index 6cabcd23..eba24964 100644 --- a/pkg/yqlib/operator_split_document.go +++ b/pkg/yqlib/operator_split_document.go @@ -3,7 +3,7 @@ package yqlib func splitDocumentOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { log.Debugf("-- splitDocumentOperator") - var index uint = 0 + var index uint for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) candidate.Document = index diff --git a/pkg/yqlib/operator_strings.go b/pkg/yqlib/operator_strings.go index 59e18e48..cfcd3a17 100644 --- a/pkg/yqlib/operator_strings.go +++ b/pkg/yqlib/operator_strings.go @@ -62,7 +62,7 @@ func substituteStringOperator(d *dataTreeNavigator, context Context, expressionN candidate := el.Value.(*CandidateNode) node := unwrapDoc(candidate.Node) if node.Tag != "!!str" { - return Context{}, fmt.Errorf("cannot substitute with %v, can only substitute strings. Hint: Most often you'll want to use '|=' over '=' for this operation.", node.Tag) + return Context{}, fmt.Errorf("cannot substitute with %v, can only substitute strings. Hint: Most often you'll want to use '|=' over '=' for this operation", node.Tag) } targetNode := substitute(node.Value, regEx, replacementText) diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index 197e1755..7bd66589 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -91,7 +91,7 @@ func testScenario(t *testing.T, s *expressionScenario) { } func resultsToString(t *testing.T, results *list.List) []string { - var pretty []string = make([]string, 0) + var pretty = make([]string, 0) for el := results.Front(); el != nil; el = el.Next() { n := el.Value.(*CandidateNode) diff --git a/pkg/yqlib/stream_evaluator.go b/pkg/yqlib/stream_evaluator.go index f49c6745..ddb777fb 100644 --- a/pkg/yqlib/stream_evaluator.go +++ b/pkg/yqlib/stream_evaluator.go @@ -52,7 +52,7 @@ func (s *streamEvaluator) EvaluateNew(expression string, printer Printer, leadin } func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, printer Printer, leadingContentPreProcessing bool) error { - var totalProcessDocs uint = 0 + var totalProcessDocs uint node, err := s.treeCreator.ParseExpression(expression) if err != nil { return err diff --git a/pkg/yqlib/utils.go b/pkg/yqlib/utils.go index d5d53071..f8291a40 100644 --- a/pkg/yqlib/utils.go +++ b/pkg/yqlib/utils.go @@ -110,7 +110,7 @@ func processReadStream(reader *bufio.Reader) (io.Reader, string, error) { func readDocuments(reader io.Reader, filename string, fileIndex int) (*list.List, error) { decoder := yaml.NewDecoder(reader) inputList := list.New() - var currentIndex uint = 0 + var currentIndex uint for { var dataBucket yaml.Node