Add test for no-primitive-constructors rule
Andrew Clark committed
Feb 28, 2017 at 16:17 UTC
7d5cc2eee3aec0ec3871c56cee9ba7cc8744fcd8
2 files changed
+51
-1
eslint-rules/__tests__/no-primitive-constructors-test.js
new
+50
@@ -0,0 +1,50 @@
1
+/**
2
+ * Copyright 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @emails react-core
10
+ */
11
+
12
+'use strict';
13
+
14
+var rule = require('../no-primitive-constructors');
15
+var RuleTester = require('eslint').RuleTester;
16
+var ruleTester = new RuleTester();
17
+
18
+ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
19
+ valid: [
20
+ '!!obj',
21
+ "'' + obj",
22
+ '+string',
23
+ ],
24
+ invalid: [
25
+ {
26
+ code: 'Boolean(obj)',
27
+ errors: [
28
+ {
29
+ message: 'Do not use the Boolean constructor. To cast a value to a boolean, use double negation: !!value',
30
+ },
31
+ ],
32
+ },
33
+ {
34
+ code: 'String(obj)',
35
+ errors: [
36
+ {
37
+ message: 'Do not use the String constructor. To cast a value to a string, concat it with the empty string (unless it\'s a symbol, which has different semantics): \'\' + value',
38
+ },
39
+ ],
40
+ },
41
+ {
42
+ code: 'Number(string)',
43
+ errors: [
44
+ {
45
+ message: 'Do not use the Number constructor. To cast a value to a number, use the plus operator: +value',
46
+ },
47
+ ],
48
+ },
49
+ ],
50
+});
eslint-rules/no-primitive-constructors.js
+1
-1
@@ -31,7 +31,7 @@ module.exports = function(context) {
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): ' +
34
+ '(unless it\'s a symbol, which has different semantics): ' +
35
'\'\' + value'
36
);
37
break;