Skip to content

Commit

Permalink
golangci-lint の設定 (#14)
Browse files Browse the repository at this point in the history
* golangci-lint の設定

* lint
  • Loading branch information
pirosiki197 authored Dec 30, 2024
1 parent eaf07f3 commit 9be9b08
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ jobs:
go-version-file: go.mod
- run: go build -o out/server ./cmd/server

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v6
with:
version: v1.62

test:
name: Test
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters:
enable:
- gofmt
- revive

issues:
exclude-dirs:
- server/handler/openapi
- ".*/mock$"
10 changes: 5 additions & 5 deletions server/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func Login(t *testing.T, server *httptest.Server, client *http.Client, userID st
t.Helper()

// not following redirect for the first request
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
client.CheckRedirect = func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
}

Expand Down Expand Up @@ -254,12 +254,12 @@ func (s *oauth2MockServer) handleToken(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(res)
_ = json.NewEncoder(w).Encode(res)
}

func (s *oauth2MockServer) handleWellKnown(w http.ResponseWriter, r *http.Request) {
func (s *oauth2MockServer) handleWellKnown(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
_ = json.NewEncoder(w).Encode(map[string]any{
"issuer": s.rootURL,
"authorization_endpoint": s.rootURL + "/authorize",
"token_endpoint": s.rootURL + "/token",
Expand All @@ -269,7 +269,7 @@ func (s *oauth2MockServer) handleWellKnown(w http.ResponseWriter, r *http.Reques

func (s *oauth2MockServer) handleJWKS(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
_ = json.NewEncoder(w).Encode(map[string]any{
"keys": []map[string]any{
{
"kty": "RSA",
Expand Down
2 changes: 1 addition & 1 deletion server/handler/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAuthMiddleware(t *testing.T) {

req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
needAuthorize(echo.New().NewContext(req, rec))
_ = needAuthorize(echo.New().NewContext(req, rec))
if rec.Code != tt.expectStatus {
t.Errorf("unexpected status code: expected=%d, got=%d", tt.expectStatus, rec.Code)
}
Expand Down
2 changes: 1 addition & 1 deletion server/handler/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestLogout(t *testing.T) {
// logout
// return not expired session
mockRepo.EXPECT().FindSession(gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, sid string) (domain.Session, error) {
DoAndReturn(func(_ context.Context, sid string) (domain.Session, error) {
return domain.Session{
ID: sid,
UserID: userID,
Expand Down
2 changes: 1 addition & 1 deletion server/repository/db/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *Repository) Transaction(ctx context.Context, f func(ctx context.Context
if err != nil {
return err
}
defer tx.Rollback()
defer tx.Rollback() //nolint errcheck

txRepo := newTxRepository(tx)

Expand Down

0 comments on commit 9be9b08

Please sign in to comment.