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

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

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

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

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

16
/** @type {import('eslint').Rule.RuleModule} */
17
module.exports = {
6✔
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 = [];
330✔
35

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

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

42
        // Check for something like `equal(...)` without assert parameter.
43
        function isGlobalEqualityAssertion(calleeNode) {
44
            return calleeNode &&
324✔
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 &&
276✔
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) ||
324✔
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 &&
282✔
68
                [node.arguments[0], node.arguments[1]]
69
                    .find(arg => arg.type === "Literal" && (arg.value === true || arg.value === false));
480✔
70
        }
71

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

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

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

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

91
        return {
330✔
92
            "CallExpression": function (node) {
93
                /* istanbul ignore else: correctly does nothing */
94
                if (utils.isTest(node.callee) || utils.isAsyncTest(node.callee)) {
654✔
95
                    testStack.push({
324✔
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)) {
654✔
105
                    testStack.pop();
324✔
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