Skip to content

Commit

Permalink
chore: add golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Chodur <[email protected]>
  • Loading branch information
FUSAKLA committed Feb 9, 2022
1 parent 8a46296 commit c8b6b52
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
with:
go-version: 1.17

- name: Golangci-lint
uses: golangci/[email protected]

- name: Build
run: make build

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ $(RELEASE_NOTES): $(TMP_DIR)
@mv $(TMP_DIR)/release-notes-part1 $(RELEASE_NOTES)
@rm $(TMP_DIR)/release-notes-part*

lint:
golangci-lint run

test:
go test -race ./...

Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ func main() {
if err != nil {
exitWithError(err)
}
for _, p := range paths {
filesToBeValidated = append(filesToBeValidated, p)
}
filesToBeValidated = append(filesToBeValidated, paths...)
}

validationConfig, err := loadConfigFile(*validateConfigFile)
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ValidationDocs(validationRules []ValidationRule, format string) (string, er
})
}

templateToUse := textTemplate
var templateToUse string
switch format {
case "text":
templateToUse = textTemplate
Expand Down
4 changes: 1 addition & 3 deletions pkg/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ func Files(fileNames []string, validationRules []*ValidationRule, excludeAnnotat
}
}
for _, v := range validationRule.validators {
for _, err := range v.Validate(rule) {
ruleReport.Errors = append(ruleReport.Errors, err)
}
ruleReport.Errors = append(ruleReport.Errors, v.Validate(rule)...)
}
if len(ruleReport.Errors) > 0 {
validationReport.Failed = true
Expand Down
1 change: 0 additions & 1 deletion pkg/validator/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func newAnnotationIsValidPromQL(paramsConfig yaml.Node) (Validator, error) {

type annotationIsValidPromQL struct {
annotation string
resolveURL bool
}

func (h annotationIsValidPromQL) String() string {
Expand Down
12 changes: 3 additions & 9 deletions pkg/validator/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,15 @@ func getExpressionUsedLabels(expr string) ([]string, error) {
parser.Inspect(promQl, func(n parser.Node, ns []parser.Node) error {
switch v := n.(type) {
case *parser.AggregateExpr:
for _, m := range v.Grouping {
usedLabels = append(usedLabels, m)
}
usedLabels = append(usedLabels, v.Grouping...)
case *parser.VectorSelector:
for _, m := range v.LabelMatchers {
usedLabels = append(usedLabels, m.Name)
}
case *parser.BinaryExpr:
if v.VectorMatching != nil {
for _, m := range v.VectorMatching.Include {
usedLabels = append(usedLabels, m)
}
for _, m := range v.VectorMatching.MatchingLabels {
usedLabels = append(usedLabels, m)
}
usedLabels = append(usedLabels, v.VectorMatching.Include...)
usedLabels = append(usedLabels, v.VectorMatching.MatchingLabels...)
}
}
return nil
Expand Down

0 comments on commit c8b6b52

Please sign in to comment.