UNPKG

1.64 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 = {
14 meta: {
15 docs: {
16 description: "disallow the unary operators `++` and `--`",
17 category: "Stylistic Issues",
18 recommended: false,
19 url: "https://eslint.org/docs/rules/no-plusplus"
20 },
21
22 schema: [
23 {
24 type: "object",
25 properties: {
26 allowForLoopAfterthoughts: {
27 type: "boolean"
28 }
29 },
30 additionalProperties: false
31 }
32 ]
33 },
34
35 create(context) {
36
37 const config = context.options[0];
38 let allowInForAfterthought = false;
39
40 if (typeof config === "object") {
41 allowInForAfterthought = config.allowForLoopAfterthoughts === true;
42 }
43
44 return {
45
46 UpdateExpression(node) {
47 if (allowInForAfterthought && node.parent.type === "ForStatement") {
48 return;
49 }
50 context.report({
51 node,
52 message: "Unary operator '{{operator}}' used.",
53 data: {
54 operator: node.operator
55 }
56 });
57 }
58
59 };
60
61 }
62};