Repository navigation
v0.5.0
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, anifon a value that is always truthy or always falsy. - Stays allowed:
?.and??on genuinely optional values, andwhile (true)as the intentional infinite-loop idiom (allowConstantLoopConditions: "always").checkTypePredicateskeeps 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
ifusually means a stale branch: delete it, or fix the type that made it constant.
How to exempt
// oxlint-disable-next-line no-unnecessary-conditionreportUnusedDisableDirectives: "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.