From c834eef28e847411e4848be7341f793ea20d8b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BIDON?= Date: Sat, 9 Aug 2025 20:10:58 +0200 Subject: [PATCH] chore(lint): updated linters, relinted code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Frédéric BIDON --- .golangci.yml | 3 +++ fmts/fixture_test.go | 31 ++++++++++++++----------------- loaders.go | 1 + options_test.go | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5006306..015e33a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,9 @@ linters: - nestif - nlreturn - nonamedreturns + - noinlineerr - paralleltest + - recvcheck - testpackage - thelper - tparallel @@ -31,6 +33,7 @@ linters: - whitespace - wrapcheck - wsl + - wsl_v5 settings: dupl: threshold: 200 diff --git a/fmts/fixture_test.go b/fmts/fixture_test.go index 6c65298..332498e 100644 --- a/fmts/fixture_test.go +++ b/fmts/fixture_test.go @@ -30,7 +30,7 @@ var extensions = []string{"json"} //nolint:unparam func assertSpecJSON(t testing.TB, specJSON []byte) bool { - var expected map[string]interface{} + var expected map[string]any require.NoError(t, json.Unmarshal(specJSON, &expected)) obj := spec.Swagger{} @@ -39,13 +39,13 @@ func assertSpecJSON(t testing.TB, specJSON []byte) bool { cb, err := json.MarshalIndent(obj, "", " ") require.NoError(t, err) - var actual map[string]interface{} + var actual map[string]any require.NoError(t, json.Unmarshal(cb, &actual)) return assertSpecMaps(t, actual, expected) } -func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool { +func assertSpecMaps(t testing.TB, actual, expected map[string]any) bool { res := true if id, ok := expected["id"]; ok { res = assert.Equal(t, id, actual["id"]) @@ -70,21 +70,21 @@ func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool } //nolint:unparam -func roundTripTest(t *testing.T, fixtureType, extension, fileName string, schema interface{}) bool { +func roundTripTest(t *testing.T, fixtureType, extension, fileName string, schema any) bool { if extension == "yaml" { return roundTripTestYAML(t, fixtureType, fileName, schema) } return roundTripTestJSON(t, fixtureType, fileName, schema) } -func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema interface{}) bool { +func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema any) bool { specName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) t.Logf("verifying %s JSON fixture %q", fixtureType, specName) b, err := os.ReadFile(fileName) require.NoError(t, err) - var expected map[string]interface{} + var expected map[string]any require.NoError(t, json.Unmarshal(b, &expected)) require.NoError(t, json.Unmarshal(b, schema)) @@ -92,20 +92,20 @@ func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema interf cb, err := json.MarshalIndent(schema, "", " ") require.NoError(t, err) - var actual map[string]interface{} + var actual map[string]any require.NoError(t, json.Unmarshal(cb, &actual)) - return assert.EqualValues(t, expected, actual) + return assert.Equal(t, expected, actual) } -func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interface{}) bool { +func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema any) bool { specName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) t.Logf("verifying %s YAML fixture %q", fixtureType, specName) b, err := YAMLDoc(fileName) require.NoError(t, err) - var expected map[string]interface{} + var expected map[string]any require.NoError(t, json.Unmarshal(b, &expected)) require.NoError(t, json.Unmarshal(b, schema)) @@ -113,10 +113,10 @@ func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interf cb, err := json.MarshalIndent(schema, "", " ") require.NoError(t, err) - var actual map[string]interface{} + var actual map[string]any require.NoError(t, json.Unmarshal(cb, &actual)) - return assert.EqualValues(t, expected, actual) + return assert.Equal(t, expected, actual) } func TestPropertyFixtures(t *testing.T) { @@ -127,9 +127,6 @@ func TestPropertyFixtures(t *testing.T) { t.Fatal(err) } - // for _, f := range files { - // roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &Schema{}) - // } f := files[0] roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &spec.Schema{}) } @@ -139,14 +136,14 @@ func TestAdditionalPropertiesWithObject(t *testing.T) { schema := new(spec.Schema) b, err := YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml") require.NoError(t, err) - var expected map[string]interface{} + var expected map[string]any require.NoError(t, json.Unmarshal(b, &expected)) require.NoError(t, json.Unmarshal(b, schema)) cb, err := json.MarshalIndent(schema, "", " ") require.NoError(t, err) - var actual map[string]interface{} + var actual map[string]any require.NoError(t, json.Unmarshal(cb, &actual)) assert.Equal(t, expected, actual) } diff --git a/loaders.go b/loaders.go index 6d73762..7c8a759 100644 --- a/loaders.go +++ b/loaders.go @@ -61,6 +61,7 @@ func NewDocLoaderWithMatch(fn DocLoader, matcher DocMatcher) DocLoaderWithMatch type loader struct { DocLoaderWithMatch + Next *loader } diff --git a/options_test.go b/options_test.go index c85c50d..9aa2e93 100644 --- a/options_test.go +++ b/options_test.go @@ -31,7 +31,7 @@ func TestOptionsWithDocLoader(t *testing.T) { trimmed, err := trimData(b) require.NoError(t, err) - assert.EqualValues(t, trimmed, document.Raw()) + assert.Equal(t, trimmed, document.Raw()) // a nil loader is a no op _, err = Spec(optionFixture, WithDocLoader(nil))