Repository: eslint/eslint
File: lib/rules/no-return-await.js (JavaScript)

Code before:
        ],

        messages: {
            removeAwait: "Remove redundant `await`.",
            redundantUseOfAwait: "Redundant use of `await` on a return value."
        }
    },

    create(context) {

        /**
         * Reports a found unnecessary `await` expression.
         * @param {ASTNode} node The node representing the `await` expression to report
         * @returns {void}
         */
        function reportUnnecessaryAwait(node) {
            context.report({
                node: context.getSourceCode().getFirstToken(node),
                loc: node.loc,
                messageId: "redundantUseOfAwait",
                suggest: [
                    {
                        messageId: "removeAwait",
                        fix(fixer) {
                            const sourceCode = context.getSourceCode();
                            const [awaitToken, tokenAfterAwait] = sourceCode.getTokens(node);

                            const areAwaitAndAwaitedExpressionOnTheSameLine = awaitToken.loc.start.line === tokenAfterAwait.loc.start.line;

                            if (!areAwaitAndAwaitedExpressionOnTheSameLine) {
                                return null;
                            }

                            const [startOfAwait, endOfAwait] = awaitToken.range;

                            const characterAfterAwait = sourceCode.text[endOfAwait];
                            const trimLength = characterAfterAwait === " " ? 1 : 0;

                            const range = [startOfAwait, endOfAwait + trimLength];

                            return fixer.removeRange(range);
                        }
                    }
                ]

            });
        }

        /**
         * Determines whether a thrown error from this node will be caught/handled within this function rather than immediately halting
         * this function. For example, a statement in a `try` block will always have an error handler. A statement in

Review comment (suggestion):
```suggestion
                            const [awaitToken, tokenAfterAwait] = sourceCode.getFirstTokens(node, 2);
```

Code after:
        ],

        messages: {
            removeAwait: "Remove redundant `await`.",
            redundantUseOfAwait: "Redundant use of `await` on a return value."
        }
    },

    create(context) {

        /**
         * Reports a found unnecessary `await` expression.
         * @param {ASTNode} node The node representing the `await` expression to report
         * @returns {void}
         */
        function reportUnnecessaryAwait(node) {
            context.report({
                node: context.getSourceCode().getFirstToken(node),
                loc: node.loc,
                messageId: "redundantUseOfAwait",
                suggest: [
                    {
                        messageId: "removeAwait",
                        fix(fixer) {
                            const sourceCode = context.getSourceCode();
                            const [awaitToken, tokenAfterAwait] = sourceCode.getFirstTokens(node, 2);

                            const areAwaitAndAwaitedExpressionOnTheSameLine = awaitToken.loc.start.line === tokenAfterAwait.loc.start.line;

                            if (!areAwaitAndAwaitedExpressionOnTheSameLine) {
                                return null;
                            }

                            const [startOfAwait, endOfAwait] = awaitToken.range;

                            const characterAfterAwait = sourceCode.text[endOfAwait];
                            const trimLength = characterAfterAwait === " " ? 1 : 0;

                            const range = [startOfAwait, endOfAwait + trimLength];

                            return fixer.removeRange(range);
                        }
                    }
                ]

            });
        }

        /**
         * Determines whether a thrown error from this node will be caught/handled within this function rather than immediately halting
         * this function. For example, a statement in a `try` block will always have an error handler. A statement in