fix: code quality and safety improvements - #306
Conversation
|
Someone is attempting to deploy a commit to the Kunal Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
🎉 Welcome to CodeLens — Thank You for Your Contribution!Hey @saurabhhhcodes! 👋 We are genuinely excited to have you here. Every single PR — big or small — makes CodeLens better, and yours is no exception. Take a moment to review the checklist below to help us merge your work quickly and smoothly. ✅ Before Requesting a Review
💬 Join Our Community Channel — This is MandatoryBeing part of our communication channel is compulsory for all contributors, not optional. Why join? This is where all important announcements, PR review updates, contribution discussions, and maintainer decisions happen in real time. Contributors who are not in the channel regularly miss critical context and updates, which often leads to duplicated or misaligned work. Staying connected here is what keeps the community strong and your contributions impactful. We are rooting for you! If you have any questions, drop them in the channel or comment right here on this PR. Let's build something great together. 🚀✨ |
📝 WalkthroughWalkthroughThe changes add an ESLint disable directive to the generated prettifier and make Codeforces difficulty and activity date sorting explicitly numeric. ChangesCodeforces numeric sorting
Generated prettifier lint directive
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@server/modules/codeforces/service.js`:
- Line 33: Update the dates sorting in the activity streak computation to use a
chronological comparator for the “YYYY-MM-DD” keys in dailyActivity, such as
comparing parsed date values or lexicographically comparing the normalized
strings. Ensure the resulting order is ascending before currentStreak and
longestStreak are calculated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7cd87788-2e38-4a70-88f4-b8dc594d6bca
📒 Files selected for processing (3)
frontend/coverage/prettify.jsfrontend/src/pages/CodeforcesPage.jsxserver/modules/codeforces/service.js
|
|
||
| // Compute streak | ||
| const dates = Object.keys(dailyActivity).sort(); | ||
| const dates = Object.keys(dailyActivity).sort((a, b) => a - b); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
node <<'NODE'
if (!Number.isNaN("2026-07-02" - "2026-07-01")) {
throw new Error("ISO date subtraction is expected to produce NaN");
}
NODE
rg -n -C 4 'computeActivityData|currentStreak|longestStreak' server --glob '*.js'Repository: kunalverma2512/CodeLens
Length of output: 12855
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '18,70p' server/modules/codeforces/service.js
node - <<'JS'
const fn = (submissions) => {
const dailyActivity = {};
for (const sub of submissions) {
const date = new Date(sub.creationTimeSeconds * 1000).toISOString().slice(0, 10);
dailyActivity[date] = (dailyActivity[date] || 0) + 1;
}
const dates = Object.keys(dailyActivity).sort((a, b) => a - b);
const sortedDesc = [...dates].reverse();
let currentStreak = 0;
let longestStreak = 0;
let tempStreak = 0;
const today = new Date().toISOString().slice(0, 10);
for (let i = 0; i <= 3; i++) {
const expected = new Date(Date.now() - i * 86_400_000).toISOString().slice(0, 10);
if (sortedDesc[i] === expected) {
currentStreak++;
} else {
break;
}
}
for (let i = 0; i < dates.length; i++) {
const prev = i === 0 ? null : new Date(dates[i - 1]);
const curr = new Date(dates[i]);
const diff = (curr - prev) / 86_400_000;
tempStreak = diff === 1 ? tempStreak + 1 : 1;
longestStreak = Math.max(longestStreak, tempStreak);
}
return { dates, currentStreak, longestStreak };
};
const submissions = [
{ creationTimeSeconds: Date.parse("2026-07-01T00:00:00Z") / 1000 },
{ creationTimeSeconds: Date.parse("2026-07-03T00:00:00Z") / 1000 },
{ creationTimeSeconds: Date.parse("2026-07-02T00:00:00Z") / 1000 },
{ creationTimeSeconds: Date.parse("2026-07-04T00:00:00Z") / 1000 },
{ creationTimeSeconds: Date.parse("2026-07-06T00:00:00Z") / 1000 },
];
const result = fn(submissions);
console.log("dates:", JSON.stringify(result.dates));
console.log("currentStreak:", result.currentStreak);
console.log("longestStreak:", result.longestStreak);
console.log("localeCompare dates:", JSON.stringify(Object.keys(result.dates.reduce((o, k) => (o[k] = 1, o), {})).sort((a, b) => a.localeCompare(b))));
JSRepository: kunalverma2512/CodeLens
Length of output: 1797
Sort activity dates before computing streaks.
dailyActivity uses "YYYY-MM-DD" keys. Subtracting those strings with a - b does not produce a chronological comparator, so dailyActivity keys remain in insertion order. That makes both currentStreak and longestStreak incorrect.
Proposed fix
- const dates = Object.keys(dailyActivity).sort((a, b) => a - b);
+ const dates = Object.keys(dailyActivity).sort((a, b) => a.localeCompare(b));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const dates = Object.keys(dailyActivity).sort((a, b) => a - b); | |
| const dates = Object.keys(dailyActivity).sort((a, b) => a.localeCompare(b)); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@server/modules/codeforces/service.js` at line 33, Update the dates sorting in
the activity streak computation to use a chronological comparator for the
“YYYY-MM-DD” keys in dailyActivity, such as comparing parsed date values or
lexicographically comparing the normalized strings. Ensure the resulting order
is ascending before currentStreak and longestStreak are calculated.
Summary by CodeRabbit
Bug Fixes
Chores