This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MESSAGE = | |
'Using the delete operator on a property will cause the shape of ' + | |
'the object to change. This will lead to JS engine to de-optimize ' + | |
'read and writes to this object.'; | |
// For now this rule is very pessimistic to limit false positives. It only | |
// covers case of form: delete this.<identifier>; | |
module.exports = function rule(context) { | |
return { | |
UnaryExpression: function(node) { | |
if (node.operator !== 'delete') { | |
return; | |
} | |
var deleteArg = node.argument; | |
if (deleteArg.type !== 'MemberExpression') { | |
return; | |
} | |
var obj = deleteArg.object; | |
var property = deleteArg.property; | |
if (obj.type !== 'ThisExpression') { | |
return; | |
} | |
if (property.type !== 'Identifier') { | |
return; | |
} | |
context.report(node, MESSAGE); | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment