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 | var assert = require('assert');
|
41 |
|
42 | module.exports = function() {};
|
43 |
|
44 | module.exports.prototype = {
|
45 |
|
46 | configure: function(options) {
|
47 | assert(
|
48 | options === true,
|
49 | this.getOptionName() + ' option requires a true value or should be removed'
|
50 | );
|
51 | },
|
52 |
|
53 | getOptionName: function() {
|
54 | return 'requireLineBreakAfterVariableAssignment';
|
55 | },
|
56 |
|
57 | check: function(file, errors) {
|
58 | var lastDeclaration;
|
59 | file.iterateNodesByType('VariableDeclaration', function(node) {
|
60 | if (node.parentElement.type === 'ForStatement' ||
|
61 | node.parentElement.type === 'ForInStatement' ||
|
62 | node.parentElement.type === 'ForOfStatement') {
|
63 | return;
|
64 | }
|
65 |
|
66 | for (var i = 0; i < node.declarations.length; i++) {
|
67 | var thisDeclaration = node.declarations[i];
|
68 | if (thisDeclaration.parentElement.kind === 'var' ||
|
69 | thisDeclaration.parentElement.kind === 'let' ||
|
70 | thisDeclaration.parentElement.kind === 'const') {
|
71 | if (lastDeclaration && lastDeclaration.init) {
|
72 | errors.assert.differentLine({
|
73 | token: lastDeclaration,
|
74 | nextToken: thisDeclaration,
|
75 | message: 'Variable assignments should be followed by new line'
|
76 | });
|
77 | }
|
78 | lastDeclaration = thisDeclaration;
|
79 | }
|
80 | }
|
81 | });
|
82 | }
|
83 |
|
84 | };
|