Repository: eslint/eslint
File: lib/rules/no-constant-condition.js (JavaScript)

Code before:
            {
                type: "object",
                properties: {
                    checkLoops: {
                        enum: ["all", "allExceptWhileTrue", "none", true, false]
                    }
                },
                additionalProperties: false
            }
        ],

        messages: {
            unexpected: "Unexpected constant condition."
        }
    },

    create(context) {
        const options = context.options[0] || {};
        let checkLoops = options.checkLoops ?? "allExceptWhileTrue";
        const loopSetStack = [];
        const sourceCode = context.sourceCode;

        if (options.checkLoops === true) {
            checkLoops = "all";
        }
        if (options.checkLoops === false) {
            checkLoops = "none";
        }

        let loopsInCurrentScope = new Set();

        //--------------------------------------------------------------------------
        // Helpers
        //--------------------------------------------------------------------------

        /**
         * Tracks when the given node contains a constant condition.
         * @param {ASTNode} node The AST node to check.
         * @returns {void}
         * @private
         */
        function trackConstantConditionLoop(node) {
            if (node.test && isConstant(sourceCode.getScope(node), node.test, true)) {
                loopsInCurrentScope.add(node);
            }
        }

        /**
         * Reports when the set contains the given constant condition node
         * @param {ASTNode} node The AST node to check.
         * @returns {void}

Review comment (suggestion):
Shall we use an `else if`? I think that makes the logic easier to follow, but it's just my feeling.

```suggestion
        } else if (options.checkLoops === false) {
```

Code after:
            {
                type: "object",
                properties: {
                    checkLoops: {
                        enum: ["all", "allExceptWhileTrue", "none", true, false]
                    }
                },
                additionalProperties: false
            }
        ],

        messages: {
            unexpected: "Unexpected constant condition."
        }
    },

    create(context) {
        const options = context.options[0] || {};
        let checkLoops = options.checkLoops ?? "allExceptWhileTrue";
        const loopSetStack = [];
        const sourceCode = context.sourceCode;

        if (options.checkLoops === true) {
            checkLoops = "all";
        } else if (options.checkLoops === false) {
            checkLoops = "none";
        }

        let loopsInCurrentScope = new Set();

        //--------------------------------------------------------------------------
        // Helpers
        //--------------------------------------------------------------------------

        /**
         * Tracks when the given node contains a constant condition.
         * @param {ASTNode} node The AST node to check.
         * @returns {void}
         * @private
         */
        function trackConstantConditionLoop(node) {
            if (node.test && isConstant(sourceCode.getScope(node), node.test, true)) {
                loopsInCurrentScope.add(node);
            }
        }

        /**
         * Reports when the set contains the given constant condition node
         * @param {ASTNode} node The AST node to check.
         * @returns {void}
         * @private