lib/rules/block-spacing.js
function checkSpacingInsideBraces(node) {

            // Gets braces and the first/last token of content.
            const openBrace = getOpenBrace(node);
            const closeBrace = sourceCode.getLastToken(node);
            const firstToken = sourceCode.getTokenAfter(openBrace, { includeComments: true });
            const lastToken = sourceCode.getTokenBefore(closeBrace, { includeComments: true });

            // Skip if the node is invalid or empty.
            if (openBrace.type !== "Punctuator" ||
                openBrace.value !== "{" ||
                closeBrace.type !== "Punctuator" ||
                closeBrace.value !== "}" ||
                firstToken === closeBrace
            ) {
                return;
            }

            // Skip line comments for option never
            if (!always && firstToken.type === "Line") {
                return;
            }

            // Check.
            if (!isValid(openBrace, firstToken)) {
                context.report({
                    node,
                    loc: openBrace.loc.start,
                    messageId,
                    data: {
                        location: "after",
                        token: openBrace.value
                    },
                    fix(fixer) {
                        if (always) {
                            return fixer.insertTextBefore(firstToken, " ");
                        }

                        return fixer.removeRange([openBrace.range[1], firstToken.range[0]]);
                    }
                });
            }
            if (!isValid(lastToken, closeBrace)) {
                context.report({
                    node,
                    loc: closeBrace.loc.start,
                    messageId,
                    data: {
                        location: "before",
                        token: closeBrace.value
                    },
                    fix(fixer) {
                        if (always) {
                            return fixer.insertTextAfter(lastToken, " ");
                        }

                        return fixer.removeRange([lastToken.range[1], closeBrace.range[0]]);
                    }
                });
            }
        }
function checkSpacingInsideBraces(node) {

            // Gets braces and the first/last token of content.
            const openBrace = getOpenBrace(node);
            const closeBrace = sourceCode.getLastToken(node);
            const firstToken = sourceCode.getTokenAfter(openBrace, { includeComments: true });
            const lastToken = sourceCode.getTokenBefore(closeBrace, { includeComments: true });

            // Skip if the node is invalid or empty.
            if (openBrace.type !== "Punctuator" ||
                openBrace.value !== "{" ||
                closeBrace.type !== "Punctuator" ||
                closeBrace.value !== "}" ||
                firstToken === closeBrace
            ) {
                return;
            }

            // Skip line comments for option never
            if (!always && firstToken.type === "Line") {
                return;
            }

            // Check.
            if (!isValid(openBrace, firstToken)) {
                context.report({
                    node,
                    loc: openBrace.loc.start,
                    messageId,
                    data: {
                        location: "after",
                        token: openBrace.value
                    },
                    fix(fixer) {
                        if (always) {
                            return fixer.insertTextBefore(firstToken, " ");
                        }

                        return fixer.removeRange([openBrace.range[1], firstToken.range[0]]);
                    }
                });
            }
            if (!isValid(lastToken, closeBrace)) {
                context.report({
                    node,
                    loc: closeBrace.loc.start,
                    messageId,
                    data: {
                        location: "before",
                        token: closeBrace.value
                    },
                    fix(fixer) {
                        if (always) {
                            return fixer.insertTextAfter(lastToken, " ");
                        }

                        return fixer.removeRange([lastToken.range[1], closeBrace.range[0]]);
                    }
                });
            }
        }
function checkSpacingInsideBraces ( node ) { // Gets braces and the first/last token of content. const openBrace = getOpenBrace ( node ) ; const closeBrace = sourceCode . getLastToken ( node ) ; const firstToken = sourceCode . getTokenAfter ( openBrace , { includeComments : true } ) ; const lastToken = sourceCode . getTokenBefore ( closeBrace , { includeComments : true } ) ; // Skip if the node is invalid or empty. if ( openBrace . type !== "Punctuator" || openBrace . value !== "{" || closeBrace . type !== "Punctuator" || closeBrace . value !== "}" || firstToken === closeBrace ) { return ; } // Skip line comments for option never if ( ! always && firstToken . type === "Line" ) { return ; } // Check. if ( ! isValid ( openBrace , firstToken ) ) { context . report ( { node , loc : openBrace . loc . start , messageId , data : { location : "after" , token : openBrace . value } , fix ( fixer ) { if ( always ) { return fixer . insertTextBefore ( firstToken , " " ) ; } return fixer . removeRange ( [ openBrace . range [ 1 ] , firstToken . range [ 0 ] ] ) ; } } ) ; } if ( ! isValid ( lastToken , closeBrace ) ) { context . report ( { node , loc : closeBrace . loc . start , messageId , data : { location : "before" , token : closeBrace . value } , fix ( fixer ) { if ( always ) { return fixer . insertTextAfter ( lastToken , " " ) ; } return fixer . removeRange ( [ lastToken . range [ 1 ] , closeBrace . range [ 0 ] ] ) ; } } ) ; } }
Reports invalid spacing style inside braces.
@param {ASTNode} node - A BlockStatement/SwitchStatement node to get.
@returns {void}
Reports invalid spacing style inside braces .