lib/rules/nonblock-statement-body-position.js
function validateStatement(node, keywordName) {
            const option = getOption(keywordName);

            if (node.type === "BlockStatement" || option === "any") {
                return;
            }

            const tokenBefore = sourceCode.getTokenBefore(node);

            if (tokenBefore.loc.end.line === node.loc.start.line && option === "below") {
                context.report({
                    node,
                    message: "Expected a linebreak before this statement.",
                    fix: fixer => fixer.insertTextBefore(node, "\n")
                });
            } else if (tokenBefore.loc.end.line !== node.loc.start.line && option === "beside") {
                context.report({
                    node,
                    message: "Expected no linebreak before this statement.",
                    fix(fixer) {
                        if (sourceCode.getText().slice(tokenBefore.range[1], node.range[0]).trim()) {
                            return null;
                        }
                        return fixer.replaceTextRange([tokenBefore.range[1], node.range[0]], " ");
                    }
                });
            }
        }
function validateStatement(node, keywordName) {
            const option = getOption(keywordName);

            if (node.type === "BlockStatement" || option === "any") {
                return;
            }

            const tokenBefore = sourceCode.getTokenBefore(node);

            if (tokenBefore.loc.end.line === node.loc.start.line && option === "below") {
                context.report({
                    node,
                    message: "Expected a linebreak before this statement.",
                    fix: fixer => fixer.insertTextBefore(node, "\n")
                });
            } else if (tokenBefore.loc.end.line !== node.loc.start.line && option === "beside") {
                context.report({
                    node,
                    message: "Expected no linebreak before this statement.",
                    fix(fixer) {
                        if (sourceCode.getText().slice(tokenBefore.range[1], node.range[0]).trim()) {
                            return null;
                        }
                        return fixer.replaceTextRange([tokenBefore.range[1], node.range[0]], " ");
                    }
                });
            }
        }
function validateStatement ( node , keywordName ) { const option = getOption ( keywordName ) ; if ( node . type === "BlockStatement" || option === "any" ) { return ; } const tokenBefore = sourceCode . getTokenBefore ( node ) ; if ( tokenBefore . loc . end . line === node . loc . start . line && option === "below" ) { context . report ( { node , message : "Expected a linebreak before this statement." , fix : fixer => fixer . insertTextBefore ( node , "\n" ) } ) ; } else if ( tokenBefore . loc . end . line !== node . loc . start . line && option === "beside" ) { context . report ( { node , message : "Expected no linebreak before this statement." , fix ( fixer ) { if ( sourceCode . getText ( ) . slice ( tokenBefore . range [ 1 ] , node . range [ 0 ] ) . trim ( ) ) { return null ; } return fixer . replaceTextRange ( [ tokenBefore . range [ 1 ] , node . range [ 0 ] ] , " " ) ; } } ) ; } }
Validates the location of a single-line statement
@param {ASTNode} node The single-line statement
@param {string} keywordName The applicable keyword name for the single-line statement
@returns {void}
Validates the location of a single - line statement