Skip to content

feat: new rule no-useless-coaleascing#704

Open
ColemanDunn wants to merge 5 commits intooxc-project:mainfrom
ColemanDunn:no-useless-coalescing
Open

feat: new rule no-useless-coaleascing#704
ColemanDunn wants to merge 5 commits intooxc-project:mainfrom
ColemanDunn:no-useless-coalescing

Conversation

@ColemanDunn
Copy link

@ColemanDunn ColemanDunn commented Feb 20, 2026

Implements #703

Apologies if opening a PR for a rule like this is a bit hasty, but I wanted to get a proof of concept out to support my issue

AI disclosure: I used codex to help me implement the rules and attempt to match the codebase

quick preview on when this rule is triggered:

type User = {
  name?: string;
  arr?: string[];
};

declare const user: User | undefined;
declare const alwaysString: string;
declare const alwaysArray: string[];
declare const maybeString: string | undefined;
declare const maybeArray: string[] | undefined;

// user.name
const sample1 = user?.name || undefined; // triggers with detectFalsyValues

// always string
const sample2 = alwaysString || ""; // triggers rule
const sample3 = alwaysString || undefined;
const sample4 = alwaysString ?? ""; // triggers rule        -------- triggers no-unnecessary-condition
const sample5 = alwaysString ?? undefined; // triggers rule  -------- triggers no-unnecessary-condition

// maybe string
const sample6 = maybeString || "";
const sample7 = maybeString || undefined; // triggers with detectFalsyValues
const sample8 = maybeString ?? "";
const sample9 = maybeString ?? undefined; // triggers rule

// always array
const sample10 = alwaysArray || []; // triggers rule         -------- triggers no-unnecessary-condition
const sample11 = alwaysArray || undefined; // triggers rule   -------- triggers no-unnecessary-condition
const sample12 = alwaysArray ?? []; // triggers rule         -------- triggers no-unnecessary-condition
const sample13 = alwaysArray ?? undefined; // triggers rule   -------- triggers no-unnecessary-condition

// maybe array
const sample14 = maybeArray || [];
const sample15 = maybeArray || undefined; // triggers rule
const sample16 = maybeArray ?? [];
const sample17 = maybeArray ?? undefined; // triggers rule

// extra ones (to demonstrate no false positives (for this example) etc.)
const sample18 = maybeString || maybeArray;
const sample19 = maybeArray || maybeString;

const sample20 = maybeString || maybeArray || undefined; // triggers with detectFalsyValues
const sample21 = maybeArray || maybeString || undefined; // triggers with detectFalsyValues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant