-
-
Notifications
You must be signed in to change notification settings - Fork 286
refactor-enforced-Number-namespace #2536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor-enforced-Number-namespace #2536
Conversation
Summary by CodeRabbit
WalkthroughRefactors frontend code to replace global numeric globals with Number‑scoped equivalents (e.g., Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
arkid15r
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
frontend/src/hooks/useSearchPage.ts (1)
40-42: LGTM! Refactor correctly implements Number namespace usage.The change from
parseInttoNumber.parseIntis correct and maintains identical behavior. This aligns with the PR objective to enforce the Number namespace for numeric globals.Optional improvement: Consider explicitly specifying the radix parameter for clarity:
const [currentPage, setCurrentPage] = useState<number>( - Number.parseInt(searchParams.get('page') || '1') + Number.parseInt(searchParams.get('page') || '1', 10) )This makes the decimal parsing intent explicit and is considered a best practice, though not strictly required since base-10 is the default for numeric strings.
frontend/eslint-rules/no-global-parsefloat.mjs (1)
1-29: LGTM! Safe replacement forparseFloat.Like
parseInt,Number.parseFloatis functionally identical to the globalparseFloat. This replacement is semantically safe.Consider adding dedicated unit tests for all five custom ESLint rules to verify:
- Correct detection of violations
- Auto-fixer behavior
- Edge cases (e.g., shadowed identifiers, already-namespaced calls)
Example test structure using ESLint's RuleTester:
import { RuleTester } from 'eslint' import noGlobalParseFloatRule from './no-global-parsefloat.mjs' const ruleTester = new RuleTester() ruleTester.run('no-global-parsefloat', noGlobalParseFloatRule, { valid: [ 'Number.parseFloat("3.14")', ], invalid: [ { code: 'parseFloat("3.14")', errors: [{ messageId: 'useNumberParseFloat' }], output: 'Number.parseFloat("3.14")', }, ], })
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
frontend/eslint-rules/no-global-isfinite.mjs(1 hunks)frontend/eslint-rules/no-global-isnan.mjs(1 hunks)frontend/eslint-rules/no-global-nan.mjs(1 hunks)frontend/eslint-rules/no-global-parsefloat.mjs(1 hunks)frontend/eslint-rules/no-global-parseint.mjs(1 hunks)frontend/eslint.config.mjs(3 hunks)frontend/src/hooks/useSearchPage.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/eslint.config.mjs (5)
frontend/eslint-rules/no-global-isfinite.mjs (1)
noGlobalIsFiniteRule(1-29)frontend/eslint-rules/no-global-isnan.mjs (1)
noGlobalIsNaNRule(1-29)frontend/eslint-rules/no-global-nan.mjs (1)
noGlobalNaNRule(1-42)frontend/eslint-rules/no-global-parsefloat.mjs (1)
noGlobalParseFloatRule(1-29)frontend/eslint-rules/no-global-parseint.mjs (1)
noGlobalParseIntRule(1-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: CodeQL (python)
- GitHub Check: CodeQL (javascript-typescript)
- GitHub Check: Run frontend checks
- GitHub Check: Run pre-commit checks
🔇 Additional comments (5)
frontend/eslint-rules/no-global-nan.mjs (1)
16-29: LGTM! Parent check correctly prevents duplicate reports.The logic properly skips
NaNwhen it's already part ofNumber.NaNby checking the parent MemberExpression. TheNaNreplacement is semantically safe since both refer to the same value.frontend/eslint.config.mjs (1)
18-22: LGTM! ESLint configuration properly wires the new rules.The custom rules are correctly imported, registered under the
nestplugin namespace, and enabled at error level. This enforces the Number namespace pattern as intended.Note: Given the semantic differences between global
isNaN/isFiniteand theirNumber.*counterparts (see comments on those rule files), ensure the auto-fixers have been tested against the actual codebase before merging.Also applies to: 69-77, 166-170
frontend/eslint-rules/no-global-parseint.mjs (1)
1-29: LGTM! Safe replacement forparseInt.Unlike
isNaN/isFinite,Number.parseIntis functionally identical to the globalparseInt(they reference the same function). This replacement is semantically safe and improves code clarity.frontend/eslint-rules/no-global-isnan.mjs (1)
1-29: No semantic risk from this rule in the current codebase.The verification shows the codebase already uses
Number.isNaN()exclusively (except in third-party minified libraries). The rule correctly targets only globalisNaN()calls via the conditionnode.callee.name === 'isNaN', so existing code usingNumber.isNaN()is unaffected. The auto-fixer will only replace problematic patterns where they appear, making the theoretical semantic concern inapplicable to this project's current state.frontend/eslint-rules/no-global-isfinite.mjs (1)
1-29: The rule is preventive but raises a valid semantic concern worthy of verification before activation.The codebase contains zero
isFinite()calls currently, so the original concern about breaking existing code is moot. However, if this rule is intended to be enabled, the semantic difference between globalisFinite()andNumber.isFinite()remains important:isFinite("123") // true (coerces to number) Number.isFinite("123") // false (no coercion)Before enabling this rule, verify:
- Whether auto-fixing to
Number.isFinite()aligns with intended behavior- Whether this should be a
suggestionor a stricter enforcement level- If any other similar rules in the suite (e.g.,
no-global-isnan) should be enabled together



Proposed change
Resolves #2529
Enforced use of Number namespace for numeric globals
For each instance:
Checklist
make check-testlocally; all checks and tests passed.