main
js 92 lines 2.25 KB
Raw
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('../warning-args');
13 const {RuleTester} = require('eslint');
14 const ruleTester = new RuleTester();
15
16 ruleTester.run('eslint-rules/warning-args', rule, {
17 valid: [
18 "console.error('hello, world');",
19 "console.error('expected %s, got %s', 42, 24);",
20 'arbitraryFunction(a, b)',
21 ],
22 invalid: [
23 {
24 code: 'console.error(null);',
25 errors: [
26 {
27 message:
28 'The first argument to console.error must be a string literal',
29 },
30 ],
31 },
32 {
33 code: 'console.warn(null);',
34 errors: [
35 {
36 message:
37 'The first argument to console.warn must be a string literal',
38 },
39 ],
40 },
41 {
42 code: 'var g = 5; console.error(g);',
43 errors: [
44 {
45 message:
46 'The first argument to console.error must be a string literal',
47 },
48 ],
49 },
50 {
51 code: "console.error('expected %s, got %s');",
52 errors: [
53 {
54 message:
55 'Expected 3 arguments in call to console.error based on the number of ' +
56 '"%s" substitutions, but got 1',
57 },
58 ],
59 },
60 {
61 code: "console.error('foo is a bar under foobar', 'junk argument');",
62 errors: [
63 {
64 message:
65 'Expected 1 arguments in call to console.error based on the number of ' +
66 '"%s" substitutions, but got 2',
67 },
68 ],
69 },
70 {
71 code: "console.error('error!');",
72 errors: [
73 {
74 message:
75 'The console.error format should be able to uniquely identify this ' +
76 'warning. Please, use a more descriptive format than: error!',
77 },
78 ],
79 },
80 {
81 code: "console.error('%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
82 errors: [
83 {
84 message:
85 'The console.error format should be able to uniquely identify this ' +
86 'warning. Please, use a more descriptive format than: ' +
87 '%s %s, %s %s: %s (%s)',
88 },
89 ],
90 },
91 ],
92 });