0

WebUI: Enforce querySelector<Type>() pattern via ESLint, part 7 (last)

In this part, amending the existing checks to also catch such cases.
All violations have been fixed in precursor CLs.

A common misuse of querySelector/querySelectorAll is to use a type cast,
like
this.shadowRoot.querySelector(...) as Type

instead of leveraging the type parameter, like
this.shadowRoot.querySelector<Type>(...)

The previously added ESLint checks miss cases where a "not null"
typecast exists, like
this.shadowRoot.querySelector(...)! as Type

Fixed: 1521107
Change-Id: I0bebe973d3467b92c53525ac4bc0337814481bde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5502593
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1294846}
This commit is contained in:
dpapad
2024-05-01 14:03:17 +00:00
committed by Chromium LUCI CQ
parent 5db8a14cab
commit a5b94b8fa0

@ -73,6 +73,11 @@ module.exports = {
'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelector$/]',
'message': 'Don\'t use \'querySelector(...) as Type\'. Use the type parameter, \'querySelector<Type>(...)\' instead',
},
{
// https://google.github.io/styleguide/tsguide.html#return-type-only-generics
'selector': 'TSAsExpression > TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelector$/]',
'message': 'Don\'t use \'querySelector(...)! as Type\'. Use the type parameter, \'querySelector<Type>(...)\', followed by an assertion instead',
},
{
// https://google.github.io/styleguide/tsguide.html#return-type-only-generics
'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]',