Skip to content

refactor: use slices.Contains to simplify code - #16680

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
weifanglab:main
Jul 7, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
weifanglab:main

Conversation

@weifanglab

Copy link
Copy Markdown
Contributor

Summary

There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6b9a5b6-7421-4963-8e55-276e6f9f9b4a

📥 Commits

Reviewing files that changed from the base of the PR and between d8cefcf and e4f8ed9.

📒 Files selected for processing (15)
  • internal/agent/canvas/loop_subgraph.go
  • internal/agent/component/llm_test.go
  • internal/agent/component/parallel_test.go
  • internal/cli/filesystem/skill_hub/source/clawhub.go
  • internal/common/format.go
  • internal/engine/infinity/chunk.go
  • internal/harness/core/callback.go
  • internal/harness/events/store.go
  • internal/harness/graph/graph/graph.go
  • internal/harness/graph/graph/message.go
  • internal/harness/graph/pregel/write.go
  • internal/ingestion/compilation/extractor/dep_relation.go
  • internal/service/nlp/term_weight_test.go
  • internal/service/nlp/wordnet_test.go
  • internal/utility/ssrf.go

📝 Walkthrough

Walkthrough

This PR performs a mechanical refactor across 14 Go files, replacing manual loop-based slice membership checks and boolean flags with the standard library's slices.Contains function. Several now-unused local helper functions (listContains, schemeAllowed, containsDep) are removed accordingly.

Changes

slices.Contains Adoption

Layer / File(s) Summary
Agent canvas loop evaluation
internal/agent/canvas/loop_subgraph.go
evalListOp's contains/not-contains checks use slices.Contains; local listContains helper removed.
Agent component registration tests
internal/agent/component/llm_test.go, internal/agent/component/parallel_test.go
Registered-name presence checks use slices.Contains instead of manual search loops.
Skill hub path safety and text detection
internal/cli/filesystem/skill_hub/source/clawhub.go
isSafePath and isTextContent use slices.Contains to detect ".." segments and null bytes.
Composite model name validation
internal/common/format.go
IsCompositeModelName and ExtractCompositeName use slices.Contains(parts, "") for empty-segment detection.
Infinity chunk field selection
internal/engine/infinity/chunk.go
convertSelectFields uses slices.Contains instead of a hasID loop flag.
Harness callback filtering
internal/harness/core/callback.go
Agent-name checks in filterOptions and filterCallbackHandlersForNestedAgents use slices.Contains.
Harness event filter matching
internal/harness/events/store.go
EventFilter.Matches uses slices.Contains for Types membership.
Harness graph edge/message filtering
internal/harness/graph/graph/graph.go, internal/harness/graph/graph/message.go
Finish-point and role-matching checks use slices.Contains.
Pregel write validator
internal/harness/graph/pregel/write.go
Whitelist channel check uses slices.Contains.
Dependency relation extraction
internal/ingestion/compilation/extractor/dep_relation.go
extractCopula uses slices.Contains; containsDep helper removed.
NLP service tests
internal/service/nlp/term_weight_test.go, internal/service/nlp/wordnet_test.go
Test assertions use slices.Contains instead of found-flag loops.
SSRF URL scheme validation
internal/utility/ssrf.go
AssertURLSafe uses slices.Contains; schemeAllowed helper removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

With paws that hop from file to file,
I swept out loops in rabbit style,
slices.Contains now takes the lead,
No more helpers that we don't need,
Clean little burrows, tidy and light — 🐇✨
Hopping through code till the tests run right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing manual membership checks with slices.Contains.
Description check ✅ Passed The description includes the required Summary section and provides adequate background on why slices.Contains is being used.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@yuzhichang
yuzhichang merged commit 7a4e1b6 into infiniflow:main Jul 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants