Skip to content

[refactor] ctxbackground re-implements astutil.IsPkgSelector logic instead of reusing it #71003

Not planned

Description

@github-actions

Overview

Sampled analysis of rotation slice 1/1 for pkg/linters/contextcancelnotdeferred and slice 1/1 for pkg/linters/ctxbackground (date 2026-10-22, 5 of 11795 total functions reviewed, coverage_days 798 for a full unchanged-inventory rotation). This is a sampled check of these two slices only, not a review of either package or the repository as a whole.

Finding

isContextBackgroundCall in pkg/linters/ctxbackground/ctxbackground.go (lines 83-101) manually re-implements the same "is this selector rooted in an import of package X" check that isContextWithCancelCall in pkg/linters/contextcancelnotdeferred/contextcancelnotdeferred.go (lines 48-62) performs by calling the shared helper astutil.IsPkgSelector(pass, sel, "context").

Observed duplicate logic in isContextBackgroundCall:

ident, ok := sel.X.(*ast.Ident)
if !ok || pass.TypesInfo == nil {
	return false
}
obj := pass.TypesInfo.ObjectOf(ident)
if obj == nil {
	return false
}
pkgName, ok := obj.(*types.PkgName)
if !ok {
	return false
}
return pkgName.Imported().Path() == "context"

versus the sibling linter's one-line equivalent:

if !astutil.IsPkgSelector(pass, sel, "context") {
	return false
}

Both resolve a *ast.SelectorExpr's base identifier to its types.Object, assert it is a *types.PkgName, and compare the imported path to "context" -- the same multi-step package-identifier resolution, just inlined in one file and factored into a helper in the other.

Proposed refactoring

Replace the inline block in isContextBackgroundCall with a call to astutil.IsPkgSelector(pass, sel, "context"), matching the pattern already used by isContextWithCancelCall. This removes about 7 duplicated lines and keeps the selector-resolution logic in one place.

Preservation risks

  • isContextBackgroundCall additionally guards on pass.TypesInfo == nil before the lookup; confirm astutil.IsPkgSelector has equivalent nil-safety (not visible in this excerpt) before removing that check.
  • Only the selector-ownership check should move; the existing sel.Sel.Name != "Background" check in isContextBackgroundCall is specific to this linter and must stay as-is.

Scope

Sampled, not exhaustive: based only on the 5 functions supplied in today's rotation slice for these 2 packages. No other files or functions in either package were reviewed.

Generated by 🔧 Semantic Function Refactoring · claude · sonnet50 · 40.9 AIC · ⌖ 19.1 AIC · ⊞ 5.2K · ◷

  • expires on Oct 23, 2026, 6:41 PM UTC-08:00

Activity

  1. github-actions commented on Oct 22, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · 0.602 AIC · ⌖ 0.743 AIC · ⊞ 12.6K · ◷

  2. github-actions commented on Oct 23, 2026

    @github-actions
    ContributorAuthor

    Superseded by a new sampled semantic-function-refactor report filed today (rotation slice pkg/workflow 455/636, pkg/cli 456/557, 2026-10-23). This workflow closes prior [refactor]-tagged issues each time it files a new one; this closure does not imply the original finding in this issue was invalid, only that the daily sampled report has moved on.

    Generated by 🔧 Semantic Function Refactoring · claude · sonnet50 · ~48 AIC · ⌖ ~25 AIC · ⊞ 5.2K

  3. github-actions commented on Oct 23, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 13K · ◷

  4. github-actions commented on Oct 24, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 13.2K · ◷

  5. github-actions commented on Oct 24, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-10-24T02:41:23.399Z.

    Closed by Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions