eslint warn on non null assertions
Summary: Let's ban the non null assertion syntax `maybeNull!` as it is unsafe and can cause unexpected behavior. Ideally this should be an error or require a comment explaining why the value cannot be nullish. Though, there are 468 occurrences around the codebase and it is not worth it to manually go around fixing it now. Thus I used a warn to still warn developers to avoid the use where possible. Last week I spend over an hour on debugging something where the code was null-asserted as the developer thought the value could never be null while in reallity it could. Adding a runtime check in this case sounds reasonable. rule docs https://typescript-eslint.io/rules/no-non-null-assertion/ Reviewed By: nikoant Differential Revision: D45773327 fbshipit-source-id: 9e8a40af353ce979f469ffaedd8e777d72500dab
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a96caacb2b
commit
4ad54db723
@@ -220,6 +220,7 @@ module.exports = {
|
||||
leadingUnderscore: 'allow',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-non-null-assertion': 'warn',
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user