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 | var assert = require('assert');
|
32 |
|
33 | module.exports = function() {};
|
34 |
|
35 | module.exports.prototype = {
|
36 |
|
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 'requireSpacesInsideImportedObjectBraces';
|
46 | },
|
47 |
|
48 | check: function(file, errors) {
|
49 | file.iterateNodesByType(['ImportDeclaration'], function(node) {
|
50 |
|
51 | if (!node.specifiers) {
|
52 | return;
|
53 | }
|
54 |
|
55 | node.specifiers.forEach(function(specifier) {
|
56 |
|
57 | if (specifier.type !== 'ImportSpecifier') {
|
58 | return;
|
59 | }
|
60 |
|
61 | var maybeOpeningBrace = file.getPrevToken(specifier.getFirstToken());
|
62 | var maybeClosingBrace = file.getNextToken(specifier.getLastToken());
|
63 |
|
64 | if (maybeOpeningBrace.value === '{') {
|
65 | errors.assert.spacesBetween({
|
66 | token: maybeOpeningBrace,
|
67 | nextToken: specifier.getFirstToken(),
|
68 | exactly: 1,
|
69 | message: 'One space required after opening curly brace'
|
70 | });
|
71 | }
|
72 |
|
73 | if (maybeClosingBrace.value === '}') {
|
74 | errors.assert.spacesBetween({
|
75 | token: specifier.getLastToken(),
|
76 | nextToken: maybeClosingBrace,
|
77 | exactly: 1,
|
78 | message: 'One space required before closing curly brace'
|
79 | });
|
80 | }
|
81 | });
|
82 | });
|
83 | }
|
84 | };
|