-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
guard-for-in.js
38 lines (32 loc) · 2.21 KB
/
guard-for-in.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
/**
* @fileoverview Tests for guard-for-in rule.
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/guard-for-in"),
RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("guard-for-in", rule, {
valid: [
"for (var x in o);",
"for (var x in o) {}",
"for (var x in o) if (x) f();",
"for (var x in o) { if (x) { f(); } }",
"for (var x in o) { if (x) continue; f(); }",
"for (var x in o) { if (x) { continue; } f(); }"
],
invalid: [
{ code: "for (var x in o) { if (x) { f(); continue; } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
{ code: "for (var x in o) { if (x) { continue; f(); } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
{ code: "for (var x in o) { if (x) { f(); } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
{ code: "for (var x in o) { if (x) f(); g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
{ code: "for (var x in o) { foo() }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
{ code: "for (var x in o) foo();", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] }
]
});