eslint-plugin-cflint
Version:
ESLint rules for CloudFlare
29 lines (26 loc) • 723 B
JavaScript
/**
* @fileoverview Rule to flag assignment of `this` to other variable names.
* @author Terin Stock
*/
;
var MESSAGE = 'this is assigned to {{name}}';
module.exports = function (context) {
return {
VariableDeclaration: function (node) {
node.declarations.forEach(function (declaration) {
if (declaration.init && declaration.init.type === 'ThisExpression') {
context.report(declaration, MESSAGE, {
name: declaration.id.name
});
}
});
},
AssignmentExpression: function (node) {
if (node.right.type === 'ThisExpression') {
context.report(node, MESSAGE, {
name: node.left.name
});
}
}
};
};