WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@lokyaan
Copy link

@lokyaan lokyaan commented Oct 29, 2025

Summary

Fixes a division-by-zero issue in the lingo.dev status CLI output.
When totalWordsToTranslate equals 0, (0 / 0) * 100 evaluates to NaN, causing the CLI to print:

Fix

Added a guard to return 0.0 instead of NaN when total words = 0:

const percent =
  totalWordsToTranslate === 0
    ? 0.0
    : ((words / totalWordsToTranslate) * 100).toFixed(1);


###Result
- fr: ~0 words (0.0% of total)

###Impact
Prevents CI/CD regex validation failures.
Improves CLI reliability and output consistency.

Copy link
Contributor

@The-Best-Codes The-Best-Codes left a comment

Choose a reason for hiding this comment

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

Just a couple of things I see that you might want to change.
Also, not sure if you ran pnpm run format before committing but don't forget to do that 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

This file needs to be removed, the repo uses pnpm

package.json Outdated
"dependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.10",
"build": "^0.1.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change needed?

@lokyaan
Copy link
Author

lokyaan commented Oct 30, 2025 via email

@lokyaan
Copy link
Author

lokyaan commented Oct 30, 2025 via email

@The-Best-Codes
Copy link
Contributor

@lokyaan I want to test this locally to see if the build dependency is actually needed on my end. AFAIK it works just fine without it.

@lokyaan
Copy link
Author

lokyaan commented Oct 30, 2025 via email

@The-Best-Codes
Copy link
Contributor

@lokyaan Okay, maybe remove the dependency, then :)

@lokyaan
Copy link
Author

lokyaan commented Oct 31, 2025 via email

@The-Best-Codes
Copy link
Contributor

@lokyaan Don't forget to run pnpm install to update the lockfile and pnpm run format to format the codebase again. After that I think this PR is ready to merge 😀

@lokyaan
Copy link
Author

lokyaan commented Oct 31, 2025 via email

Copy link
Contributor

@The-Best-Codes The-Best-Codes left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@lokyaan
Copy link
Author

lokyaan commented Oct 31, 2025 via email

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a division-by-zero bug in the lingo.dev status CLI command that caused "NaN%" to appear in the output when all translations are complete (totalWordsToTranslate = 0). The fix adds a guard condition to return 0.0 instead of the result of dividing zero by zero.

Key Changes:

  • Added conditional check in status command to handle edge case when totalWordsToTranslate === 0
  • Updated pnpm-lock.yaml with dependency resolution changes (unrelated to main fix)

Reviewed Changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/cli/src/cli/cmd/status.ts Added guard condition to prevent NaN% when calculating per-language translation percentages with zero total words
pnpm-lock.yaml Dependency resolution updates for eslint-related packages (unrelated to the main fix)
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const percent = ((words / totalWordsToTranslate) * 100).toFixed(1);
const percent =
totalWordsToTranslate === 0
? 0.0
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The ternary operator has a type inconsistency. The true branch returns 0.0 (a number), while the false branch returns the result of .toFixed(1) (a string). This should be "0.0" (a string) to match the type returned by .toFixed(1).

const percent =
  totalWordsToTranslate === 0
    ? "0.0"
    : ((words / totalWordsToTranslate) * 100).toFixed(1);
Suggested change
? 0.0
? "0.0"

Copilot uses AI. Check for mistakes.
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.

2 participants