From 17043521ac7182456930daa2e9dd775155b711be Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Sun, 3 May 2026 20:49:23 +0200 Subject: fix new lints in golangci-lint 2.12.1 --- jsonmatch/machinery.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'jsonmatch/machinery.go') diff --git a/jsonmatch/machinery.go b/jsonmatch/machinery.go index ae0c254..f3f5348 100644 --- a/jsonmatch/machinery.go +++ b/jsonmatch/machinery.go @@ -120,6 +120,11 @@ func keyIntoPointerFragment(key string) string { return s } +const ( + kindValueMismatch = "value mismatch" + kindTypeMismatch = "type mismatch" +) + // NOTE: getDiffsForValue is the main part of the recursion to generate the diff. func getDiffsForValue(path []pathElement, expected, actual any) []Diff { // specialized handling for relevant recursible or capturable types @@ -155,7 +160,7 @@ func getDiffsForValue(path []pathElement, expected, actual any) []Diff { return nil } else { return []Diff{{ - Kind: "type mismatch", + Kind: kindTypeMismatch, Pointer: pathIntoPointer(path), ExpectedJSON: "null", ActualJSON: marshalActualForDiff(actual), @@ -205,7 +210,7 @@ func getDiffsForObject(path []pathElement, expected map[string]any, actual any) return getDiffsForConfirmedObject(path, expected, actual) } return []Diff{{ - Kind: "type mismatch", + Kind: kindTypeMismatch, Pointer: pathIntoPointer(path), ExpectedJSON: marshalExpectedForDiff(expected), ActualJSON: marshalActualForDiff(actual), @@ -221,7 +226,7 @@ func getDiffsForConfirmedObject(path []pathElement, expected, actual map[string] diffs = append(diffs, getDiffsForValue(subpath, expectedValue, actual[key])...) } else { diffs = append(diffs, Diff{ - Kind: "value mismatch", + Kind: kindValueMismatch, Pointer: pathIntoPointer(subpath), ExpectedJSON: "", ActualJSON: marshalActualForDiff(actual[key]), @@ -233,7 +238,7 @@ func getDiffsForConfirmedObject(path []pathElement, expected, actual map[string] if !exists { subpath := append(path, keyElement(key)) diffs = append(diffs, Diff{ - Kind: "value mismatch", + Kind: kindValueMismatch, Pointer: pathIntoPointer(subpath), ExpectedJSON: marshalExpectedForDiff(expected[key]), ActualJSON: "", @@ -249,7 +254,7 @@ func getDiffsForArray(path []pathElement, expected []any, actual any) []Diff { return getDiffsForConfirmedArray(path, expected, actual) } return []Diff{{ - Kind: "type mismatch", + Kind: kindTypeMismatch, Pointer: pathIntoPointer(path), ExpectedJSON: marshalExpectedForDiff(expected), ActualJSON: marshalActualForDiff(actual), @@ -263,14 +268,14 @@ func getDiffsForConfirmedArray(path []pathElement, expected, actual []any) (diff switch { case idx >= len(actual): diffs = append(diffs, Diff{ - Kind: "value mismatch", + Kind: kindValueMismatch, Pointer: pathIntoPointer(subpath), ActualJSON: "", ExpectedJSON: marshalExpectedForDiff(expected[idx]), }) case idx >= len(expected): diffs = append(diffs, Diff{ - Kind: "value mismatch", + Kind: kindValueMismatch, Pointer: pathIntoPointer(subpath), ActualJSON: marshalActualForDiff(actual[idx]), ExpectedJSON: "", -- cgit v1.2.3