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 | var assert = require('assert');
|
29 | var defaultOperators = require('../utils').incrementAndDecrementOperators;
|
30 |
|
31 | module.exports = function() {};
|
32 |
|
33 | module.exports.prototype = {
|
34 |
|
35 | configure: function(operators) {
|
36 | var isTrue = operators === true;
|
37 |
|
38 | assert(
|
39 | Array.isArray(operators) || isTrue,
|
40 | this.getOptionName() + ' option requires array or true value'
|
41 | );
|
42 |
|
43 | if (isTrue) {
|
44 | operators = defaultOperators;
|
45 | }
|
46 |
|
47 | this._operatorIndex = {};
|
48 | for (var i = 0, l = operators.length; i < l; i++) {
|
49 | this._operatorIndex[operators[i]] = true;
|
50 | }
|
51 | },
|
52 |
|
53 | getOptionName: function() {
|
54 | return 'disallowSpaceBeforePostfixUnaryOperators';
|
55 | },
|
56 |
|
57 | check: function(file, errors) {
|
58 | var operatorIndex = this._operatorIndex;
|
59 |
|
60 |
|
61 | file.iterateNodesByType('UpdateExpression', function(node) {
|
62 |
|
63 | if (!node.prefix && operatorIndex[node.operator]) {
|
64 | var operatorToken = file.getLastNodeToken(node);
|
65 | errors.assert.noWhitespaceBetween({
|
66 | token: file.getPrevToken(operatorToken),
|
67 | nextToken: operatorToken,
|
68 | message: 'Operator ' + node.operator + ' should stick to operand'
|
69 | });
|
70 | }
|
71 | });
|
72 | }
|
73 | };
|