UNPKG

1.26 kBJavaScriptView Raw
1/**
2 * Disallows placing object keys on new line
3 *
4 * Type: `Boolean`
5 *
6 * Value: `true`
7 *
8 * #### Example
9 *
10 * ```js
11 * "disallowObjectKeysOnNewLine": true
12 * ```
13 *
14 * ##### Valid
15 *
16 * ```js
17 * var a = {
18 * b: 'b', c: 'c'
19 * };
20 * ```
21 *
22 * ##### Invalid
23 *
24 * ```js
25 * var a = {
26 * b: 'b',
27 * c: 'c'
28 * };
29 * ```
30 */
31
32var assert = require('assert');
33
34module.exports = function() {};
35
36module.exports.prototype = {
37 configure: function(options) {
38 assert(
39 options === true,
40 this.getOptionName() + ' option requires a true value or should be removed'
41 );
42 },
43
44 getOptionName: function() {
45 return 'disallowObjectKeysOnNewLine';
46 },
47
48 check: function(file, errors) {
49 file.iterateNodesByType('ObjectExpression', function(node) {
50 var properties = node.properties;
51 for (var i = 1; i < properties.length; i++) {
52 var propertyNode = properties[i];
53
54 errors.assert.sameLine({
55 token: propertyNode.getPreviousCodeToken(),
56 nextToken: propertyNode.getFirstToken(),
57 message: 'Object keys should be on the same line'
58 });
59 }
60 });
61 }
62};