Repository navigation
Done
Labels
automated-analysisbacklog:engineering-qualityEngineering quality, tests and refactorscode-healthcookieIssue Monster Loves Cookies!refactoring
Description
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
analysistestrun againsttestdata. - 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
execcommandoutputerrdiscard.go(about 200 lines):Analyzer,run,execOutputMethod,enclosingFunction, and the result-binding helpers. Responsibility: analyzer entry point and call detection.failure_paths.go(about 300 lines): thereturns*OnFailurePathfunctions,failureBranchReturnsObject,returnPropagatesObject,expressionPropagatesError,hasOnlyWrapVerb,errorFailureBranch,hasReturnBefore,hasNamedResult. Responsibility: failure-path propagation checks.retention.go(about 350 lines):objectRetainedUntil,expressionRetainsObject, the slice alias functions,isRetainingAppend,isBuiltinCall. Responsibility: retention and alias analysis.stderr.go(about 450 lines): theExitErrorand stderr helpers, and the captured buffer analysis. Responsibility: stderr usage detection.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:
- Extend
testdatawith cases for each cluster: alias retention, wrapped errors, captured stderr buffers, and reassignment between call and use. - Add small internal unit tests for the pure helpers
hasOnlyWrapVerb,isExecExitErrorType, andnodeContains. - Target >80% coverage per new file.
Implementation Guidelines
- Preserve behavior: diagnostics must be identical.
- Keep the exported API (
Analyzer) unchanged. - Move one cluster at a time and run
go test ./pkg/linters/...after each move. - Run
make fmtandmake lint.
Acceptance Criteria
- File split into about 5 focused files, each under 500 lines
-
make test-unitpasses - Test coverage ≥80% for the new files
- No public API changes
-
make lintandmake buildsucceed
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
Reacted by Copilot
Metadata
Metadata
Labels
automated-analysisbacklog:engineering-qualityEngineering quality, tests and refactorscode-healthcookieIssue Monster Loves Cookies!refactoring
Activity
github-actions commentedon Nov 23, 2026
🍪 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! 🍪