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 | var assert = require('assert');
|
36 | var defaultOperators = require('../utils').binaryOperators.slice().concat(['.']);
|
37 |
|
38 | module.exports = function() {};
|
39 |
|
40 | module.exports.prototype = {
|
41 | configure: function(operators) {
|
42 | assert(Array.isArray(operators) || operators === true,
|
43 | this.getOptionName() + ' option requires array or true value');
|
44 |
|
45 | if (operators === true) {
|
46 | operators = defaultOperators;
|
47 | }
|
48 | this._operators = operators;
|
49 | },
|
50 |
|
51 | getOptionName: function() {
|
52 | return 'disallowOperatorBeforeLineBreak';
|
53 | },
|
54 |
|
55 | check: function(file, errors) {
|
56 | file.iterateTokensByTypeAndValue('Punctuator', this._operators, function(token) {
|
57 | errors.assert.sameLine({
|
58 | token: token,
|
59 | nextToken: file.getNextToken(token),
|
60 | message: 'Operator needs to either be on the same line or after a line break.'
|
61 | });
|
62 | });
|
63 | }
|
64 | };
|