Skip to content

feat: golangci-lint v2 設定ファイルを追加(unused / revive / gosec を有効化)#276

Open
taminororo wants to merge 2 commits into
developfrom
feat/kanba/274/golangci-lint-config
Open

feat: golangci-lint v2 設定ファイルを追加(unused / revive / gosec を有効化)#276
taminororo wants to merge 2 commits into
developfrom
feat/kanba/274/golangci-lint-config

Conversation

@taminororo
Copy link
Copy Markdown
Collaborator

@taminororo taminororo commented May 1, 2026

対応Issue

resolve #274

概要

.golangci.yml を golangci-lint v2 の schema で書き直し、unused / revive / gosec を有効化しました。CI 化は別 issue で対応します。

なぜ

設定内容

version: "2"

linters:
  default: none
  enable:
    - unused
    - revive
    - gosec
  settings:
    revive:
      severity: warning
    gosec:

run:
  timeout: 5m

設計判断:

設定 意図
default: none + 明示 enable 意図したルールのみ動作
revive.severity: warning スタイル系で CI を止めない
gosec: (空設定) 全ルール有効。除外なし(G104 (エラーの握りつぶし)含めて検出)
run.timeout: 5m 将来のスケール対応

FinanSu の .golangci.yml を起点に、SeeFT 用に gosec を追加。

ローカル実行結果(v2.11.4 / 2026-05-02)

cd api && golangci-lint run --config=../.golangci.yml ./...

検出された違反 7 件:

ファイル ルール 内容
api/lib/externals/db/db.go 70 gosec G104 c.db.Close() のエラー未処理
api/lib/externals/server/server.go 42 gosec G104 e.Start(":1234") のエラー未処理
api/lib/usecase/mail_auth_usecase.go 131 gosec G104 sessionRep.DeleteByUserID(...) のエラー未処理
api/lib/usecase/rescue_unified_usecase.go 299 gosec G704 SSRF via taint analysis
api/lib/usecase/rescue_unified_usecase.go 306 gosec G704 SSRF via taint analysis
api/lib/usecase/user_usecase.go 18 unused field burearRep is unused
api/lib/usecase/user_usecase.go 19 unused field taskRep is unused

→ いずれも 本 PR のスコープ外。個別 PR で対応。

補足: gosec の SQL injection 検出限界(実験で確定)

gosec の G201/G202(SQL 文字列連結)は *sql.DB 型の識別子を介していない呼び出しを SQL 実行関数として認識できない

パターン 検出
直接連結インライン(db.QueryContext(ctx, "..."+id) される
変数経由(同一関数内)(q := "..."+id; db.QueryContext(ctx, q) される
ラッパー関数経由(q := "..."+id; crud.UpdateDB(ctx, q) されない
メソッドチェーン直結(b.client.DB().QueryRowContext(ctx, q) されない
チェーン結果を変数化(db := b.client.DB(); db.QueryRowContext(ctx, q) される

SeeFT の repository 層は ラッパー関数経由(b.crud.UpdateDB(c, query) 等) および メソッドチェーン直結(b.client.DB().QueryRowContext(...) の両パターンを使用しているため、grep で確認した SQL 文字列連結 41 件は gosec では 0 件報告

→ SQL injection 防止策は AGENTS.md (#269) のプレースホルダ規約 + CodeRabbit (#273) + 人間レビュー に依存する方針。gosec は SSRF・弱暗号などの補完的検出として活用。

画面スクリーンショット等

設定ファイル追加のため画面なし。

テスト項目

  • .golangci.yml がリポジトリルートに配置されている
  • cd api && golangci-lint run --config=../.golangci.yml ./... で上記 7 件が検出される
  • golangci-lint config verify --config=.golangci.yml で設定が validate される

備考

本 PR のスコープ外(別タスク)

項目 対応先
CI 化(GitHub Actions ワークフロー) 別 issue 予定
G104 エラー未処理 3 件の修正 別 PR
SSRF 2 件の修正(rescue_unified_usecase.go 別 PR
未使用フィールド 2 件の修正(user_usecase.go 別 PR
SQL injection 41 件の修正 #266 で進行中

参考

Summary by CodeRabbit

リリースノート

  • Chores

    • コード品質チェック設定を新しいフォーマットに更新し、使用するリンタを絞り、実行タイムアウト等を調整しました。
  • Documentation

    • マニュアル作成〜スライド生成〜確認の運用Q&Aドキュメントを追加。作業フロー、誤り訂正・再生成手順、TODO(自動化案/運用体制)や返信テンプレート、関連リンクをまとめています。

Review Change Stack

Review Change Stack

- 既存の placeholder 設定を v2 schema に置き換え
- gosec で SSRF / 弱暗号 / エラー無視等を検出(G104 はノイズ抑制のため除外)
- gosec G201/G202 は SeeFT の変数経由 SQL 連結パターンを検出しない gosec の既知の限界あり、SQL injection 防止は AGENTS.md + CodeRabbit に依存
- CI 化は別 issue で対応予定

refs #274
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

.golangci.yml を issues ベースから golangci-lint v2 フォーマットに置換。linters.default: noneunusedrevivegosec を有効化、revive を警告化、gosec セクションを追加し、run.timeout を 5m に設定。加えて、手動スライド生成〜確認の運用 Q&A ドキュメントを新規追加。

Changes

Linter 設定更新

Layer / File(s) Summary
ヘッダ/既存設定削除
.golangci.yml
トップレベルの issues: exclude-use-default: false を削除。
linters 設定追加
.golangci.yml
linters.default: none にし、unused, revive, gosec を有効化。revivewarning に設定し、gosec セクションを追加。
ランタイム設定
.golangci.yml
run.timeout5m に設定。

マニュアル・スライドパイプライン Q&A(新規追加)

Layer / File(s) Summary
文書メタと用途記載
docs/proposals/manual-slide-pipeline-qa.md
タイトル、ステータス、最終更新日、担当者、関連 HTML 参照、用途を記載。
Q1: 作成者作業定義
docs/proposals/manual-slide-pipeline-qa.md
作成者が行う作業と不要作業を整理。
Q2: 作業順序と検証観点
docs/proposals/manual-slide-pipeline-qa.md
作成〜PM〜確認の手順と検証観点(生成物と元 Doc の一致)を定義。
Q3: 誤り対応の切り分け
docs/proposals/manual-slide-pipeline-qa.md
AI 出力ミス/元 Doc 誤り/レイアウト崩れごとの対応手段を区分。
Q4: 再生成フローと運用事項
docs/proposals/manual-slide-pipeline-qa.md
再エクスポート・再生成・再アップロード手順と執行部 MT で詰める運用項目を列挙。
Q5: 注意点(画像・フォールバック等)
docs/proposals/manual-slide-pipeline-qa.md
画像キャプション重視、AI 補完非推奨、障害時フォールバックなどをまとめる。
Q6: パイプライン位置づけと禁止事項
docs/proposals/manual-slide-pipeline-qa.md
パイプラインを情報圧縮タスクと説明し、禁止区域を明文化。
Q7: 今週 MT 出席可否
docs/proposals/manual-slide-pipeline-qa.md
PM の当該週の出席可否を記載。
自動化フロー TODO
docs/proposals/manual-slide-pipeline-qa.md
現状手動工程、検討案(A〜D)、Phase1〜3 の TODO を列挙。
ベトナム期間中の運用 TODO
docs/proposals/manual-slide-pipeline-qa.md
運用体制、共有アカウント/キー方針、フォールバック手順等をまとめる。
Slack テンプレと関連ドキュメント
docs/proposals/manual-slide-pipeline-qa.md
Slack 返信テンプレートと関連資料へのリンク一覧を追加。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 新しい朝に跳ねるよ、設定整えて
ゴーセックが見張り、Revive はささやく
ドキュメントは丁寧に並べておくよ
手順は明日へ続く橋となり
みんなで安全なスライド届けよう 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning raw_summary に docs/proposals/manual-slide-pipeline-qa.md が含まれているが、この文書追加は #274 の golangci-lint 設定とは無関係である。 docs/proposals/manual-slide-pipeline-qa.md を別 PR に分離するか、変更対象外として除外し、.golangci.yml の設定追加に特化した PR に統一してください。
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは .golangci.yml の v2 設定追加と有効化するリンターを明確に記述しており、主要な変更内容を適切に要約している。
Description check ✅ Passed PR 説明は対応Issue、概要、設定内容、設計判断、ローカル実行結果、テスト項目を含む充実した内容である。テンプレートの必須セクションが完成度高く埋められている。
Linked Issues check ✅ Passed PR は #274 の全主要要件を満たしている:.golangci.yml を追加、unused/revive/gosec を有効化、ローカル実行で違反検出、既存違反を別タスクとして分離、テスト項目を定義。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/kanba/274/golangci-lint-config

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@uchida189
Copy link
Copy Markdown
Contributor

コマンド実行したら4つしか違反が検出されなかったけど大丈夫そうかな?
コマンド自体は実行できました!

api/lib/usecase/rescue_unified_usecase.go:299:29: G704: SSRF via taint analysis (gosec)
        req, err := http.NewRequest("POST", gasURL, bytes.NewBuffer(jsonData))
                                   ^
api/lib/usecase/rescue_unified_usecase.go:306:24: G704: SSRF via taint analysis (gosec)
        resp, err := client.Do(req)
                              ^
api/lib/usecase/user_usecase.go:18:2: field burearRep is unused (unused)
        burearRep  rep.BureauRepository
        ^
api/lib/usecase/user_usecase.go:19:2: field taskRep is unused (unused)
        taskRep    rep.TaskRepository
        ^
4 issues:
* gosec: 2
* unused: 2

@taminororo
Copy link
Copy Markdown
Collaborator Author

0c41c75
このコミットでerrの握りつぶしもリンターに検知してもらおうと設定を変える前はその4件だったので問題ないです!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/proposals/manual-slide-pipeline-qa.md (1)

208-209: ⚡ Quick win

OAuthトークン埋め込みを選択肢として残さないでください。

Line 208 は「トークン埋め込み」を許容する読まれ方になるため、秘密情報管理の観点で危険です。埋め込み禁止(Secret Manager / CI Secrets / OS keychain を使用) を明記しておくのがよいです。

修正例
-- [ ] 認証の持ち方(PM 個人サブスク → スクリプトに OAuth トークン埋め込み?)
+- [ ] 認証の持ち方(トークンのコード埋め込みは禁止。Secret Manager / CI Secrets / OS keychain のいずれかで管理)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/proposals/manual-slide-pipeline-qa.md` around lines 208 - 209,
行の「認証の持ち方(PM 個人サブスク → スクリプトに OAuth
トークン埋め込み?)」という文がトークン埋め込みを許容して読めるため、該当箇所を編集して「埋め込み禁止」を明記し、代替として Secret Manager /
CI Secrets / OS keychain
などの安全な秘密管理手段を必ず使うよう指示するように修正してください(該当テキストを「埋め込み禁止(Secret Manager / CI Secrets /
OS keychain を使用)」のように置き換える)。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/proposals/manual-slide-pipeline-qa.md`:
- Around line 39-55: The fenced code block in
docs/proposals/manual-slide-pipeline-qa.md (the block starting with ```) is
missing a language spec causing markdownlint MD040; fix it by adding a language
identifier (e.g., text) after the opening backticks so the block becomes ```text
— update the single fenced block that contains the flow diagram to include the
language spec and save the file.
- Around line 247-253: Replace the policy section titled "**メインバックエンド: 上林の
Claude Max プランを新 PM と共用**" (the bullets currently suggesting sharing an
individual Claude Max account) with a non-sharing policy: remove any instruction
that a new PM should log into 上林’s personal account and explicitly state that
personal account sharing is prohibited per Anthropic Consumer Terms of Service;
instead prescribe organization-managed authentication (e.g., organization API
keys, service accounts, or provisioned org credentials) as the default, keep the
note to re-evaluate post-Vietnam but only with an org-managed migration option,
and update the bullets and any examples to reference the new auth methods rather
than `claude login` into a personal account.

---

Nitpick comments:
In `@docs/proposals/manual-slide-pipeline-qa.md`:
- Around line 208-209: 行の「認証の持ち方(PM 個人サブスク → スクリプトに OAuth
トークン埋め込み?)」という文がトークン埋め込みを許容して読めるため、該当箇所を編集して「埋め込み禁止」を明記し、代替として Secret Manager /
CI Secrets / OS keychain
などの安全な秘密管理手段を必ず使うよう指示するように修正してください(該当テキストを「埋め込み禁止(Secret Manager / CI Secrets /
OS keychain を使用)」のように置き換える)。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 59c3d8e8-ea8b-412d-9e45-e23ede96c8de

📥 Commits

Reviewing files that changed from the base of the PR and between c7375a4 and 91c0df9.

📒 Files selected for processing (1)
  • docs/proposals/manual-slide-pipeline-qa.md

Comment on lines +39 to +55
```
[マニュアル作成者]
↓ Google Doc 編集
↓ 完了 or 更新したら PM に通知

[PM(上林、引き継ぎ後は新PM)]
↓ Doc を HTML エクスポート(Google Docs の「ダウンロード → Web ページ」)
↓ ローカルで生成ツール実行(コマンド1回、3〜6 分)
↓ 生成された Web ページを SeeFT の配信先にデプロイ
↓ SeeFT シフトページのリンクを更新(Doc URL → Web ページ URL)

[マニュアル確認担当者]
↓ 元 Doc と生成 Web ページを照合
↓ OK → 完了 / NG → PM に修正依頼

[技大祭当日も同じフロー: Doc 変更 → PM 再生成 → URL は同じまま中身だけ更新]
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

コードフェンスに言語指定を追加してください(MD040)。

Line 39 の fenced code block に言語が未指定です。markdownlint 警告の解消のため、text などを明示してください。

修正例
-```
+```text
 [マニュアル作成者]
    ↓ Google Doc 編集
    ↓ 完了 or 更新したら PM に通知
 ...
 [技大祭当日も同じフロー: Doc 変更 → PM 再生成 → URL は同じまま中身だけ更新]
-```
+```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
[マニュアル作成者]
↓ Google Doc 編集
↓ 完了 or 更新したら PM に通知
[PM(上林、引き継ぎ後は新PM)]
↓ Doc を HTML エクスポート(Google Docs の「ダウンロード → Web ページ」)
↓ ローカルで生成ツール実行(コマンド1回、3〜6 分)
↓ 生成された Web ページを SeeFT の配信先にデプロイ
↓ SeeFT シフトページのリンクを更新(Doc URL → Web ページ URL)
[マニュアル確認担当者]
↓ 元 Doc と生成 Web ページを照合
↓ OK → 完了 / NG → PM に修正依頼
[技大祭当日も同じフロー: Doc 変更 → PM 再生成 → URL は同じまま中身だけ更新]
```
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 39-39: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/proposals/manual-slide-pipeline-qa.md` around lines 39 - 55, The fenced
code block in docs/proposals/manual-slide-pipeline-qa.md (the block starting
with ```) is missing a language spec causing markdownlint MD040; fix it by
adding a language identifier (e.g., text) after the opening backticks so the
block becomes ```text — update the single fenced block that contains the flow
diagram to include the language spec and save the file.

Comment on lines +247 to +253
**メインバックエンド: 上林の Claude Max プランを新 PM と共用**

- 上林の既存 Max プラン契約の容量を新 PM が利用する
- 追加コストゼロ(既に上林が支払い中)
- 新 PM の Mac に 1 度だけ `claude login` → OAuth トークンが保存される → 以降は新 PM が普通にコマンドを叩くだけ
- ベトナム滞在中の上林はほぼ Claude を使わない → 実質単一ユーザーパターンになり、TOS リスクは実用上ほぼゼロ
- ベトナム終了後(10月以降)に方針を再決定(新 PM 個人契約に移行 or 共用継続)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🌐 Web query:

Anthropic Claude Max の最新利用規約で、個人アカウントの共有利用(別ユーザーが別端末で使用)は許可されていますか?公式ToS/Usage Policyの該当条項を提示してください。

💡 Result:

いいえ、Anthropic Claude Maxの最新利用規約(Consumer Terms of Service)では、個人アカウントの共有利用(別ユーザーが別端末で使用)は許可されていません。[1][2]

Citations:


個人アカウント共用は Claude Max の利用規約で明確に禁止されています。

Line 247-253 の方針は Anthropic の公式利用規約(Consumer Terms of Service)に違反します。同規約では、別ユーザーが別端末で個人アカウントを使用することは許可されていません。

上林の既存 Max プラン契約を新 PM と共用する運用は、利用規約違反および責任分界の不明確化につながるため、運用ドキュメント上は「個人契約の共用を前提にしない」方針へ修正が必須です。組織管理可能な認証方式(組織 API キー・サービス用認証)を主系に置くことで、規約リスクと監査トレーサビリティを同時に解決できます。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/proposals/manual-slide-pipeline-qa.md` around lines 247 - 253, Replace
the policy section titled "**メインバックエンド: 上林の Claude Max プランを新 PM と共用**" (the
bullets currently suggesting sharing an individual Claude Max account) with a
non-sharing policy: remove any instruction that a new PM should log into 上林’s
personal account and explicitly state that personal account sharing is
prohibited per Anthropic Consumer Terms of Service; instead prescribe
organization-managed authentication (e.g., organization API keys, service
accounts, or provisioned org credentials) as the default, keep the note to
re-evaluate post-Vietnam but only with an org-managed migration option, and
update the bullets and any examples to reference the new auth methods rather
than `claude login` into a personal account.

@taminororo taminororo force-pushed the feat/kanba/274/golangci-lint-config branch from 91c0df9 to c7375a4 Compare May 13, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golangci-lint 設定ファイル追加(gosec で SQLi 検出可能に)

2 participants