Skip to content

feat(ts): implement unnecessaryLogicalComparisons rule#2259

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-unnecessary-logical-comparisons-rule
Draft

feat(ts): implement unnecessaryLogicalComparisons rule#2259
Copilot wants to merge 3 commits intomainfrom
copilot/add-unnecessary-logical-comparisons-rule

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Implements lint rule to detect and simplify unnecessary boolean literal comparisons in TypeScript code.

Changes

  • Rule implementation (packages/ts/src/rules/unnecessaryLogicalComparisons.ts)

    • Detects equality comparisons with boolean literals
    • Supports both strict (===, !==) and loose (==, !=) operators
    • Provides automatic fixes with proper negation handling
    • Unwraps parenthesized expressions in simplified output
  • Test coverage (packages/ts/src/rules/unnecessaryLogicalComparisons.test.ts)

    • 33 test cases covering all operator and operand combinations
    • Edge cases: parenthesized expressions, member access, array indexing
  • Registration

    • Added to plugin exports in alphabetical order
    • Marked as implemented in comparisons data

Examples

// ❌ Unnecessary comparisons
if (isActive === true) { }
const result = flag !== false;
while (condition == true) { }

// ✅ Simplified
if (isActive) { }
const result = flag;
while (condition) { }
// ❌ With negation
if (isActive === false) { }
const result = flag !== true;

// ✅ Simplified
if (!isActive) { }
const result = !flag;

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • typescript-eslint.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>🚀 Feature: Implement unnecessaryLogicalComparisons rule (TypeScript)</issue_title>
<issue_description>### Feature Request Checklist

Overview

Per flint.fyi/rules, Flint is intended to have a unnecessaryLogicalComparisons rule in the TypeScript plugin (ts). It'll behave roughly equivalently to the existing implementations in other linters to start. This issue tracks adding that rule.

Adding this rule will entail creating the following new source files:

  • packages/ts/src/rules/unnecessaryLogicalComparisons.ts: implementation of the rule itself
  • packages/ts/src/rules/unnecessaryLogicalComparisons.test.ts: tests for the rule
  • packages/site/src/content/docs/rules/ts/unnecessaryLogicalComparisons.mdx: documentation of the rule

Additionally, the following files will need to be edited:

  • packages/comparisons/src/data.json: Comparisons data will need to mention the rule is now "status": "implemented"
  • packages/ts/src/plugin.ts: Included rules should have the new one inserted in alphabetical order

Additional Info

Existing rules in other linters:

❤️‍🔥</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flint Ready Ready Preview, Comment Feb 1, 2026 4:54pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: dd8b41f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI changed the title [WIP] Add unnecessaryLogicalComparisons rule to TypeScript plugin feat(ts): implement unnecessaryLogicalComparisons rule Feb 1, 2026
Copilot AI requested a review from JoshuaKGoldberg February 1, 2026 16:54
@JoshuaKGoldberg
Copy link
Collaborator

The backing typescript-eslint rule is a good bit more complex. Marking as blocked until we have more built-up practices around Flint rules.

@JoshuaKGoldberg JoshuaKGoldberg added the status: blocked Waiting for something else to be resolved 🙅 label Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: blocked Waiting for something else to be resolved 🙅

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: Implement unnecessaryLogicalComparisons rule (TypeScript)

2 participants