-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
quote-props.js
78 lines (52 loc) · 2.14 KB
/
quote-props.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
/**
* @fileoverview Tests for quote-props rule.
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
/*jshint node:true*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var vows = require("vows"),
assert = require("assert"),
sinon = require("sinon"),
eslint = require("../../../lib/eslint");
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
var RULE_ID = "quote-props";
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
vows.describe(RULE_ID).addBatch({
"when evaluating `var x = { foo: 42 }`": {
topic: "var x = { foo: 42 }",
"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, "Non-quoted property `foo` found.");
assert.include(messages[0].node.type, "Property");
assert.include(messages[0].node.key.name, "foo");
}
},
"when evaluating `var x = { 'foo': 42 }`": {
topic: "var x = { 'foo': 42 }",
"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 `var x = { \"foo\": 42 }`": {
topic: "var x = { \"foo\": 42 }",
"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);