Replace megacheck with staticcheck

Fixed issues reported by staticcheck

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2019-01-09 11:08:58 -07:00
parent 9e215b6218
commit 7449e9ac53
15 changed files with 89 additions and 92 deletions

View File

@@ -84,6 +84,7 @@ func ParseFile(fp string) (map[string]interface{}, error) {
return p.mapping, nil
}
// ParseFileWithChecks is equivalent to ParseFile but runs in pedantic mode.
func ParseFileWithChecks(fp string) (map[string]interface{}, error) {
data, err := ioutil.ReadFile(fp)
if err != nil {
@@ -240,9 +241,9 @@ func (p *parser) processItem(it item, fp string) error {
if err != nil {
if e, ok := err.(*strconv.NumError); ok &&
e.Err == strconv.ErrRange {
return fmt.Errorf("Integer '%s' is out of the range.", it.val)
return fmt.Errorf("integer '%s' is out of the range", it.val)
}
return fmt.Errorf("Expected integer, but got '%s'.", it.val)
return fmt.Errorf("expected integer, but got '%s'", it.val)
}
// Process a suffix
suffix := strings.ToLower(strings.TrimSpace(it.val[lastDigit:]))
@@ -268,9 +269,9 @@ func (p *parser) processItem(it item, fp string) error {
if err != nil {
if e, ok := err.(*strconv.NumError); ok &&
e.Err == strconv.ErrRange {
return fmt.Errorf("Float '%s' is out of the range.", it.val)
return fmt.Errorf("float '%s' is out of the range", it.val)
}
return fmt.Errorf("Expected float, but got '%s'.", it.val)
return fmt.Errorf("expected float, but got '%s'", it.val)
}
setValue(it, num)
case itemBool:
@@ -280,14 +281,14 @@ func (p *parser) processItem(it item, fp string) error {
case "false", "no", "off":
setValue(it, false)
default:
return fmt.Errorf("Expected boolean value, but got '%s'.", it.val)
return fmt.Errorf("expected boolean value, but got '%s'", it.val)
}
case itemDatetime:
dt, err := time.Parse("2006-01-02T15:04:05Z", it.val)
if err != nil {
return fmt.Errorf(
"Expected Zulu formatted DateTime, but got '%s'.", it.val)
"expected Zulu formatted DateTime, but got '%s'", it.val)
}
setValue(it, dt)
case itemArrayStart:
@@ -314,7 +315,7 @@ func (p *parser) processItem(it item, fp string) error {
p.setValue(value)
}
} else {
return fmt.Errorf("Variable reference for '%s' on line %d can not be found.",
return fmt.Errorf("variable reference for '%s' on line %d can not be found",
it.val, it.line)
}
case itemInclude:
@@ -328,7 +329,7 @@ func (p *parser) processItem(it item, fp string) error {
m, err = ParseFile(filepath.Join(p.fp, it.val))
}
if err != nil {
return fmt.Errorf("Error parsing include file '%s', %v.", it.val, err)
return fmt.Errorf("error parsing include file '%s', %v", it.val, err)
}
for k, v := range m {
p.pushKey(k)
@@ -364,7 +365,7 @@ func (p *parser) lookupVariable(varReference string) (interface{}, bool) {
}
// Loop through contexts currently on the stack.
for i := len(p.ctxs) - 1; i >= 0; i -= 1 {
for i := len(p.ctxs) - 1; i >= 0; i-- {
ctx := p.ctxs[i]
// Process if it is a map context
if m, ok := ctx.(map[string]interface{}); ok {

View File

@@ -86,7 +86,7 @@ func TestMissingVariable(t *testing.T) {
if err == nil {
t.Fatalf("Expected an error for a missing variable, got none")
}
if !strings.HasPrefix(err.Error(), "Variable reference") {
if !strings.HasPrefix(err.Error(), "variable reference") {
t.Fatalf("Wanted a variable reference err, got %q\n", err)
}
}