Repository: eslint/eslint
File: lib/rules/no-implicit-coercion.js (JavaScript)

Code before:
    },

    create(context) {
        const options = parseOptions(context.options[0] || {});
        const sourceCode = context.sourceCode;

        /**
         * Reports an error and autofixes the node
         * @param {ASTNode} node An ast node to report the error on.
         * @param {string} recommendation The recommended code for the issue
         * @param {bool} shouldFix Whether this report should fix the node
         * @returns {void}
         */
        function report(node, recommendation, shouldFix) {

            /**
             * Fix function
             * @param {RuleFixer} fixer The fixer to fix.
             * @returns {Fix} The fix object.
             */
            function fix(fixer) {
                const tokenBefore = sourceCode.getTokenBefore(node);

                if (
                    tokenBefore &&
                    tokenBefore.range[1] === node.range[0] &&
                    !astUtils.canTokensBeAdjacent(tokenBefore, recommendation)
                ) {
                    return fixer.replaceText(node, ` ${recommendation}`);
                }

                return fixer.replaceText(node, recommendation);
            }

            context.report({
                node,
                messageId: "implicitCoercion",
                data: { recommendation },
                fix(fixer) {
                    if (!shouldFix) {
                        return null;
                    }

                    return fix(fixer);
                },
                suggest: [
                    {
                        messageId: "useRecommendation",
                        data: { recommendation },
                        fix(fixer) {
                            if (shouldFix) {

Review comment (suggestion):
[Nit] This would be a bit more succinct, I think.

```suggestion
                    tokenBefore?.range[1] === node.range[0] &&
```

Code after:
    },

    create(context) {
        const options = parseOptions(context.options[0] || {});
        const sourceCode = context.sourceCode;

        /**
         * Reports an error and autofixes the node
         * @param {ASTNode} node An ast node to report the error on.
         * @param {string} recommendation The recommended code for the issue
         * @param {bool} shouldSuggest Whether this report should offer a suggestion
         * @param {bool} shouldFix Whether this report should fix the node
         * @returns {void}
         */
        function report(node, recommendation, shouldSuggest, shouldFix) {

            /**
             * Fix function
             * @param {RuleFixer} fixer The fixer to fix.
             * @returns {Fix} The fix object.
             */
            function fix(fixer) {
                const tokenBefore = sourceCode.getTokenBefore(node);

                if (
                    tokenBefore?.range[1] === node.range[0] &&
                    !astUtils.canTokensBeAdjacent(tokenBefore, recommendation)
                ) {
                    return fixer.replaceText(node, ` ${recommendation}`);
                }

                return fixer.replaceText(node, recommendation);
            }

            context.report({
                node,
                messageId: "implicitCoercion",
                data: { recommendation },
                fix(fixer) {
                    if (!shouldFix) {
                        return null;
                    }

                    return fix(fixer);
                },
                suggest: [
                    {
                        messageId: "useRecommendation",
                        data: { recommendation },
                        fix(fixer) {
                            if (shouldFix || !shouldSuggest) {