Add caveat about symbols to string error message
Andrew Clark committed
Feb 28, 2017 at 16:05 UTC
b9c96cfc73b6e0adcb7b747c40ac40c74995ea7f
1 file changed
+16
-6
eslint-rules/no-primitive-constructors.js
+16
-6
@@ -12,20 +12,30 @@
12
'use strict';
13
14
module.exports = function(context) {
15
+ function report(node, name, msg) {
16
+ context.report(node, `Do not use the ${name} constructor. ${msg}`);
17
+ }
18
+
19
function check(node) {
20
const name = node.callee.name;
17
- let msg = null;
21
switch (name) {
22
case 'Boolean':
20
- msg = 'To cast a value to a boolean, use double negation: !!value';
23
+ report(
24
+ node,
25
+ name,
26
+ 'To cast a value to a boolean, use double negation: !!value'
27
+ );
28
break;
29
case 'String':
23
- msg = 'To cast a value to a string, concat it with the empty string: \'\' + value';
30
+ report(
31
+ node,
32
+ name,
33
+ 'To cast a value to a string, concat it with the empty string ' +
34
+ '(unless it\'s a symbol, which have different semantics): ' +
35
+ '\'\' + value'
36
+ );
37
break;
38
}
26
- if (msg) {
27
- context.report(node, `Do not use the ${name} constructor. ${msg}`);
28
- }
39
}
40
41
return {