Add caveat about symbols to string error message

This commit is contained in:
Andrew Clark
2017-02-28 18:57:06 -08:00
parent 6ac5fd3c2b
commit b9c96cfc73
+16 -6
View File
@@ -12,20 +12,30 @@
'use strict';
module.exports = function(context) {
function report(node, name, msg) {
context.report(node, `Do not use the ${name} constructor. ${msg}`);
}
function check(node) {
const name = node.callee.name;
let msg = null;
switch (name) {
case 'Boolean':
msg = 'To cast a value to a boolean, use double negation: !!value';
report(
node,
name,
'To cast a value to a boolean, use double negation: !!value'
);
break;
case 'String':
msg = 'To cast a value to a string, concat it with the empty string: \'\' + value';
report(
node,
name,
'To cast a value to a string, concat it with the empty string ' +
'(unless it\'s a symbol, which have different semantics): ' +
'\'\' + value'
);
break;
}
if (msg) {
context.report(node, `Do not use the ${name} constructor. ${msg}`);
}
}
return {