• 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-assert-equal-boolean.js
1
"use strict";
2

3
//------------------------------------------------------------------------------
4
// Requirements
5
//------------------------------------------------------------------------------
6

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

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

14
const EQUALITY_ASSERTIONS = new Set(["equal", "deepEqual", "strictEqual"]);
8✔
15

16
/** @type {import('eslint').Rule.RuleModule} */
17
module.exports = {
8✔
18
    meta: {
19
        type: "suggestion",
20
        docs: {
21
            description: "require use of boolean assertions",
22
            category: "Best Practices",
23
            url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal-boolean.md"
24
        },
25
        fixable: "code",
26
        messages: {
27
            useAssertTrueOrFalse: "Use `assert.true or `assert.false` for boolean assertions."
28
        },
29
        schema: []
30
    },
31

32
    create: function (context) {
33
        // Declare a test stack in case of nested test cases (not currently supported by QUnit).
34
        const testStack = [];
440✔
35

36
        function getCurrentAssertContextVariable() {
37
            assert(testStack.length, "Test stack should not be empty");
296✔
38

39
            return testStack[testStack.length - 1].assertVar;
296✔
40
        }
41

42
        // Check for something like `equal(...)` without assert parameter.
43
        function isGlobalEqualityAssertion(calleeNode) {
44
            return calleeNode &&
432✔
45
                calleeNode.type === "Identifier" &&
46
                EQUALITY_ASSERTIONS.has(calleeNode.name);
47
        }
48

49
        // Check for something like `assert.equal(...)`.
50
        function isAssertEquality(calleeNode) {
51
            return calleeNode &&
368✔
52
                calleeNode.type === "MemberExpression" &&
53
                calleeNode.property.type === "Identifier" &&
54
                EQUALITY_ASSERTIONS.has(calleeNode.property.name) &&
55
                calleeNode.object.type === "Identifier" &&
56
                calleeNode.object.name === getCurrentAssertContextVariable();
57
        }
58

59
        // Check for something like `equal(...)` or `assert.equal(...)`.
60
        function isEqualityAssertion(calleeNode) {
61
            return isGlobalEqualityAssertion(calleeNode) ||
432✔
62
                isAssertEquality(calleeNode);
63
        }
64

65
        // Finds the first boolean argument of a CallExpression if one exists.
66
        function getBooleanArgument(node) {
67
            return node.arguments.length >= 2 &&
376✔
68
                [node.arguments[0], node.arguments[1]]
69
                    .find(arg => arg.type === "Literal" && (arg.value === true || arg.value === false));
640✔
70
        }
71

72
        function reportError(node) {
73
            context.report({
128✔
74
                node: node,
75
                messageId: "useAssertTrueOrFalse",
76
                fix(fixer) {
77
                    const booleanArgument = getBooleanArgument(node);
128✔
78
                    const newAssertionFunctionName = booleanArgument.value ? "true" : "false";
128✔
79

80
                    const sourceCode = context.getSourceCode();
128✔
81
                    const newArgsTextArray = node.arguments.filter(arg => arg !== booleanArgument).map(arg => sourceCode.getText(arg));
264✔
82
                    const newArgsTextJoined = newArgsTextArray.join(", ");
128✔
83

84
                    const assertVariablePrefix = node.callee.type === "Identifier" ? "" : `${getCurrentAssertContextVariable()}.`;
128✔
85

86
                    return fixer.replaceText(node, `${assertVariablePrefix}${newAssertionFunctionName}(${newArgsTextJoined})`);
128✔
87
                }
88
            });
89
        }
90

91
        return {
440✔
92
            "CallExpression": function (node) {
93
                /* istanbul ignore else: correctly does nothing */
94
                if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) {
872✔
95
                    testStack.push({
432✔
96
                        assertVar: utils.getAssertContextNameForTest(node.arguments)
97
                    });
98
                } else if (testStack.length > 0 && isEqualityAssertion(node.callee) && getBooleanArgument(node)) {
99
                    reportError(node);
100
                }
101
            },
102
            "CallExpression:exit": function (node) {
103
                /* istanbul ignore else: correctly does nothing */
104
                if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) {
872✔
105
                    testStack.pop();
432✔
106
                }
107
            }
108
        };
109
    }
110
};
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