lib/rules/comma-dangle.js
function forceTrailingComma(node) {
            const lastItem = getLastItem(node);

            if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
                return;
            }
            if (!isTrailingCommaAllowed(lastItem)) {
                forbidTrailingComma(node);
                return;
            }

            const trailingToken = getTrailingToken(node, lastItem);

            if (trailingToken.value !== ",") {
                context.report({
                    node: lastItem,
                    loc: trailingToken.loc.end,
                    messageId: "missing",
                    fix(fixer) {
                        return fixer.insertTextAfter(trailingToken, ",");
                    }
                });
            }
        }
function forceTrailingComma(node) {
            const lastItem = getLastItem(node);

            if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
                return;
            }
            if (!isTrailingCommaAllowed(lastItem)) {
                forbidTrailingComma(node);
                return;
            }

            const trailingToken = getTrailingToken(node, lastItem);

            if (trailingToken.value !== ",") {
                context.report({
                    node: lastItem,
                    loc: trailingToken.loc.end,
                    messageId: "missing",
                    fix(fixer) {
                        return fixer.insertTextAfter(trailingToken, ",");
                    }
                });
            }
        }
function forceTrailingComma ( node ) { const lastItem = getLastItem ( node ) ; if ( ! lastItem || ( node . type === "ImportDeclaration" && lastItem . type !== "ImportSpecifier" ) ) { return ; } if ( ! isTrailingCommaAllowed ( lastItem ) ) { forbidTrailingComma ( node ) ; return ; } const trailingToken = getTrailingToken ( node , lastItem ) ; if ( trailingToken . value !== "," ) { context . report ( { node : lastItem , loc : trailingToken . loc . end , messageId : "missing" , fix ( fixer ) { return fixer . insertTextAfter ( trailingToken , "," ) ; } } ) ; } }
Reports the last element of a given node if it does not have a trailing
comma.

If a given node is `ArrayPattern` which has `RestElement`, the trailing
comma is disallowed, so report if it exists.

@param {ASTNode} node - A node to check. Its type is one of
ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
ImportDeclaration, and ExportNamedDeclaration.
@returns {void}
Reports the last element of a given node if it does not have a trailing comma .