| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @emails react-core |
| 8 | */ |
| 9 | |
| 10 | 'use strict'; |
| 11 | |
| 12 | const rule = require('../no-primitive-constructors'); |
| 13 | const {RuleTester} = require('eslint'); |
| 14 | const ruleTester = new RuleTester(); |
| 15 | |
| 16 | ruleTester.run('eslint-rules/no-primitive-constructors', rule, { |
| 17 | valid: ['!!obj', '+string'], |
| 18 | invalid: [ |
| 19 | { |
| 20 | code: 'Boolean(obj)', |
| 21 | errors: [ |
| 22 | { |
| 23 | message: |
| 24 | 'Do not use the Boolean constructor. To cast a value to a boolean, use double negation: !!value', |
| 25 | }, |
| 26 | ], |
| 27 | }, |
| 28 | { |
| 29 | code: 'new String(obj)', |
| 30 | errors: [ |
| 31 | { |
| 32 | message: |
| 33 | "Do not use `new String()`. Use String() without new (or '' + value for perf-sensitive code).", |
| 34 | }, |
| 35 | ], |
| 36 | }, |
| 37 | { |
| 38 | code: 'Number(string)', |
| 39 | errors: [ |
| 40 | { |
| 41 | message: |
| 42 | 'Do not use the Number constructor. To cast a value to a number, use the plus operator: +value', |
| 43 | }, |
| 44 | ], |
| 45 | }, |
| 46 | ], |
| 47 | }); |