refactor: use semver instead of manual implementations#48
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis pull request adds the semver runtime package and its TypeScript types, removes three custom version helpers (getPrereleaseId, comparePrereleasePrecedence, lt) from src/utils/version.ts, updates diagnostics rules to use semver functions (prerelease, gtr, ltr and semver/functions/lt), updates tests to remove coverage for the removed helpers, and configures semver to be inlined during bundling. Possibly related PRs
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
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/upgrade.ts (1)
30-42:⚠️ Potential issue | 🔴 CriticalArray reference comparison silently disables all prerelease upgrade hints.
semver.prerelease()returns an array of prerelease components (e.g.prerelease('1.2.3-alpha.1') -> ['alpha', 1]), ornullif none exist.On Line 37,
prerelease(tagVersion) !== currentPreIdcompares two separate array instances with reference equality. These are always distinct object references, so the condition is alwaystrue, causing the loop tocontinueon every iteration — meaningcreateUpgradeDiagnosticis never reached for any dist-tag. All prerelease upgrade diagnostics are silently suppressed.The prior
getPrereleaseIdreturned the first prerelease component as a string, which supported scalar===/!==comparison. The fix is to compare only the first element (the channel identifier, e.g.'beta'), preserving the original semantics:🐛 Proposed fix
- const currentPreId = prerelease(semver) + const currentPreId = prerelease(semver)?.[0] if (!currentPreId) return for (const [tag, tagVersion] of Object.entries(pkg.distTags)) { if (tag === 'latest') continue - if (prerelease(tagVersion) !== currentPreId) + if (prerelease(tagVersion)?.[0] !== currentPreId) continue if (!lt(semver, tagVersion)) continue
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
package.jsonpnpm-workspace.yamlsrc/providers/diagnostics/rules/upgrade.tssrc/providers/diagnostics/rules/vulnerability.tssrc/utils/version.tstests/utils/version.test.tstsdown.config.ts
💤 Files with no reviewable changes (1)
- src/utils/version.ts
No description provided.