WebUI: Prevent "not null" cast for querySelectorAll() calls, part 2.
A "!" not-null operator after querySelectorAll() is unnecessary since, unlike querySelector(), it always returns a non-null value. In this part adding an ESLint check to automatically catch such violations. Bug: 720034 Change-Id: I0460549c0038d6cf56d2aeb9db13ebf5ea7d3447 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5250843 Commit-Queue: John Lee <johntlee@chromium.org> Reviewed-by: John Lee <johntlee@chromium.org> Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org> Cr-Commit-Position: refs/heads/main@{#1254271}
This commit is contained in:
@ -76,6 +76,11 @@ module.exports = {
|
||||
// https://google.github.io/styleguide/tsguide.html#return-type-only-generics
|
||||
'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]',
|
||||
'message': 'Don\'t use \'querySelectorAll(...) as Type\'. Use the type parameter, \'querySelectorAll<Type>(...)\' instead',
|
||||
},
|
||||
{
|
||||
// Prevent a common misuse of "!" operator.
|
||||
"selector": "TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]",
|
||||
"message": "Remove unnecessary \"!\" non-null operator after querySelectorAll(). It always returns a non-null result",
|
||||
}],
|
||||
'no-throw-literal': 'error',
|
||||
'no-trailing-spaces': 'error',
|
||||
|
Reference in New Issue
Block a user