runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
314 stars 35 forks source link

Update no-nullable-attribute-binding fix for null attribute #339

Closed AndrewJakubowicz closed 6 months ago

AndrewJakubowicz commented 6 months ago

Context

Fixes: https://github.com/runem/lit-analyzer/issues/317

In versions of Lit >2, ifDefined can handle null and undefined so the explicit null check is no longer required.

Change

Instead of recommending ifDefined(expr === null ? undefined : expr), instead recommend ifDefined(expr) for both undefined and null.

Test

Added message tests to ensure that type detection works correctly, and that the diagnostic message correctly identify either null or undefined. This will make it easier to catch regressions when moving to isTypeAssignableTo in the future.

AndrewJakubowicz commented 6 months ago

Ready for review, cc/ @rictic

rictic commented 6 months ago

Great change!