forked from eslint/eslint
/
no-dangle.js
106 lines (73 loc) · 3.23 KB
/
no-dangle.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @fileoverview Tests for no-dangle rule.
* @author Ian Christian Myers
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var vows = require("vows"),
assert = require("assert"),
eslint = require("../../../lib/eslint");
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
var RULE_ID = "no-dangle";
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
vows.describe(RULE_ID).addBatch({
"when evaluating object literal with a dangling comma": {
topic: "var foo = { bar: \"baz\", }",
"should report a violation": function(topic) {
var config = { rules: {} };
config.rules[RULE_ID] = 1;
var messages = eslint.verify(topic, config);
assert.equal(messages.length, 1);
assert.equal(messages[0].ruleId, RULE_ID);
assert.equal(messages[0].message, "Found trailing comma in object literal.");
assert.include(messages[0].node.type, "ObjectExpression");
}
},
"when evaluating object literal passed to a function with a dangling comma": {
topic: "foo({ bar: \"baz\", qux: \"quux\", });",
"should report a violation": function(topic) {
var config = { rules: {} };
config.rules[RULE_ID] = 1;
var messages = eslint.verify(topic, config);
assert.equal(messages.length, 1);
assert.equal(messages[0].ruleId, RULE_ID);
assert.equal(messages[0].message, "Found trailing comma in object literal.");
assert.include(messages[0].node.type, "ObjectExpression");
}
},
"when evaluating object literal without a dangling comma": {
topic: "var foo = { bar: \"baz\" }",
"should not report a violation": function(topic) {
var config = { rules: {} };
config.rules[RULE_ID] = 1;
var messages = eslint.verify(topic, config);
assert.equal(messages.length, 0);
}
},
"when evaluating array literal with a dangling comma": {
topic: "var foo = [ \"baz\", ]",
"should report a violation": function(topic) {
var config = { rules: {} };
config.rules[RULE_ID] = 1;
var messages = eslint.verify(topic, config);
assert.equal(messages.length, 1);
assert.equal(messages[0].ruleId, RULE_ID);
assert.equal(messages[0].message, "Found trailing comma in object literal.");
assert.include(messages[0].node.type, "ArrayExpression");
}
},
"when evaluating array literal without a dangling comma": {
topic: "var foo = [ \"baz\" ]",
"should not report a violation": function(topic) {
var config = { rules: {} };
config.rules[RULE_ID] = 1;
var messages = eslint.verify(topic, config);
assert.equal(messages.length, 0);
}
}
}).export(module);