ci(golangci-lint): update configuration and fix lint issues (#4247)

* ci: update golangci-lint configuration and lint settings

- Update golangci-lint to version 2
- Enable new linters and adjust existing ones
- Update lint settings across multiple test files
- Remove unused struct and variable checks
- Add new lint exclusions for generated code and specific directories

Signed-off-by: Flc <four_leaf_clover@foxmail.com>

* ci(github): update golangci-lint-action to v8 and lint version to v2.3.4

Signed-off-by: Flc <four_leaf_clover@foxmail.com>

* ci: downgrade golangci-lint to v2.1.6

Signed-off-by: Flc <four_leaf_clover@foxmail.com>

* ci(golangci): add gofumpt linter and fix related issues- Added gofumpt linter to .golangci.yml

Signed-off-by: Flc <four_leaf_clover@foxmail.com>

* test: ignore testifylint and gofumpt lints in specific test cases

Signed-off-by: Flc <four_leaf_clover@foxmail.com>

* build(deps): remove golang.org/x/lint

- Remove golang.org/x/lint package from go.mod
- Update related dependencies in go.sum

Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>

* build(deps): downgrade golang.org/x/mod and golang.org/x/tools

- Downgrade golang.org/x/mod from v0.24.0 to v0.18.0
- Downgrade golang.org/x/tools from v0.33.0 to v.22.0

These changes are made to address compatibility issues with the current project setup.

Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>

---------

Signed-off-by: Flc <four_leaf_clover@foxmail.com>
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
This commit is contained in:
Flc゛
2025-05-23 14:46:48 +08:00
committed by GitHub
parent 8fb3136664
commit c4287b1300
27 changed files with 164 additions and 149 deletions
+19 -19
View File
@@ -918,7 +918,7 @@ func TestContextRenderJSON(t *testing.T) {
c.JSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
assert.JSONEq(t, "{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}
@@ -946,7 +946,7 @@ func TestContextRenderJSONPWithoutCallback(t *testing.T) {
c.JSONP(http.StatusCreated, H{"foo": "bar"})
assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.JSONEq(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}
@@ -972,7 +972,7 @@ func TestContextRenderAPIJSON(t *testing.T) {
c.JSON(http.StatusCreated, H{"foo": "bar"})
assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.JSONEq(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.Equal(t, "application/vnd.api+json", w.Header().Get("Content-Type"))
}
@@ -998,7 +998,7 @@ func TestContextRenderIndentedJSON(t *testing.T) {
c.IndentedJSON(http.StatusCreated, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})
assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}", w.Body.String())
assert.JSONEq(t, "{\n \"bar\": \"foo\",\n \"foo\": \"bar\",\n \"nested\": {\n \"foo\": \"bar\"\n }\n}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}
@@ -1059,7 +1059,7 @@ func TestContextRenderPureJSON(t *testing.T) {
c, _ := CreateTestContext(w)
c.PureJSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})
assert.Equal(t, http.StatusCreated, w.Code)
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())
assert.JSONEq(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}
@@ -1233,7 +1233,7 @@ func TestContextRenderSSE(t *testing.T) {
"bar": "foo",
})
assert.Equal(t, strings.Replace(w.Body.String(), " ", "", -1), strings.Replace("event:float\ndata:1.5\n\nid:123\ndata:text\n\nevent:chat\ndata:{\"bar\":\"foo\",\"foo\":\"bar\"}\n\n", " ", "", -1))
assert.Equal(t, strings.ReplaceAll(w.Body.String(), " ", ""), strings.ReplaceAll("event:float\ndata:1.5\n\nid:123\ndata:text\n\nevent:chat\ndata:{\"bar\":\"foo\",\"foo\":\"bar\"}\n\n", " ", ""))
}
func TestContextRenderFile(t *testing.T) {
@@ -1247,7 +1247,7 @@ func TestContextRenderFile(t *testing.T) {
assert.Contains(t, w.Body.String(), "func New(opts ...OptionFunc) *Engine {")
// Content-Type='text/plain; charset=utf-8' when go version <= 1.16,
// else, Content-Type='text/x-go; charset=utf-8'
assert.NotEqual(t, "", w.Header().Get("Content-Type"))
assert.NotEmpty(t, w.Header().Get("Content-Type"))
}
func TestContextRenderFileFromFS(t *testing.T) {
@@ -1261,7 +1261,7 @@ func TestContextRenderFileFromFS(t *testing.T) {
assert.Contains(t, w.Body.String(), "func New(opts ...OptionFunc) *Engine {")
// Content-Type='text/plain; charset=utf-8' when go version <= 1.16,
// else, Content-Type='text/x-go; charset=utf-8'
assert.NotEqual(t, "", w.Header().Get("Content-Type"))
assert.NotEmpty(t, w.Header().Get("Content-Type"))
assert.Equal(t, "/some/path", c.Request.URL.Path)
}
@@ -1432,7 +1432,7 @@ func TestContextNegotiationWithJSON(t *testing.T) {
})
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.JSONEq(t, "{\"foo\":\"bar\"}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
}
@@ -1518,7 +1518,7 @@ func TestContextNegotiationFormat(t *testing.T) {
c.Request, _ = http.NewRequest(http.MethodPost, "", nil)
assert.Panics(t, func() { c.NegotiateFormat() })
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML)) //nolint:testifylint
assert.Equal(t, MIMEHTML, c.NegotiateFormat(MIMEHTML, MIMEJSON))
}
@@ -1540,7 +1540,7 @@ func TestContextNegotiationFormatWithWildcardAccept(t *testing.T) {
assert.Equal(t, "*/*", c.NegotiateFormat("*/*"))
assert.Equal(t, "text/*", c.NegotiateFormat("text/*"))
assert.Equal(t, "application/*", c.NegotiateFormat("application/*"))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON)) //nolint:testifylint
assert.Equal(t, MIMEXML, c.NegotiateFormat(MIMEXML))
assert.Equal(t, MIMEHTML, c.NegotiateFormat(MIMEHTML))
@@ -1550,9 +1550,9 @@ func TestContextNegotiationFormatWithWildcardAccept(t *testing.T) {
assert.Equal(t, "*/*", c.NegotiateFormat("*/*"))
assert.Equal(t, "text/*", c.NegotiateFormat("text/*"))
assert.Equal(t, "", c.NegotiateFormat("application/*"))
assert.Equal(t, "", c.NegotiateFormat(MIMEJSON))
assert.Equal(t, "", c.NegotiateFormat(MIMEXML))
assert.Empty(t, c.NegotiateFormat("application/*"))
assert.Empty(t, c.NegotiateFormat(MIMEJSON))
assert.Empty(t, c.NegotiateFormat(MIMEXML))
assert.Equal(t, MIMEHTML, c.NegotiateFormat(MIMEHTML))
}
@@ -1564,9 +1564,9 @@ func TestContextNegotiationFormatCustom(t *testing.T) {
c.Accepted = nil
c.SetAccepted(MIMEJSON, MIMEXML)
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON, MIMEXML)) //nolint:testifylint
assert.Equal(t, MIMEXML, c.NegotiateFormat(MIMEXML, MIMEHTML))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON))
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON)) //nolint:testifylint
}
func TestContextNegotiationFormat2(t *testing.T) {
@@ -1574,7 +1574,7 @@ func TestContextNegotiationFormat2(t *testing.T) {
c.Request, _ = http.NewRequest(http.MethodPost, "/", nil)
c.Request.Header.Add("Accept", "image/tiff-fx")
assert.Equal(t, "", c.NegotiateFormat("image/tiff"))
assert.Empty(t, c.NegotiateFormat("image/tiff"))
}
func TestContextIsAborted(t *testing.T) {
@@ -1634,7 +1634,7 @@ func TestContextAbortWithStatusJSON(t *testing.T) {
_, err := buf.ReadFrom(w.Body)
require.NoError(t, err)
jsonStringBody := buf.String()
assert.Equal(t, "{\"foo\":\"fooValue\",\"bar\":\"barValue\"}", jsonStringBody)
assert.JSONEq(t, "{\"foo\":\"fooValue\",\"bar\":\"barValue\"}", jsonStringBody)
}
func TestContextError(t *testing.T) {
@@ -3076,7 +3076,7 @@ func TestInterceptedHeader(t *testing.T) {
// Compared to this time, this is when the response headers will be flushed
// As response is flushed on c.String, the Header cannot be set by the first
// middleware. Assert this
assert.Equal(t, "", w.Result().Header.Get("X-Test"))
assert.Empty(t, w.Result().Header.Get("X-Test"))
assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))
}