Skip to content

Commit 4244521

Browse files
committed
Add test for no-primitive-constructors rule
1 parent f4f975e commit 4244521

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function(context) {
3131
node,
3232
name,
3333
'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): ' +
3535
'\'\' + value'
3636
);
3737
break;

0 commit comments

Comments
 (0)