Skip to content

fix: align no-unnecessary-boolean-literal-compare with ESLint implementation#568

Merged
fansenze merged 1 commit intomainfrom
fix/no-unnecessary-boolean-literal-compare-20260324
Mar 25, 2026
Merged

fix: align no-unnecessary-boolean-literal-compare with ESLint implementation#568
fansenze merged 1 commit intomainfrom
fix/no-unnecessary-boolean-literal-compare-20260324

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

Summary

Fix auto-fix output discrepancies in @typescript-eslint/no-unnecessary-boolean-literal-compare where rslint diverged from the original ESLint rule:

  • Leading trivia in fix text: When the boolean literal was on the left side (e.g., false !== b), the fix included leading whitespace from the AST node's Pos(). Fixed by using TrimNodeTextRange to skip trivia.
  • Unwanted parentheses in fix text: The TypeScript AST wraps expressions in ParenthesizedExpression nodes (unlike ESTree which is parenthesis-transparent), causing fix output like (b ?? false) instead of b ?? false. Fixed by using SkipParentheses before extracting replacement text and checking precedence.
  • Comprehensive test coverage: Added 20 new invalid test cases covering all operator variants (==/!=), literal-on-left positions, false literal type, both nullable options false, nullable with literal on left, and the combined ! + ?? true fix path. Go and JS tests are fully in sync (22 valid + 47 invalid = 69 total).

Verified via exhaustive 37-case end-to-end comparison: detection lines and fix outputs are identical between rslint and ESLint.

Related Links

N/A

Checklist

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

@gemini-code-assist
Copy link
Copy Markdown

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 refines the auto-fix behavior of the @typescript-eslint/no-unnecessary-boolean-literal-compare rule within rslint. The changes ensure that the generated fix outputs are consistent with the original ESLint implementation by accurately handling leading whitespace and unnecessary parentheses in expressions, thereby improving the reliability and correctness of code transformations.

Highlights

  • Fix auto-fix output for leading trivia: Corrected an issue where auto-fix included leading whitespace when the boolean literal was on the left side of a comparison, by using TrimNodeTextRange.
  • Handle unwanted parentheses in fix text: Addressed the problem of TypeScript AST wrapping expressions in ParenthesizedExpression nodes, which led to incorrect fix outputs like (b ?? false), by using SkipParentheses.
  • Expanded test coverage: Introduced 20 new invalid test cases to thoroughly cover various operator variants, literal positions, and nullable options, ensuring full sync between Go and JS tests.
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.

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

@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 aligns the no-unnecessary-boolean-literal-compare rule with its ESLint counterpart. The changes modify the autofix logic to correctly handle parenthesized expressions and leading trivia by using ast.SkipParentheses and utils.TrimNodeTextRange. Additionally, the test suite is substantially expanded with numerous new test cases to cover more edge cases and ensure behavioral parity with ESLint. The changes appear correct and well-tested.

@fansenze fansenze force-pushed the fix/no-unnecessary-boolean-literal-compare-20260324 branch from 1a3c25a to 198968f Compare March 24, 2026 11:07
…mentation

Fix auto-fix output discrepancies where rslint produced extra whitespace
or unwanted parentheses compared to the original ESLint rule, and add
comprehensive test coverage for all operator/literal/type/config combinations.
@fansenze fansenze force-pushed the fix/no-unnecessary-boolean-literal-compare-20260324 branch from 198968f to 452e312 Compare March 25, 2026 02:27
@fansenze fansenze merged commit 20fa43b into main Mar 25, 2026
14 checks passed
@fansenze fansenze deleted the fix/no-unnecessary-boolean-literal-compare-20260324 branch March 25, 2026 02:47
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.

2 participants