-
Notifications
You must be signed in to change notification settings - Fork 48.3k
/
Copy pathwarning-args-test.internal.js
92 lines (89 loc) · 2.25 KB
/
warning-args-test.internal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
const rule = require('../warning-args');
const {RuleTester} = require('eslint');
const ruleTester = new RuleTester();
ruleTester.run('eslint-rules/warning-args', rule, {
valid: [
"console.error('hello, world');",
"console.error('expected %s, got %s', 42, 24);",
'arbitraryFunction(a, b)',
],
invalid: [
{
code: 'console.error(null);',
errors: [
{
message:
'The first argument to console.error must be a string literal',
},
],
},
{
code: 'console.warn(null);',
errors: [
{
message:
'The first argument to console.warn must be a string literal',
},
],
},
{
code: 'var g = 5; console.error(g);',
errors: [
{
message:
'The first argument to console.error must be a string literal',
},
],
},
{
code: "console.error('expected %s, got %s');",
errors: [
{
message:
'Expected 3 arguments in call to console.error based on the number of ' +
'"%s" substitutions, but got 1',
},
],
},
{
code: "console.error('foo is a bar under foobar', 'junk argument');",
errors: [
{
message:
'Expected 1 arguments in call to console.error based on the number of ' +
'"%s" substitutions, but got 2',
},
],
},
{
code: "console.error('error!');",
errors: [
{
message:
'The console.error format should be able to uniquely identify this ' +
'warning. Please, use a more descriptive format than: error!',
},
],
},
{
code: "console.error('%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
errors: [
{
message:
'The console.error format should be able to uniquely identify this ' +
'warning. Please, use a more descriptive format than: ' +
'%s %s, %s %s: %s (%s)',
},
],
},
],
});