From b9c96cfc73b6e0adcb7b747c40ac40c74995ea7f Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 28 Feb 2017 16:05:38 -0800 Subject: [PATCH] Add caveat about symbols to string error message --- eslint-rules/no-primitive-constructors.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/eslint-rules/no-primitive-constructors.js b/eslint-rules/no-primitive-constructors.js index fcf13c2ccf..887c9ed67a 100644 --- a/eslint-rules/no-primitive-constructors.js +++ b/eslint-rules/no-primitive-constructors.js @@ -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 {