Skip to content

v0.5.0

Choose a tag to compare

@PerfectPan PerfectPan released this 09 Oct 07:48
· 15 commits to main since this release
772215b

What changed

oxlint.json enables no-unnecessary-condition as an error with { "allowConstantLoopConditions": "always" } (type-aware; it runs through the existing typeAware pass):

  • Fails: a condition, optional chain or ?? whose outcome the types already decide — ?. on a value that is never nullish, ?? on a non-nullable left-hand side, an if on a value that is always truthy or always falsy.
  • Stays allowed: ?. and ?? on genuinely optional values, and while (true) as the intentional infinite-loop idiom (allowConstantLoopConditions: "always"). checkTypePredicates keeps its default (false).

vite-plus.d.ts describes the new rule; the version bump and README are updated. No other rule changed.

What newly fails

interface Config {
  name: string;
}

export function label(config: Config): string {
  return config?.name ?? "unnamed";
  // error typescript(no-unnecessary-condition): Unnecessary optional chain on a non-nullish value.
  // error typescript(no-unnecessary-condition): Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined.
}

How to fix

  • Drop the ?. or ?? when the type says the value is always present.
  • If the value really can be missing, make the type say so (name?: string, or a schema that marks the field optional); the rule then accepts the check.
  • An always-true or always-false if usually means a stale branch: delete it, or fix the type that made it constant.

How to exempt

// oxlint-disable-next-line no-unnecessary-condition

reportUnusedDisableDirectives: "error" fails the comment once the code no longer needs it. A repository can also turn the rule off in its own config; local settings win over the shared ones.

Impact on consumers

Measured with oxlint 1.86.0 and a type-aware config that enables only this rule, over authored sources on each default branch:

Repository Hits
agent-kit 12
project-template-rush 0

The other consumers are measured when they adopt the tag.