Skip to content

feat: port rule use-isnan#521

Merged
fansenze merged 1 commit intomainfrom
feat/port-rule-use-isnan-20260317
Apr 6, 2026
Merged

feat: port rule use-isnan#521
fansenze merged 1 commit intomainfrom
feat/port-rule-use-isnan-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the use-isnan rule from ESLint to rslint.

Require calls to isNaN() when checking for NaN

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the use-isnan linting rule to rslint, which guides developers to use the isNaN() or Number.isNaN() functions for checking NaN values, rather than direct comparisons. This prevents common pitfalls associated with NaN's unique comparison behavior in JavaScript, thereby improving code reliability and preventing subtle bugs.

Highlights

  • New Rule Implementation: The use-isnan rule has been ported from ESLint to rslint, enforcing correct usage of isNaN() when checking for NaN values.
  • Comprehensive NaN Checks: The rule identifies incorrect comparisons with NaN in binary expressions (e.g., ==, ===, !=, !==, <, >, <=, >=), switch statement discriminants, and case clauses.
  • Configurable Options: Two options, enforceForSwitchCase (default true) and enforceForIndexOf (default false), allow customization of the rule's behavior for switch statements and indexOf/lastIndexOf calls, respectively.
  • Documentation and Testing: The new rule includes dedicated documentation explaining its purpose, options, and providing examples of correct and incorrect code, along with comprehensive unit tests.
Changelog
  • internal/config/config.go
    • Imported the new use_isnan rule package.
    • Registered the use-isnan rule in the global rule registry.
  • internal/rules/use_isnan/use_isnan.go
    • Added the use_isnan rule implementation, including logic for detecting NaN comparisons in binary expressions, switch statements, and indexOf/lastIndexOf methods.
    • Implemented isNaNIdentifier helper function to check for NaN or Number.NaN identifiers.
    • Included parseOptions function to handle rule configuration for enforceForSwitchCase and enforceForIndexOf.
  • internal/rules/use_isnan/use_isnan.md
    • Created documentation for the use-isnan rule, detailing its purpose, options, and providing code examples.
  • internal/rules/use_isnan/use_isnan_test.go
    • Added unit tests for the use-isnan rule, covering various valid and invalid code scenarios and option configurations.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new use-isnan rule tests.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/use-isnan.test.ts.snap
    • Generated snapshot tests for the use-isnan rule's error reporting.
  • packages/rslint-test-tools/tests/eslint/rules/use-isnan.test.ts
    • Created ESLint-style rule tester for the use-isnan rule with basic valid and invalid cases.
Activity
  • No specific human activity (comments, reviews) has been recorded yet for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request ports the use-isnan ESLint rule to rslint. The implementation is well-structured, including comprehensive rule logic, documentation, and tests. I have two minor suggestions: one to use a more idiomatic Go function for string formatting in the rule's implementation, and another to remove a redundant test file entry from the configuration. Overall, this is a solid contribution.

Comment thread internal/rules/use_isnan/use_isnan.go
Comment thread packages/rslint-test-tools/rstest.config.mts Outdated
@fansenze fansenze force-pushed the feat/port-rule-use-isnan-20260317 branch 2 times, most recently from 35803df to fea92e1 Compare March 17, 2026 10:29
@fansenze fansenze force-pushed the feat/port-rule-use-isnan-20260317 branch 3 times, most recently from 8031680 to aea70fd Compare March 18, 2026 02:58
@fansenze fansenze force-pushed the feat/port-rule-use-isnan-20260317 branch from aea70fd to dee68de Compare April 6, 2026 14:02
@fansenze fansenze force-pushed the feat/port-rule-use-isnan-20260317 branch from dee68de to 44740d3 Compare April 6, 2026 14:15
@fansenze fansenze merged commit dcd3ad8 into main Apr 6, 2026
10 checks passed
@fansenze fansenze deleted the feat/port-rule-use-isnan-20260317 branch April 6, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant