UNPKG

1.11 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag use of unary increment and decrement operators.
3 * @author Ian Christian Myers
4 * @author Brody McKee (github.com/mrmckeb)
5 */
6
7"use strict";
8
9//------------------------------------------------------------------------------
10// Rule Definition
11//------------------------------------------------------------------------------
12
13module.exports = function(context) {
14
15 var config = context.options[0],
16 allowInForAfterthought = false;
17
18 if (typeof config === "object") {
19 allowInForAfterthought = config.allowForLoopAfterthoughts === true;
20 }
21
22 return {
23
24 "UpdateExpression": function(node) {
25 if (allowInForAfterthought && node.parent.type === "ForStatement") {
26 return;
27 }
28 context.report(node, "Unary operator '" + node.operator + "' used.");
29 }
30
31 };
32
33};
34
35module.exports.schema = [
36 {
37 "type": "object",
38 "properties": {
39 "allowForLoopAfterthoughts": {
40 "type": "boolean"
41 }
42 },
43 "additionalProperties": false
44 }
45];