Skip to content

Conversation

@ledigang
Copy link
Contributor

@ledigang ledigang commented Nov 20, 2025

Proposed changes

The new version of Go has been optimized, and variables do not need to be reassigned.

For more info: https://tip.golang.org/wiki/LoopvarExperiment#does-this-mean-i-dont-have-to-write-x--x-in-my-loops-anymore

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Refactor
    • Internal code cleanup: removed redundant variable shadowing and simplified loop captures to improve clarity and maintainability.
  • Tests
    • Adjusted internal tests to align with the cleanup.
  • Impact
    • No user-facing behavior changes; no API or public interfaces modified.

✏️ Tip: You can customize this high-level summary in your review settings.

@auto-assign auto-assign bot requested a review from dwisiswant0 November 20, 2025 08:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

Removed redundant per-iteration variable shadowing in three files; two removals are pure cleanup, one (in a concurrency test) removes a loop-variable copy that may alter concurrent capture semantics.

Changes

Cohort / File(s) Change summary
Removed redundant shadowing — core & input
pkg/core/execute_options.go, pkg/input/formats/burp/burp.go
Deleted redundant per-iteration shadowing assignments (template := template, item := item) inside loops; no changes to exported APIs or control flow.
Removed per-iteration shadowing — concurrency test
pkg/protocols/common/hosterrorscache/hosterrorscache_test.go
Removed i := i copy inside a loop used with goroutines in TestCacheCheckConcurrent; this changes how the loop variable is captured by goroutines (affects concurrent test behavior).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review areas that may need extra attention:
    • pkg/protocols/common/hosterrorscache/hosterrorscache_test.go — verify goroutine captures and test determinism after removal.
    • Confirm no lingering shadowing or closure-capture issues in pkg/core/execute_options.go and pkg/input/formats/burp/burp.go.

Poem

🐰 I nudged the shadows from the loop,

No doubles left to make me stoop.
Concurrency hops may now be bold,
But cleaner code is worth the hold. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'chore: omit unnecessary reassignment' accurately describes the main change across all three modified files, where variable shadowing assignments inside loops were removed based on Go's loop variable semantics improvements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@dwisiswant0
Copy link
Member

Thanks for the PR, @ledigang!

Out of curiosity, how did you catch them? golangci-lint wasn’t able to detect it.

$ golangci-lint run -E ineffassign ./...
0 issues.

@ledigang
Copy link
Contributor Author

@dwisiswant0

Thanks for the PR, @ledigang!

Out of curiosity, how did you catch them? golangci-lint wasn’t able to detect it.

$ golangci-lint run -E ineffassign ./...
0 issues.

Thank you for your review. I am currently using a tool I wrote myself, which is based on golangci-lint, go tools, and a wrapper for go-critic. It is not open source yet (because there are still many false positives and bugs).

@dwisiswant0
Copy link
Member

I see.

The ineffassign CLI also didn’t catch those (likely because the inner x is effectively used).

Could you update the remaining occurrences (specifically pkg/protocols/common/hosterrorscache/hosterrorscache_test.go:180) as well? Got them using ripgrep.

$ rg -n --no-ignore -g '!**/vendor/**' --pcre2 '\b([A-Za-z_]\w*)\s*:=\s*\1\b(?!\s*[.(])' -C 2
pkg/core/execute_options.go
110-
111-	for _, template := range templatesList {
112:		template := template
113-
114-		select {

pkg/input/formats/burp/burp.go
44-	// Print the parsed data for verification
45-	for _, item := range items.Items {
46:		item := item
47-		binx, err := base64.StdEncoding.DecodeString(item.Request.Raw)
48-		if err != nil {

pkg/protocols/common/hosterrorscache/hosterrorscache_test.go
178-	for i := 1; i <= 100; i++ {
179-		wg.Add(1)
180:		i := i
181-		go func() {
182-			defer wg.Done()

@ledigang
Copy link
Contributor Author

I see.

The ineffassign CLI also didn’t catch those (likely because the inner x is effectively used).

Could you update the remaining occurrences (specifically

Indeed! This regular expression is written brilliantly.

image

@dogancanbakir @dwisiswant0 Please review it again.

@dwisiswant0 dwisiswant0 changed the title refactor: omit unnecessary reassignment chore: omit unnecessary reassignment Nov 24, 2025
@dwisiswant0 dwisiswant0 merged commit 2997735 into projectdiscovery:dev Nov 24, 2025
31 of 32 checks passed
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.

3 participants