lib/rules/comma-style.js
function validateCommaItemSpacing(previousItemToken, commaToken, currentItemToken, reportItem) {

            // if single line
            if (astUtils.isTokenOnSameLine(commaToken, currentItemToken) &&
                    astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {

                // do nothing.

            } else if (!astUtils.isTokenOnSameLine(commaToken, currentItemToken) &&
                    !astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {

                const comment = sourceCode.getCommentsAfter(commaToken)[0];
                const styleType = comment && comment.type === "Block" && astUtils.isTokenOnSameLine(commaToken, comment)
                    ? style
                    : "between";

                // lone comma
                context.report({
                    node: reportItem,
                    loc: {
                        line: commaToken.loc.end.line,
                        column: commaToken.loc.start.column
                    },
                    messageId: "unexpectedLineBeforeAndAfterComma",
                    fix: getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken)
                });

            } else if (style === "first" && !astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

                context.report({
                    node: reportItem,
                    messageId: "expectedCommaFirst",
                    fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
                });

            } else if (style === "last" && astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

                context.report({
                    node: reportItem,
                    loc: {
                        line: commaToken.loc.end.line,
                        column: commaToken.loc.end.column
                    },
                    messageId: "expectedCommaLast",
                    fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
                });
            }
        }
function validateCommaItemSpacing(previousItemToken, commaToken, currentItemToken, reportItem) {

            // if single line
            if (astUtils.isTokenOnSameLine(commaToken, currentItemToken) &&
                    astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {

                // do nothing.

            } else if (!astUtils.isTokenOnSameLine(commaToken, currentItemToken) &&
                    !astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {

                const comment = sourceCode.getCommentsAfter(commaToken)[0];
                const styleType = comment && comment.type === "Block" && astUtils.isTokenOnSameLine(commaToken, comment)
                    ? style
                    : "between";

                // lone comma
                context.report({
                    node: reportItem,
                    loc: {
                        line: commaToken.loc.end.line,
                        column: commaToken.loc.start.column
                    },
                    messageId: "unexpectedLineBeforeAndAfterComma",
                    fix: getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken)
                });

            } else if (style === "first" && !astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

                context.report({
                    node: reportItem,
                    messageId: "expectedCommaFirst",
                    fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
                });

            } else if (style === "last" && astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

                context.report({
                    node: reportItem,
                    loc: {
                        line: commaToken.loc.end.line,
                        column: commaToken.loc.end.column
                    },
                    messageId: "expectedCommaLast",
                    fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
                });
            }
        }
function validateCommaItemSpacing ( previousItemToken , commaToken , currentItemToken , reportItem ) { // if single line if ( astUtils . isTokenOnSameLine ( commaToken , currentItemToken ) && astUtils . isTokenOnSameLine ( previousItemToken , commaToken ) ) { // do nothing. } else if ( ! astUtils . isTokenOnSameLine ( commaToken , currentItemToken ) && ! astUtils . isTokenOnSameLine ( previousItemToken , commaToken ) ) { const comment = sourceCode . getCommentsAfter ( commaToken ) [ 0 ] ; const styleType = comment && comment . type === "Block" && astUtils . isTokenOnSameLine ( commaToken , comment ) ? style : "between" ; // lone comma context . report ( { node : reportItem , loc : { line : commaToken . loc . end . line , column : commaToken . loc . start . column } , messageId : "unexpectedLineBeforeAndAfterComma" , fix : getFixerFunction ( styleType , previousItemToken , commaToken , currentItemToken ) } ) ; } else if ( style === "first" && ! astUtils . isTokenOnSameLine ( commaToken , currentItemToken ) ) { context . report ( { node : reportItem , messageId : "expectedCommaFirst" , fix : getFixerFunction ( style , previousItemToken , commaToken , currentItemToken ) } ) ; } else if ( style === "last" && astUtils . isTokenOnSameLine ( commaToken , currentItemToken ) ) { context . report ( { node : reportItem , loc : { line : commaToken . loc . end . line , column : commaToken . loc . end . column } , messageId : "expectedCommaLast" , fix : getFixerFunction ( style , previousItemToken , commaToken , currentItemToken ) } ) ; } }
Validates the spacing around single items in lists.
@param {Token} previousItemToken The last token from the previous item.
@param {Token} commaToken The token representing the comma.
@param {Token} currentItemToken The first token of the current item.
@param {Token} reportItem The item to use when reporting an error.
@returns {void}
@private
Validates the spacing around single items in lists .