Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
teejaded committed Mar 15, 2023
1 parent b499322 commit 0cc181e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/yqlib/doc/operators/divide.md
Expand Up @@ -19,7 +19,7 @@ c:
```

## Number division
The result during divison is calculated as a float
The result during division is calculated as a float

Given a sample.yml file of:
```yaml
Expand Down
10 changes: 2 additions & 8 deletions pkg/yqlib/operator_divide.go
Expand Up @@ -8,12 +8,6 @@ import (
yaml "gopkg.in/yaml.v3"
)

func createDivideOp(lhs *ExpressionNode, rhs *ExpressionNode) *ExpressionNode {
return &ExpressionNode{Operation: &Operation{OperationType: divideOpType},
LHS: lhs,
RHS: rhs}
}

func divideOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("Divide operator")

Expand All @@ -33,7 +27,7 @@ func divide(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Cand
target := &yaml.Node{}

if lhsNode.Kind == yaml.ScalarNode && rhs.Node.Kind == yaml.ScalarNode {
if err := divideScalars(context, target, lhsNode, rhs.Node); err != nil {
if err := divideScalars(target, lhsNode, rhs.Node); err != nil {
return nil, err
}
} else {
Expand All @@ -43,7 +37,7 @@ func divide(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Cand
return lhs.CreateReplacement(target), nil
}

func divideScalars(context Context, target *yaml.Node, lhs *yaml.Node, rhs *yaml.Node) error {
func divideScalars(target *yaml.Node, lhs *yaml.Node, rhs *yaml.Node) error {
lhsTag := lhs.Tag
rhsTag := guessTagFromCustomType(rhs)
lhsIsCustom := false
Expand Down
2 changes: 1 addition & 1 deletion pkg/yqlib/operator_divide_test.go
Expand Up @@ -32,7 +32,7 @@ var divideOperatorScenarios = []expressionScenario{
},
{
description: "Number division",
subdescription: "The result during divison is calculated as a float",
subdescription: "The result during division is calculated as a float",
document: `{a: 12, b: 2.5}`,
expression: `.a = .a / .b`,
expected: []string{
Expand Down
1 change: 0 additions & 1 deletion pkg/yqlib/operator_filter.go
Expand Up @@ -30,4 +30,3 @@ func filterOperator(d *dataTreeNavigator, context Context, expressionNode *Expre
}
return context.ChildContext(results), nil
}

14 changes: 7 additions & 7 deletions pkg/yqlib/operator_filter_test.go
Expand Up @@ -7,22 +7,22 @@ import (
var filterOperatorScenarios = []expressionScenario{
{
description: "Filter array",
document: `[1,2,3]`,
expression: `filter(. < 3)`,
document: `[1,2,3]`,
expression: `filter(. < 3)`,
expected: []string{
"D0, P[], (!!seq)::[1, 2]\n",
},
},
{
skipDoc: true,
document: `[1,2,3]`,
expression: `filter(. > 1)`,
skipDoc: true,
document: `[1,2,3]`,
expression: `filter(. > 1)`,
expected: []string{
"D0, P[], (!!seq)::[2, 3]\n",
},
},
{
skipDoc: true,
skipDoc: true,
description: "Filter array to empty",
document: `[1,2,3]`,
expression: `filter(. > 4)`,
Expand All @@ -31,7 +31,7 @@ var filterOperatorScenarios = []expressionScenario{
},
},
{
skipDoc: true,
skipDoc: true,
description: "Filter empty array",
document: `[]`,
expression: `filter(. > 1)`,
Expand Down
10 changes: 2 additions & 8 deletions pkg/yqlib/operator_modulo.go
Expand Up @@ -9,12 +9,6 @@ import (
yaml "gopkg.in/yaml.v3"
)

func createModuloOp(lhs *ExpressionNode, rhs *ExpressionNode) *ExpressionNode {
return &ExpressionNode{Operation: &Operation{OperationType: moduloOpType},
LHS: lhs,
RHS: rhs}
}

func moduloOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("Modulo operator")

Expand All @@ -34,7 +28,7 @@ func modulo(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Cand
target := &yaml.Node{}

if lhsNode.Kind == yaml.ScalarNode && rhs.Node.Kind == yaml.ScalarNode {
if err := moduloScalars(context, target, lhsNode, rhs.Node); err != nil {
if err := moduloScalars(target, lhsNode, rhs.Node); err != nil {
return nil, err
}
} else {
Expand All @@ -44,7 +38,7 @@ func modulo(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *Cand
return lhs.CreateReplacement(target), nil
}

func moduloScalars(context Context, target *yaml.Node, lhs *yaml.Node, rhs *yaml.Node) error {
func moduloScalars(target *yaml.Node, lhs *yaml.Node, rhs *yaml.Node) error {
lhsTag := lhs.Tag
rhsTag := guessTagFromCustomType(rhs)
lhsIsCustom := false
Expand Down

0 comments on commit 0cc181e

Please sign in to comment.