Skip to content

fix: code quality and safety improvements - #306

Open
saurabhhhcodes wants to merge 1 commit into
kunalverma2512:mainfrom
saurabhhhcodes:fix/CodeLens-89816
Open

fix: code quality and safety improvements#306
saurabhhhcodes wants to merge 1 commit into
kunalverma2512:mainfrom
saurabhhhcodes:fix/CodeLens-89816

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Corrected sorting of Codeforces difficulty ratings for accurate ordering.
    • Improved activity date sorting to ensure streak calculations are accurate.
  • Chores

    • Updated generated tooling metadata without changing its behavior.

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown

🎉 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

  • Keep code clean, readable, and consistent with the existing codebase
  • Avoid unrelated or unnecessary file changes
  • Make sure the UI is fully responsive across all device sizes
  • Attach screenshots or a short screen recording for any UI changes
  • Resolve all merge conflicts before marking the PR as ready
  • Do not submit AI-generated, copy-pasted, or low-effort implementations

💬 Join Our Community Channel — This is Mandatory

Being part of our communication channel is compulsory for all contributors, not optional.

📡 Join the CodeLens Matrix Channel

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. 🚀✨

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes add an ESLint disable directive to the generated prettifier and make Codeforces difficulty and activity date sorting explicitly numeric.

Changes

Codeforces numeric sorting

Layer / File(s) Summary
Codeforces numeric sorting
frontend/src/pages/CodeforcesPage.jsx, server/modules/codeforces/service.js
Difficulty rating keys now use an explicit decimal radix. Activity date keys now use numeric comparison before streak calculation.

Generated prettifier lint directive

Layer / File(s) Summary
Prettifier lint directive
frontend/coverage/prettify.js
The generated prettifier now starts with a file-level ESLint disable directive.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: kunalverma2512

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, so the required summary, motivation, testing, and checklist information is missing. Add the required pull request sections, including changes made, motivation, change type, testing details, checklist status, and related issue information.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title broadly describes the changes but does not identify the specific sorting and linting improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad67ff and d019cac.

📒 Files selected for processing (3)
  • frontend/coverage/prettify.js
  • frontend/src/pages/CodeforcesPage.jsx
  • server/modules/codeforces/service.js


// Compute streak
const dates = Object.keys(dailyActivity).sort();
const dates = Object.keys(dailyActivity).sort((a, b) => a - b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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))));
JS

Repository: 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.

Suggested change
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.

@coderabbitai coderabbitai Bot mentioned this pull request Aug 2, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant