Skip to content

[file-diet] Split pkg/linters/execcommandoutputerrdiscard/execcommandoutputerrdiscard.go (1534 lines) #80381

Done

Description

@github-actions

Overview

pkg/linters/execcommandoutputerrdiscard/execcommandoutputerrdiscard.go has grown to 1534 lines (threshold: 800), which makes it hard to maintain. Split it into focused files within the same package.

Current State

  • File: pkg/linters/execcommandoutputerrdiscard/execcommandoutputerrdiscard.go
  • Size: 1534 lines, about 60 functions and 1 type
  • Test Coverage: the test file has 16 lines (ratio ≈ 0.01). It is a single analysistest run against testdata.
  • Complexity: many AST-walking helpers. Several take 6 or more parameters (pass, body, object, after, before, ...).
Full File Analysis

The functions fall into these clusters, with approximate line ranges:

  • Entry and call detection (25–190): run, execOutputMethod, enclosingFunction, findCallResults, resultBinding, bindResults, bindingObject, sameCall, callIsReturned.
  • Error and output propagation on failure paths (193–475): returnsErrorOnFailurePath, returnsOutputOnAllReturns, returnsObjectOnFailurePath, hasRetainedObjectUseOnFailurePath, isDiagnosticSinkCall, failureBranchReturnsObject, returnPropagatesObject, isErrorObject, expressionPropagatesError, hasOnlyWrapVerb, expressionRetainsObject.
  • Retention and slice aliasing (478–810): objectRetainedUntil, findSliceAliases, expressionAliasesObjectAt, sliceAliasMayAliasAt, isFullSliceAliasAt, isSliceConversion, isDirectFunctionBodyAssignment, expressionUsesObjectOrAliasAt, isBuiltinCall, isRetainingAppend, isObjectIdent, expressionUsesObject.
  • Failure branch helpers (811–870): hasReturnBefore, hasNamedResult, errorFailureBranch.
  • Stderr and ExitError usage (871–1130, 1217–1410): hasExitErrorStderrUse, hasConfiguredStderrUse, isOSStderr, stderrWriterObject, isKnownCapturedStderrWriter, stderrSinkReassignedBetween, hasRetainedCapturedStderrUse, returnedCall, stderrFieldWrittenBetween, sameExitErrorReceiver, findExitErrorObjects.
  • Captured buffer analysis (1066–1215): capturedStderrConsumedBetween, findCapturedBufferAliases, expressionUsesBufferBytes.
  • Generic AST utilities (1296–1534): nodeContains, isAssignmentDestination, objectReassignedBetween, isDiscardedValue, isExitErrorAssertion, isErrorsAsForExitError, isExecExitErrorType.

Refactoring Strategy

Proposed File Splits

  1. execcommandoutputerrdiscard.go (about 200 lines): Analyzer, run, execOutputMethod, enclosingFunction, and the result-binding helpers. Responsibility: analyzer entry point and call detection.
  2. failure_paths.go (about 300 lines): the returns*OnFailurePath functions, failureBranchReturnsObject, returnPropagatesObject, expressionPropagatesError, hasOnlyWrapVerb, errorFailureBranch, hasReturnBefore, hasNamedResult. Responsibility: failure-path propagation checks.
  3. retention.go (about 350 lines): objectRetainedUntil, expressionRetainsObject, the slice alias functions, isRetainingAppend, isBuiltinCall. Responsibility: retention and alias analysis.
  4. stderr.go (about 450 lines): the ExitError and stderr helpers, and the captured buffer analysis. Responsibility: stderr usage detection.
  5. astutil.go (about 200 lines): nodeContains, isAssignmentDestination, objectReassignedBetween, isDiscardedValue, isObjectIdent, expressionUsesObject, isErrorObject. Responsibility: shared AST and type utilities.

Interface Abstractions

Group the repeated (pass, body, object, after, before) parameters into a small analysisContext struct. This reduces coupling and parameter noise.

Test Coverage Plan

The existing testdata-driven test is the main safety net. Before and during the split:

  1. Extend testdata with cases for each cluster: alias retention, wrapped errors, captured stderr buffers, and reassignment between call and use.
  2. Add small internal unit tests for the pure helpers hasOnlyWrapVerb, isExecExitErrorType, and nodeContains.
  3. Target >80% coverage per new file.

Implementation Guidelines

  1. Preserve behavior: diagnostics must be identical.
  2. Keep the exported API (Analyzer) unchanged.
  3. Move one cluster at a time and run go test ./pkg/linters/... after each move.
  4. Run make fmt and make lint.

Acceptance Criteria

  • File split into about 5 focused files, each under 500 lines
  • make test-unit passes
  • Test coverage ≥80% for the new files
  • No public API changes
  • make lint and make build succeed

Priority: Medium
Effort: Medium
Expected Impact: easier maintenance and testing of the linter

Generated by 🧹 Daily File Diet · copilot · auto (Claude Sonnet 5.5) · ~23 AIC · ⌖ ~2 AIC · ⊞ 13.4K · history

  • expires on Nov 25, 2026, 4:47 AM UTC-08:00

Activity

  1. added
    cookie
    backlog:engineering-quality
    on Nov 23, 2026
  2. github-actions commented on Nov 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, Copilot 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 · ⌖ ~2 AIC · ⊞ 10.5K · history

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

Metadata

Metadata

Labels

automated-analysisbacklog:engineering-qualitycode-healthcookierefactoring

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions