feat: add vulnerability quick-fix + hint#39
Conversation
📝 WalkthroughWalkthroughAdds a VulnerabilityCodeActionProvider that offers QuickFix actions to replace vulnerable dependency versions with a parsed "fixed in" version; registers the provider conditionally when diagnostics.vulnerability is enabled; extends vulnerability diagnostics to compute and include a best fixedIn version and to append an upgrade hint to diagnostic messages; adds an optional Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/providers/code-actions/vulnerability.ts (1)
47-51: Minor: RedundantparseVersioncall onfixedInVersion.The
fixedInVersionextracted from the diagnostic code is already a raw semver string (e.g.,"16.1.5"), soparseVersion(fixedInVersion)?.semverwill return the same value. While this works correctly, it's slightly redundant.♻️ Optional simplification
const currentVersion = document.getText(diagnostic.range) const currentSemver = parseVersion(currentVersion)?.semver - const fixedSemver = parseVersion(fixedInVersion)?.semver ?? fixedInVersion - if (currentSemver && currentSemver === fixedSemver) + if (currentSemver && currentSemver === fixedInVersion) return []
# Conflicts: # src/index.ts
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/providers/diagnostics/rules/vulnerability.ts (1)
75-103:⚠️ Potential issue | 🟠 MajorGuard
vulnerablePackagesto avoid runtime crashes.
If the API omitsvulnerablePackages, Line 94 will throw, breaking diagnostics for the file. Default to an empty list before filtering.🔧 Suggested fix
- const { totalCounts, vulnerablePackages } = result + const { totalCounts, vulnerablePackages = [] } = result @@ - const rootVulnerabilitiesFixedIn = vulnerablePackages + const rootVulnerabilitiesFixedIn = vulnerablePackages .filter((vulnerablePackage) => vulnerablePackage.depth === 'root')
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/providers/diagnostics/rules/vulnerability.ts (2)
15-20: Clarify function intent: this finds the maximum (not earliest) fixedIn version.The reduce logic returns the maximum version from the list (since
lt(best, current)keeps the larger value). This is correct when you need to fix all vulnerabilities simultaneously—the user must upgrade to at least the highest fixedIn version. However, the PR objective references "earliest safe version," which could cause confusion.Consider renaming to
getMinimumRequiredFixVersionor adding a brief comment explaining why the maximum is chosen.📝 Suggested clarification
+/** + * Returns the highest fixedIn version, ensuring all vulnerabilities are addressed. + */ function getBestFixedInVersion(fixedInVersions: string[]): string | undefined { if (!fixedInVersions.length) return - return fixedInVersions.reduce((best, current) => lt(best, current) ? current : best) + return fixedInVersions.reduce((best, current) => lt(best, current) ? current : best) }
62-64: Reconsider preserving the version prefix in the upgrade message.Using
parsed.prefix(e.g.,^or~) in the message produces output like "Upgrade to ^16.1.5 to fix." This could be confusing because:
- The prefix implies a range, not a specific version.
- If the user's current range (e.g.,
^16.0.0) already technically includes16.1.5, the message may seem contradictory.Consider showing the exact version without a prefix in the message, or clarifying that the version number is the minimum required.
💡 Suggested fix
const fixedInVersion = getBestFixedInVersion(rootVulnerabilitiesFixedIn) const messageSuffix = fixedInVersion - ? ` Upgrade to ${parsed.prefix}${fixedInVersion} to fix.` + ? ` Upgrade to ${fixedInVersion} to fix.` : ''
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Closes #24