1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var assert = require('assert');
|
21 |
|
22 | module.exports = function() {};
|
23 |
|
24 | module.exports.prototype = {
|
25 |
|
26 | configure: function(options) {
|
27 | this._allowComments = true;
|
28 |
|
29 | if (typeof options === 'number') {
|
30 | assert(
|
31 | typeof options === 'number',
|
32 | this.getOptionName() + ' option requires number value or options object'
|
33 | );
|
34 | this._maximumNumberOfLines = options;
|
35 | } else {
|
36 | assert(
|
37 | typeof options.value === 'number',
|
38 | this.getOptionName() + ' option requires the "value" property to be defined'
|
39 | );
|
40 | this._maximumNumberOfLines = options.value;
|
41 |
|
42 | var exceptions = options.allExcept || [];
|
43 | this._allowComments = (exceptions.indexOf('comments') === -1);
|
44 | }
|
45 | },
|
46 |
|
47 | getOptionName: function() {
|
48 | return 'maximumNumberOfLines';
|
49 | },
|
50 |
|
51 | check: function(file, errors) {
|
52 | var firstToken = file.getFirstToken({includeComments: true});
|
53 | var lines = this._allowComments ?
|
54 | file.getLines() : file.getLinesWithCommentsRemoved();
|
55 |
|
56 | lines = lines.filter(function(line) {return line !== '';});
|
57 |
|
58 | if (lines.length > this._maximumNumberOfLines) {
|
59 | errors.add(
|
60 | 'File must be at most ' + this._maximumNumberOfLines + ' lines long',
|
61 | firstToken,
|
62 | firstToken.value.length
|
63 | );
|
64 | }
|
65 | }
|
66 |
|
67 | };
|