sindresorhus/eslint-plugin-unicorn
Rule proposal: No computed object property existence check
Chiusa
#1096 aperta il 5 feb 2021
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
If property name is a variable, this may leads to unexpected result.
Fail
if (foo[bar]) {}
if (bar in foo) {}
In these cases if bar is 'toString', 'constructor' etc, it will be true.
Pass
if (foo[bar] === true) {}
if (Object.prototype.hasOwnProperty.call(foo, bar)) {}
Problem: foo maybe an array, static check can't know.