• 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-assert-equal.js
1
/**
2
 * @fileoverview Forbid the use of assert.equal and suggest other assertions.
3
 * @author Kevin Partington
4
 */
5
"use strict";
6

7
//------------------------------------------------------------------------------
8
// Requirements
9
//------------------------------------------------------------------------------
10

11
const assert = require("node:assert"),
6✔
12
    utils = require("../utils"),
6✔
13
    { ReferenceTracker } = require("eslint-utils");
6✔
14

15
//------------------------------------------------------------------------------
16
// Rule Definition
17
//------------------------------------------------------------------------------
18

19
/** @type {import('eslint').Rule.RuleModule} */
20
module.exports = {
6✔
21
    meta: {
22
        type: "suggestion",
23
        docs: {
24
            description: "disallow the use of assert.equal",
25
            category: "Best Practices",
26
            url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal.md"
27
        },
28
        messages: {
29
            unexpectedGlobalEqual: "Unexpected equal. Use strictEqual, deepEqual, or propEqual.",
30
            unexpectedAssertEqual: "Unexpected {{assertVar}}.equal. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.",
31
            switchToDeepEqual: "Switch to deepEqual.",
32
            switchToPropEqual: "Switch to propEqual.",
33
            switchToStrictEqual: "Switch to strictEqual."
34
        },
35
        schema: [],
36
        hasSuggestions: true
37
    },
38

39
    create: function (context) {
40
        // Declare a test stack in case of nested test cases (not currently
41
        // supported by QUnit).
42
        const testStack = [];
126✔
43

44
        // We check upfront to find all the references to global equal(),
45
        // and then report them if they end up being inside test contexts.
46
        const globalEqualCallNodes = new Set();
126✔
47

48
        function getCurrentAssertContextVariable() {
49
            assert(testStack.length, "Test stack should not be empty");
48✔
50

51
            return testStack[testStack.length - 1].assertVar;
48✔
52
        }
53

54
        function isAssertEqual(calleeNode) {
55
            return calleeNode &&
114✔
56
                calleeNode.type === "MemberExpression" &&
57
                calleeNode.property.type === "Identifier" &&
58
                calleeNode.property.name === "equal" &&
59
                calleeNode.object.type === "Identifier" &&
60
                calleeNode.object.name === getCurrentAssertContextVariable();
61
        }
62

63
        function reportError(node, isGlobal) {
64
            context.report({
36✔
65
                node: node,
66
                messageId: isGlobal ? "unexpectedGlobalEqual" : "unexpectedAssertEqual",
36✔
67
                data: {
68
                    assertVar: isGlobal ? null : getCurrentAssertContextVariable()
36✔
69
                },
70
                suggest: [
71
                    {
72
                        messageId: "switchToDeepEqual",
73
                        fix(fixer) {
74
                            return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "deepEqual");
36✔
75
                        }
76
                    },
77
                    {
78
                        messageId: "switchToPropEqual",
79
                        fix(fixer) {
80
                            return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "propEqual");
36✔
81
                        }
82
                    },
83
                    {
84
                        messageId: "switchToStrictEqual",
85
                        fix(fixer) {
86
                            return fixer.replaceText(isGlobal ? node.callee : node.callee.property, "strictEqual");
36✔
87
                        }
88
                    }
89
                ]
90

91
            });
92
        }
93

94
        return {
126✔
95
            "CallExpression": function (node) {
96
                /* istanbul ignore else: correctly does nothing */
97
                if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) {
240✔
98
                    testStack.push({
120✔
99
                        assertVar: utils.getAssertContextNameForTest(node.arguments)
100
                    });
101
                } else if (testStack.length > 0) {
102
                    if (isAssertEqual(node.callee)) {
103
                        reportError(node, false);
104
                    } else if (globalEqualCallNodes.has(node)) {
105
                        reportError(node, true);
106
                    }
107
                }
108
            },
109
            "CallExpression:exit": function (node) {
110
                /* istanbul ignore else: correctly does nothing */
111
                if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) {
240✔
112
                    testStack.pop();
120✔
113
                }
114
            },
115
            "Program": function () {
116
                // Gather all calls to global `equal()`.
117

118
                const tracker = new ReferenceTracker(context.getScope());
126✔
119
                const traceMap = { equal: { [ReferenceTracker.CALL]: true } };
126✔
120

121
                for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
126✔
122
                    globalEqualCallNodes.add(node);
18✔
123
                }
124
            }
125
        };
126
    }
127
};
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

© 2026 Coveralls, Inc