lib/rules/semi-style.js
function check(semiToken, expected) {
            const prevToken = sourceCode.getTokenBefore(semiToken);
            const nextToken = sourceCode.getTokenAfter(semiToken);
            const prevIsSameLine = !prevToken || astUtils.isTokenOnSameLine(prevToken, semiToken);
            const nextIsSameLine = !nextToken || astUtils.isTokenOnSameLine(semiToken, nextToken);

            if ((expected === "last" && !prevIsSameLine) || (expected === "first" && !nextIsSameLine)) {
                context.report({
                    loc: semiToken.loc,
                    message: "Expected this semicolon to be at {{pos}}.",
                    data: {
                        pos: (expected === "last")
                            ? "the end of the previous line"
                            : "the beginning of the next line"
                    },
                    fix(fixer) {
                        if (prevToken && nextToken && sourceCode.commentsExistBetween(prevToken, nextToken)) {
                            return null;
                        }

                        const start = prevToken ? prevToken.range[1] : semiToken.range[0];
                        const end = nextToken ? nextToken.range[0] : semiToken.range[1];
                        const text = (expected === "last") ? ";\n" : "\n;";

                        return fixer.replaceTextRange([start, end], text);
                    }
                });
            }
        }
function check(semiToken, expected) {
            const prevToken = sourceCode.getTokenBefore(semiToken);
            const nextToken = sourceCode.getTokenAfter(semiToken);
            const prevIsSameLine = !prevToken || astUtils.isTokenOnSameLine(prevToken, semiToken);
            const nextIsSameLine = !nextToken || astUtils.isTokenOnSameLine(semiToken, nextToken);

            if ((expected === "last" && !prevIsSameLine) || (expected === "first" && !nextIsSameLine)) {
                context.report({
                    loc: semiToken.loc,
                    message: "Expected this semicolon to be at {{pos}}.",
                    data: {
                        pos: (expected === "last")
                            ? "the end of the previous line"
                            : "the beginning of the next line"
                    },
                    fix(fixer) {
                        if (prevToken && nextToken && sourceCode.commentsExistBetween(prevToken, nextToken)) {
                            return null;
                        }

                        const start = prevToken ? prevToken.range[1] : semiToken.range[0];
                        const end = nextToken ? nextToken.range[0] : semiToken.range[1];
                        const text = (expected === "last") ? ";\n" : "\n;";

                        return fixer.replaceTextRange([start, end], text);
                    }
                });
            }
        }
function check ( semiToken , expected ) { const prevToken = sourceCode . getTokenBefore ( semiToken ) ; const nextToken = sourceCode . getTokenAfter ( semiToken ) ; const prevIsSameLine = ! prevToken || astUtils . isTokenOnSameLine ( prevToken , semiToken ) ; const nextIsSameLine = ! nextToken || astUtils . isTokenOnSameLine ( semiToken , nextToken ) ; if ( ( expected === "last" && ! prevIsSameLine ) || ( expected === "first" && ! nextIsSameLine ) ) { context . report ( { loc : semiToken . loc , message : "Expected this semicolon to be at {{pos}}." , data : { pos : ( expected === "last" ) ? "the end of the previous line" : "the beginning of the next line" } , fix ( fixer ) { if ( prevToken && nextToken && sourceCode . commentsExistBetween ( prevToken , nextToken ) ) { return null ; } const start = prevToken ? prevToken . range [ 1 ] : semiToken . range [ 0 ] ; const end = nextToken ? nextToken . range [ 0 ] : semiToken . range [ 1 ] ; const text = ( expected === "last" ) ? ";\n" : "\n;" ; return fixer . replaceTextRange ( [ start , end ] , text ) ; } } ) ; } }
Check the given semicolon token.
@param {Token} semiToken The semicolon token to check.
@param {"first"|"last"} expected The expected location to check.
@returns {void}
Check the given semicolon token .