# reviewdog — Turn Lint Into PR Review Comments > reviewdog reads any linter output and posts precise PR comments or Checks, so teams can enforce quality without noisy, copy-pasted logs in reviews. ## Install Copy the content below into your project: ## Quick Use 1. Install (Homebrew or Go): ```bash brew install reviewdog/tap/reviewdog # or go install github.com/reviewdog/reviewdog/cmd/reviewdog@latest ``` 2. Local smoke test (no PR needed): ```bash echo "README.md:1:1: demo message" | reviewdog -f=golint -reporter=local ``` 3. In CI, report to GitHub PR review: ```bash # Needs GITHUB_TOKEN + a PR context reviewdog -f=golint -reporter=github-pr-review -filter-mode=diff_context ``` ## Intro reviewdog reads any linter output and posts precise PR comments or Checks, so teams can enforce quality without noisy, copy-pasted logs in reviews. - **Best for:** repos that have multiple linters and want consistent, diff-scoped PR feedback - **Works with:** GitHub/GitLab CI, any linter output (checkstyle/eslint/golangci-lint, etc.) - **Setup time:** 10–20 minutes ## Practical Notes - Quant gate: make CI fail when new issues appear (diff-only mode). - Tip: start with `-reporter=local` before wiring PR credentials. ## Pattern: “diff-only” quality gate When a repo has a backlog of existing issues, the fastest rollout is **only comment on new problems introduced by the PR**. 1) Pick one linter and ensure it prints file/line/col. 2) Pipe to reviewdog with diff filtering: ```bash | reviewdog -f=golint -reporter=github-pr-review -filter-mode=diff_context ``` 3) Tighten gradually: - Start as `github-pr-review` (developer-friendly), - then switch to `github-check` (status checks) if you want a strict merge gate. ## Pattern: unify many linters into one “review surface” If your CI runs multiple tools (format, security, deps, etc.), keep the PR readable: - Use a consistent reporter (Checks or Review), - use consistent severity mapping, - keep messages short and actionable (first sentence: what to change). ## Troubleshooting - If nothing posts: validate you’re running in a PR context and tokens are present. - If comments are too noisy: use diff filtering, or limit to changed paths only. ### FAQ **Q: Do I have to use GitHub Actions?** A: No. reviewdog can run in many CI systems; the key is having a PR diff context when you want PR comments. **Q: Can I run it locally?** A: Yes. Use `-reporter=local` to validate parsing and formatting before wiring CI credentials. **Q: How do I avoid commenting on old issues?** A: Use diff filtering (`-filter-mode=diff_context`) so only new issues are surfaced. ## Source & Thanks > Source: https://github.com/reviewdog/reviewdog > License: MIT > GitHub stars: 9,286 · forks: 485 --- ## 快速使用 1. 安装(Homebrew 或 Go): ```bash brew install reviewdog/tap/reviewdog # 或 go install github.com/reviewdog/reviewdog/cmd/reviewdog@latest ``` 2. 本地先跑通(不依赖 PR): ```bash echo "README.md:1:1: demo message" | reviewdog -f=golint -reporter=local ``` 3. 在 CI 里发到 GitHub PR Review: ```bash # 需要 GITHUB_TOKEN 且在 PR 上下文中运行 reviewdog -f=golint -reporter=github-pr-review -filter-mode=diff_context ``` ## 简介 reviewdog 可以读取任意 Lint/静态分析输出,并把问题精确贴到 PR diff 上(Review 评论或 Checks);让质量门槛自动化落地,不再靠复制粘贴日志,并方便多仓库统一规则。 - **适合谁:** 同时跑多个 linter、希望把反馈“只对本次改动生效”的代码仓库 - **可搭配:** GitHub/GitLab CI;支持多种 linter 输出格式(checkstyle/eslint/golangci-lint 等) - **准备时间:** 10–20 分钟 ## 实战建议 - 量化门槛:只对本次 diff 新增问题失败(diff-only 反馈)。 - 建议:先用 `-reporter=local` 跑通,再接入 PR 权限与 Token。 ## 常用打法:先做“只看 diff 新增问题” 当仓库历史遗留问题很多时,最快的上线方式是:**只对 PR 引入的新问题发评论**,避免“一上来就刷屏”。 1)先选一个 linter,确保输出里有 file/line/col。 2)用 reviewdog 做 diff 过滤: ```bash <你的_linter_命令> | reviewdog -f=golint -reporter=github-pr-review -filter-mode=diff_context ``` 3)逐步收紧: - 先用 `github-pr-review`(体验更友好), - 需要强制合并门槛时再切到 `github-check`(更像 gate)。 ## 常用打法:把多个 linter 统一到一个“review 面板” CI 同时跑格式化、安全、依赖等工具时,关键是让 PR 结果可读: - reporter 统一(Checks 或 Review 选一个), - 严重级别映射统一, - 每条消息第一句话直接告诉“改什么”。 ## 排错建议 - 完全没输出:先确认确实在 PR 上下文中跑,并且 token/权限齐全。 - 太吵:启用 diff 过滤,或按路径白名单/黑名单收敛。 ### FAQ **一定要 GitHub Actions 吗?** 答:不一定。reviewdog 支持多种 CI;想发 PR 评论时关键是要拿到 PR diff 上下文。 **可以本地跑吗?** 答:可以。先用 `-reporter=local` 验证解析与输出格式,再接入 CI。 **如何避免把历史问题全刷出来?** 答:用 diff 过滤(`-filter-mode=diff_context`),只对本次改动新增问题提示。 ## 来源与感谢 > Source: https://github.com/reviewdog/reviewdog > License: MIT > GitHub stars: 9,286 · forks: 485 --- Source: https://tokrepo.com/en/workflows/reviewdog-turn-lint-into-pr-review-comments Author: Script Depot