1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var assert = require('assert');
|
25 |
|
26 | module.exports = function() {};
|
27 |
|
28 | module.exports.prototype = {
|
29 |
|
30 | configure: function(options) {
|
31 | assert(
|
32 | options === true,
|
33 | this.getOptionName() + ' option requires a true value or should be removed'
|
34 | );
|
35 | },
|
36 |
|
37 | getOptionName: function() {
|
38 | return 'requireSpaceAfterObjectKeys';
|
39 | },
|
40 |
|
41 | check: function(file, errors) {
|
42 | file.iterateNodesByType('ObjectExpression', function(node) {
|
43 | node.properties.forEach(function(property) {
|
44 | if (
|
45 | property.type === 'ObjectMethod' &&
|
46 | (property.kind === 'get' || property.kind === 'set')
|
47 | ) {
|
48 | return;
|
49 | }
|
50 |
|
51 | if (property.shorthand ||
|
52 | property.type === 'SpreadProperty') {
|
53 | return;
|
54 | }
|
55 |
|
56 | var token = file.getLastNodeToken(property.key);
|
57 |
|
58 | if (property.computed === true) {
|
59 | token = file.getNextToken(token);
|
60 | }
|
61 |
|
62 | errors.assert.whitespaceBetween({
|
63 | token: token,
|
64 | nextToken: file.getNextToken(token),
|
65 | message: 'Missing space after key'
|
66 | });
|
67 | });
|
68 | });
|
69 | }
|
70 |
|
71 | };
|