| 1 | import rule from "../../lib/rules/no-unused-expressions.cjs"; |
| 2 | import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester.js"; |
| 3 | |
| 4 | const ruleTester = new RuleTester(); |
| 5 | ruleTester.run("@babel/no-unused-expressions", rule, { |
| 6 | valid: [ |
| 7 | "let a = do { if (foo) { foo.bar; } }", |
| 8 | "let a = do { foo; }", |
| 9 | "let a = do { let b = 2; foo; }", |
| 10 | "let a = do { (foo + 1); }", |
| 11 | "let a = do { if (foo) { if (foo.bar) { foo.bar; } } }", |
| 12 | "let a = do { if (foo) { if (foo.bar) { foo.bar; } else if (foo.baz) { foo.baz; } } }", |
| 13 | "foo.bar?.();", |
| 14 | ], |
| 15 | invalid: [ |
| 16 | { |
| 17 | code: "let a = do { foo; let b = 2; }", |
| 18 | errors: [ |
| 19 | { |
| 20 | message: |
| 21 | "Expected an assignment or function call and instead saw an expression.", |
| 22 | type: "ExpressionStatement", |
| 23 | }, |
| 24 | ], |
| 25 | }, |
| 26 | { |
| 27 | code: "let a = do { if (foo) { foo.bar } else { a; bar.foo } }", |
| 28 | errors: [ |
| 29 | { |
| 30 | message: |
| 31 | "Expected an assignment or function call and instead saw an expression.", |
| 32 | type: "ExpressionStatement", |
| 33 | }, |
| 34 | ], |
| 35 | }, |
| 36 | ], |
| 37 | }); |