forked from jscs-dev/node-jscs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-indentation.js
105 lines (98 loc) · 2.58 KB
/
validate-indentation.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var Checker = require('../../lib/checker');
var assert = require('assert');
var fs = require('fs');
var fixture = fs.readFileSync(__dirname + '/../data/validate-indentation.js', 'utf8');
describe('rules/validate-indentation', function() {
var checker;
beforeEach(function() {
checker = new Checker();
checker.registerDefaultRules();
});
function checkErrors(string, expectedErrorLines) {
var errors = checker.checkString(string).getErrorList().sort(function(a, b) {
return a.line - b.line;
});
errors.forEach(function(error, i) {
assert(error.line === expectedErrorLines[i], 'did not expect an error on line ' + error.line);
});
expectedErrorLines.forEach(function(line, i) {
assert(errors[i] && errors[i].line === line, 'expected an error on line ' + line);
});
assert(expectedErrorLines.length === errors.length);
}
it('should validate tab indentation properly', function() {
checker.configure({ validateIndentation: '\t' });
checkErrors('if (a){\n\tb=c;\n\t\tc=d;\ne=f;\n}', [3, 4]);
});
it('should validate 4 spaces indentation properly', function() {
checker.configure({ validateIndentation: 4 });
checkErrors('if (a){\n b=c;\n c=d;\n e=f;\n}', [3, 4]);
});
it('should validate 2 spaces indentation properly', function() {
// maxErrors set to avoid this test failing with the default value
checker.configure({ validateIndentation: 2, maxErrors: 500 });
checkErrors(fixture, [
5,
10,
11,
15,
16,
23,
29,
30,
36,
38,
39,
40,
46,
54,
114,
120,
124,
127,
134,
139,
145,
149,
152,
159,
168,
176,
184,
186,
200,
202,
214,
218,
220,
330,
331,
371,
372,
375,
376,
379,
380,
386,
388,
399,
401,
405,
407,
414,
416,
421,
423,
440,
441,
447,
448,
454,
455,
461,
462,
467,
472
]);
});
});