fix: add JSDoc overloads to stackAnalysisBatch for type narrowing#502
Merged
Merged
Conversation
Consumers can now get precise return types based on html and batchMetadata arguments, matching the pattern used by stackAnalysis and imageAnalysis. Related: fabric8-analytics/fabric8-analytics-vscode-extension#889 (comment) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's GuideAdds four precise JSDoc @overload signatures to stackAnalysisBatch to narrow its Promise return type based on the html flag and batchMetadata option, aligning its typing behavior with stackAnalysis/imageAnalysis while not changing runtime behavior. Class diagram for stackAnalysisBatch JSDoc overloadsclassDiagram
class stackAnalysisBatch {
<<function>>
+Promise stackAnalysisBatch(workspaceRoot string, html true, opts OptionsBatchMetadataTrue)
+Promise stackAnalysisBatch(workspaceRoot string, html true, opts OptionsBatchMetadataFalseOrUndef)
+Promise stackAnalysisBatch(workspaceRoot string, html false, opts OptionsBatchMetadataTrue)
+Promise stackAnalysisBatch(workspaceRoot string, html false, opts OptionsBatchMetadataFalseOrUndef)
+Promise stackAnalysisBatch(workspaceRoot string, html boolean, opts Options)
}
class Options {
+number batchConcurrency
+boolean continueOnError
+boolean batchMetadata
+string[] discoveryIgnores
}
class OptionsBatchMetadataTrue {
+boolean batchMetadata = true
}
class OptionsBatchMetadataFalseOrUndef {
+boolean batchMetadata = false
}
class BatchAnalysisMetadata {
+number totalPackages
+number successfulAnalyses
+number failedAnalyses
+string[] sbomErrors
+string[] validationErrors
}
class AnalysisReport {
}
class HtmlBatchResultWithMetadata {
+string analysis
+BatchAnalysisMetadata metadata
}
class JsonBatchResultWithMetadata {
+AnalysisReportByPath analysis
+BatchAnalysisMetadata metadata
}
class AnalysisReportByPath {
+AnalysisReport reportsByPath
}
stackAnalysisBatch ..> Options : uses
stackAnalysisBatch ..> OptionsBatchMetadataTrue : narrows
stackAnalysisBatch ..> OptionsBatchMetadataFalseOrUndef : narrows
stackAnalysisBatch ..> BatchAnalysisMetadata : returns
stackAnalysisBatch ..> AnalysisReport : returns
stackAnalysisBatch ..> HtmlBatchResultWithMetadata : returns
stackAnalysisBatch ..> JsonBatchResultWithMetadata : returns
OptionsBatchMetadataTrue --|> Options
OptionsBatchMetadataFalseOrUndef --|> Options
HtmlBatchResultWithMetadata *-- BatchAnalysisMetadata
JsonBatchResultWithMetadata *-- BatchAnalysisMetadata
JsonBatchResultWithMetadata *-- AnalysisReportByPath
AnalysisReportByPath *-- AnalysisReport
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The final JSDoc block for
stackAnalysisBatch(the implementation signature) should not be marked with@overload, otherwise TypeScript may treat it as another overload rather than the implementation; drop@overloadfrom that last block and keep it only on the four specific overload signatures. - To avoid duplicating long generic return types, consider extracting the
Object.<string, AnalysisReport>shape and the{ analysis, metadata }shape into named JSDoc typedefs and referencing those in the overloads to keep the comments more maintainable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The final JSDoc block for `stackAnalysisBatch` (the implementation signature) should not be marked with `@overload`, otherwise TypeScript may treat it as another overload rather than the implementation; drop `@overload` from that last block and keep it only on the four specific overload signatures.
- To avoid duplicating long generic return types, consider extracting the `Object.<string, AnalysisReport>` shape and the `{ analysis, metadata }` shape into named JSDoc typedefs and referencing those in the overloads to keep the comments more maintainable.
## Individual Comments
### Comment 1
<location path="src/index.js" line_range="451-460" />
<code_context>
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
*
+ * @overload
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
</code_context>
<issue_to_address>
**issue:** The non-specific, final JSDoc block for this function probably should not be tagged with `@overload`.
In TypeScript JSDoc, `@overload` should only annotate the overload signatures; the concrete implementation docblock should omit it. Tagging this final, general block with `@overload` can mislead tooling and produce incorrect type resolution. Please remove `@overload` from the last block so it’s treated as the implementation signature, leaving the earlier blocks as the overloads.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
8 tasks
Strum355
approved these changes
May 5, 2026
a-oren
enabled auto-merge (squash)
May 5, 2026 12:38
a-oren
disabled auto-merge
May 5, 2026 12:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@overloadJSDoc blocks tostackAnalysisBatch()that narrow return types based onhtmlandbatchMetadataargumentsstackAnalysis()andimageAnalysis()Related
Test plan
npm test)🤖 Generated with Claude Code
Summary by Sourcery
Enhancements: