• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

platinumazure / eslint-plugin-qunit / 7857817061

10 Feb 2024 10:29PM UTC coverage: 100.0%. Remained the same
7857817061

Pull #455

github

web-flow
upgrade: Bump eslint-doc-generator from 1.5.2 to 1.6.2

Bumps [eslint-doc-generator](https://github.com/bmish/eslint-doc-generator) from 1.5.2 to 1.6.2.
- [Release notes](https://github.com/bmish/eslint-doc-generator/releases)
- [Changelog](https://github.com/bmish/eslint-doc-generator/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bmish/eslint-doc-generator/compare/v1.5.2...v1.6.2)

---
updated-dependencies:
- dependency-name: eslint-doc-generator
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #455: upgrade: Bump eslint-doc-generator from 1.5.2 to 1.6.2

653 of 653 branches covered (100.0%)

878 of 878 relevant lines covered (100.0%)

496.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/rules/no-async-in-loops.js
1
/**
2
 * @fileoverview Forbid async calls in loops.
3
 * @author Kevin Partington
4
 */
5
"use strict";
6

7
const assert = require("node:assert"),
6✔
8
    utils = require("../utils");
6✔
9

10
//------------------------------------------------------------------------------
11
// Rule Definition
12
//------------------------------------------------------------------------------
13

14
/** @type {import('eslint').Rule.RuleModule} */
15
module.exports = {
6✔
16
    meta: {
17
        type: "suggestion",
18
        docs: {
19
            description: "disallow async calls in loops",
20
            category: "Best Practices",
21
            url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-async-in-loops.md"
22
        },
23
        messages: {
24
            unexpectedAsyncInLoop: "Unexpected {{call}} in {{loopTypeText}}."
25
        },
26
        schema: []
27
    },
28

29
    create: function (context) {
30
        const loopStack = [],
354✔
31
            assertVariableStack = [];
354✔
32

33
        function isAsyncCallExpression(node) {
34
            const assertContextVar = assertVariableStack[assertVariableStack.length - 1];
660✔
35
            return utils.isAsyncCallExpression(node, assertContextVar);
660✔
36
        }
37

38
        function popAndMatch(expectedNode) {
39
            const actualNode = loopStack.pop();
330✔
40
            assert.strictEqual(actualNode, expectedNode, "Node mismatch in loop stack");
330✔
41
        }
42

43
        function getLoopTypeText(loopType) {
44
            switch (loopType) {
330✔
45
                case "WhileStatement": {
46
                    return "while loop";
78✔
47
                } case "DoWhileStatement": {
48
                    return "do-while loop";
66✔
49
                } case "ForStatement": {
50
                    return "for loop";
66✔
51
                } case "ForInStatement": {
52
                    return "for-in loop";
60✔
53
                } case "ForOfStatement": {
54
                    return "for-of loop";
60✔
55
                }
56
                /* istanbul ignore next */
57
                default: {
58
                    throw new RangeError(`Invalid loop type: ${loopType}`);
59
                }
60
            }
61
        }
62

63
        function getAsyncCallType(node) {
64
            let callType;
65

66
            /* istanbul ignore else: correctly returning undefined */
67
            if (isAsyncCallExpression(node)) {
330✔
68
                const assertContextVar = assertVariableStack[assertVariableStack.length - 1];
90✔
69
                callType = `${assertContextVar}.async()`;
90✔
70
            } else if (utils.isStop(node.callee)) {
71
                callType = "stop()";
72
            } else if (utils.isStart(node.callee)) {
73
                callType = "start()";
74
            }
75

76
            return callType;
330✔
77
        }
78

79
        function reportError(node) {
80
            const loopNode = loopStack[loopStack.length - 1],
330✔
81
                loopType = loopNode.type;
330✔
82

83
            context.report({
330✔
84
                node: node,
85
                messageId: "unexpectedAsyncInLoop",
86
                data: {
87
                    call: getAsyncCallType(node),
88
                    loopTypeText: getLoopTypeText(loopType)
89
                }
90
            });
91
        }
92

93
        return {
354✔
94
            "CallExpression": function (node) {
95
                /* istanbul ignore else: correctly not doing anything */
96
                if (utils.isTest(node.callee)) {
720✔
97
                    assertVariableStack.push(utils.getAssertContextNameForTest(node.arguments));
354✔
98
                } else if (loopStack.length > 0) {
99
                    const isStopOrStartOrAsync = isAsyncCallExpression(node) ||
100
                        utils.isStop(node.callee) ||
101
                        utils.isStart(node.callee);
102

103
                    /* istanbul ignore else: correctly not doing anything */
104
                    if (isStopOrStartOrAsync) {
105
                        reportError(node);
106
                    }
107
                }
108
            },
109
            "CallExpression:exit": function (node) {
110
                if (utils.isTest(node.callee)) {
720✔
111
                    assertVariableStack.pop();
354✔
112
                }
113
            },
114
            "WhileStatement": function (node) {
115
                loopStack.push(node);
78✔
116
            },
117
            "WhileStatement:exit": function (node) {
118
                popAndMatch(node);
78✔
119
            },
120
            "DoWhileStatement": function (node) {
121
                loopStack.push(node);
66✔
122
            },
123
            "DoWhileStatement:exit": function (node) {
124
                popAndMatch(node);
66✔
125
            },
126
            "ForStatement": function (node) {
127
                loopStack.push(node);
66✔
128
            },
129
            "ForStatement:exit": function (node) {
130
                popAndMatch(node);
66✔
131
            },
132
            "ForInStatement": function (node) {
133
                loopStack.push(node);
60✔
134
            },
135
            "ForInStatement:exit": function (node) {
136
                popAndMatch(node);
60✔
137
            },
138
            "ForOfStatement": function (node) {
139
                loopStack.push(node);
60✔
140
            },
141
            "ForOfStatement:exit": function (node) {
142
                popAndMatch(node);
60✔
143
            }
144
        };
145
    }
146
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc