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

platinumazure / eslint-plugin-qunit / 5244492784

pending completion
5244492784

push

github

web-flow
Upgrade: Bump release-it from 15.10.1 to 15.11.0

Bumps [release-it](https://github.com/release-it/release-it) from 15.10.1 to 15.11.0.
- [Release notes](https://github.com/release-it/release-it/releases)
- [Changelog](https://github.com/release-it/release-it/blob/main/CHANGELOG.md)
- [Commits](https://github.com/release-it/release-it/compare/15.10.1...15.11.0)

---
updated-dependencies:
- dependency-name: release-it
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

653 of 653 branches covered (100.0%)

878 of 878 relevant lines covered (100.0%)

661.49 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("assert"),
8✔
8
    utils = require("../utils");
8✔
9

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

14
/** @type {import('eslint').Rule.RuleModule} */
15
module.exports = {
8✔
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 = [],
472✔
31
            assertVariableStack = [];
472✔
32

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

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

43
        function getLoopTypeText(loopType) {
44
            switch (loopType) {
440✔
45
                case "WhileStatement": {
46
                    return "while loop";
104✔
47
                } case "DoWhileStatement": {
48
                    return "do-while loop";
88✔
49
                } case "ForStatement": {
50
                    return "for loop";
88✔
51
                } case "ForInStatement": {
52
                    return "for-in loop";
80✔
53
                } case "ForOfStatement": {
54
                    return "for-of loop";
80✔
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)) {
440✔
68
                const assertContextVar = assertVariableStack[assertVariableStack.length - 1];
120✔
69
                callType = `${assertContextVar}.async()`;
120✔
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;
440✔
77
        }
78

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

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

93
        return {
472✔
94
            "CallExpression": function (node) {
95
                /* istanbul ignore else: correctly not doing anything */
96
                if (utils.isTest(node.callee)) {
960✔
97
                    assertVariableStack.push(utils.getAssertContextNameForTest(node.arguments));
472✔
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)) {
960✔
111
                    assertVariableStack.pop();
472✔
112
                }
113
            },
114
            "WhileStatement": function (node) {
115
                loopStack.push(node);
104✔
116
            },
117
            "WhileStatement:exit": function (node) {
118
                popAndMatch(node);
104✔
119
            },
120
            "DoWhileStatement": function (node) {
121
                loopStack.push(node);
88✔
122
            },
123
            "DoWhileStatement:exit": function (node) {
124
                popAndMatch(node);
88✔
125
            },
126
            "ForStatement": function (node) {
127
                loopStack.push(node);
88✔
128
            },
129
            "ForStatement:exit": function (node) {
130
                popAndMatch(node);
88✔
131
            },
132
            "ForInStatement": function (node) {
133
                loopStack.push(node);
80✔
134
            },
135
            "ForInStatement:exit": function (node) {
136
                popAndMatch(node);
80✔
137
            },
138
            "ForOfStatement": function (node) {
139
                loopStack.push(node);
80✔
140
            },
141
            "ForOfStatement:exit": function (node) {
142
                popAndMatch(node);
80✔
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