]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-confusing-arrow.js
58724d9ace29a8971ff6eeb578b856765a268691
[pve-eslint.git] / eslint / tests / lib / rules / no-confusing-arrow.js
1 /**
2 * @fileoverview Tests for no-confusing-arrow rule.
3 * @author Jxck <https://github.com/Jxck>
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-confusing-arrow"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
20
21 ruleTester.run("no-confusing-arrow", rule, {
22 valid: [
23 "a => { return 1 ? 2 : 3; }",
24 { code: "a => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
25
26 "var x = a => { return 1 ? 2 : 3; }",
27 { code: "var x = a => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
28
29 "var x = (a) => { return 1 ? 2 : 3; }",
30 { code: "var x = (a) => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
31
32 "var x = a => (1 ? 2 : 3)",
33 { code: "var x = a => (1 ? 2 : 3)", options: [{ allowParens: true }] }
34 ],
35 invalid: [
36 {
37 code: "a => 1 ? 2 : 3",
38 output: "a => (1 ? 2 : 3)",
39 errors: [{ messageId: "confusing" }]
40 },
41 {
42 code: "a => 1 ? 2 : 3",
43 output: "a => (1 ? 2 : 3)",
44 options: [{ allowParens: true }],
45 errors: [{ messageId: "confusing" }]
46 },
47 {
48 code: "a => 1 ? 2 : 3",
49 output: null,
50 options: [{ allowParens: false }],
51 errors: [{ messageId: "confusing" }]
52 },
53 {
54 code: "var x = a => 1 ? 2 : 3",
55 output: "var x = a => (1 ? 2 : 3)",
56 errors: [{ messageId: "confusing" }]
57 },
58 {
59 code: "var x = a => 1 ? 2 : 3",
60 output: "var x = a => (1 ? 2 : 3)",
61 options: [{ allowParens: true }],
62 errors: [{ messageId: "confusing" }]
63 },
64 {
65 code: "var x = a => 1 ? 2 : 3",
66 output: null,
67 options: [{ allowParens: false }],
68 errors: [{ messageId: "confusing" }]
69 },
70 {
71 code: "var x = (a) => 1 ? 2 : 3",
72 output: "var x = (a) => (1 ? 2 : 3)",
73 errors: [{ messageId: "confusing" }]
74 }
75 ]
76 });