Skip to content

fix(linter): avoid false positive for 3e-308#19995

Closed
Boshen wants to merge 2 commits intomainfrom
fix/no-loss-of-precision-3e-308
Closed

fix(linter): avoid false positive for 3e-308#19995
Boshen wants to merge 2 commits intomainfrom
fix/no-loss-of-precision-3e-308

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Mar 4, 2026

Summary

  • fix eslint/no-loss-of-precision false positive for 3e-308 by simplifying internal precision formatting
  • align test coverage with ESLint's current no-loss-of-precision test cases (including TS cases)
  • keep additional Oxc regression coverage for subnormal/underflow literals

Closes #19988

Testing

  • cargo test -p oxc_linter no_loss_of_precision -- --nocapture

AI usage disclosure

This PR was prepared with AI assistance, and I reviewed and validated the generated changes and test updates.

@Boshen Boshen requested a review from camc314 as a code owner March 4, 2026 09:58
Copilot AI review requested due to automatic review settings March 4, 2026 09:58
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Mar 4, 2026
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

Fixes eslint/no-loss-of-precision false positives for very small literals (e.g. 3e-308) by simplifying internal precision-string generation, and updates snapshots/tests to align with ESLint’s current test cases (including TS/TSX coverage).

Changes:

  • Replace the custom toPrecision-like formatting logic with Rust scientific formatting to avoid truncation for very small exponents.
  • Expand pass/fail test vectors to include additional exponent/TS cases and underflow/subnormal regressions.
  • Update the rule snapshot output to reflect the new/expanded test coverage.

Reviewed changes

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

File Description
crates/oxc_linter/src/rules/eslint/no_loss_of_precision.rs Simplifies to_precision implementation and updates rule test cases for additional exponent/TS and underflow scenarios.
crates/oxc_linter/src/snapshots/eslint_no_loss_of_precision.snap Updates expected diagnostics to match the expanded test coverage.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 4, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 52 skipped benchmarks1


Comparing fix/no-loss-of-precision-3e-308 (7d1d07f) with main (6245c56)

Open in CodSpeed

Footnotes

  1. 52 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df413b4fd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Boshen
Copy link
Member Author

Boshen commented Mar 4, 2026

Addressed review feedback in 7d1d07fa39:

  • restored JS-style toPrecision formatting behavior in the rule path (fixes the reported rounding regression)
  • fixed tiny-exponent handling by extracting digits from high-precision scientific notation (3e-308 case)
  • added runtime precision guard with assert!((1..=100).contains(&precision)) and made to_precision private to the module
  • aligned normalization with ESLint's raw-vs-stored behavior (parseAsFloat equivalent)
  • added regression coverage for 39782723799.5411758422851563 in the original test vectors

Validation:

  • cargo test -p oxc_linter no_loss_of_precision -- --nocapture
  • manual check: 3e-308 and 39782723799.5411758422851563 are no longer flagged; 9007199254740993 is still flagged.

@Boshen Boshen closed this Mar 4, 2026
@Boshen Boshen deleted the fix/no-loss-of-precision-3e-308 branch March 4, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: Incorrect no-loss-of-precision of '3e-308'

3 participants