packages/eslint-plugin-internal/padded-blocks.js
function checkPadding(node, type) {
      const openBrace = getOpenBrace(node);
      const firstBlockToken = getFirstBlockToken(openBrace);
      const tokenBeforeFirst = sourceCode.getTokenBefore(firstBlockToken, { includeComments: true });
      const closeBrace = sourceCode.getLastToken(node);
      const lastBlockToken = getLastBlockToken(closeBrace);
      const tokenAfterLast = sourceCode.getTokenAfter(lastBlockToken, { includeComments: true });
      const blockHasTopPadding = isPaddingBetweenTokens(tokenBeforeFirst, firstBlockToken);
      const blockHasBottomPadding = isPaddingBetweenTokens(lastBlockToken, tokenAfterLast);
      const onlyTopPadding = context.options[0][type] === 'top';
      const onlyBottomPadding = context.options[0][type] === 'bottom';

      if (requirePaddingFor(node)) {
        if (!blockHasTopPadding && !onlyBottomPadding) {
          context.report({
            node,
            loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
            fix(fixer) {
              return fixer.insertTextAfter(tokenBeforeFirst, '\n');
            },
            message: ALWAYS_MESSAGE,
          });
        }

        if (!blockHasBottomPadding && !onlyTopPadding) {
          context.report({
            node,
            loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
            fix(fixer) {
              return fixer.insertTextBefore(tokenAfterLast, '\n');
            },
            message: ALWAYS_MESSAGE,
          });
        }
      } else {
        if (blockHasTopPadding && !onlyBottomPadding) {
          context.report({
            node,
            loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
            fix(fixer) {
              return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], '\n');
            },
            message: NEVER_MESSAGE,
          });
        }

        if (blockHasBottomPadding && !onlyTopPadding) {
          context.report({
            node,
            loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
            fix(fixer) {
              return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], '\n');
            },
            message: NEVER_MESSAGE,
          });
        }
      }
    }
function checkPadding(node, type) {
      const openBrace = getOpenBrace(node);
      const firstBlockToken = getFirstBlockToken(openBrace);
      const tokenBeforeFirst = sourceCode.getTokenBefore(firstBlockToken, { includeComments: true });
      const closeBrace = sourceCode.getLastToken(node);
      const lastBlockToken = getLastBlockToken(closeBrace);
      const tokenAfterLast = sourceCode.getTokenAfter(lastBlockToken, { includeComments: true });
      const blockHasTopPadding = isPaddingBetweenTokens(tokenBeforeFirst, firstBlockToken);
      const blockHasBottomPadding = isPaddingBetweenTokens(lastBlockToken, tokenAfterLast);
      const onlyTopPadding = context.options[0][type] === 'top';
      const onlyBottomPadding = context.options[0][type] === 'bottom';

      if (requirePaddingFor(node)) {
        if (!blockHasTopPadding && !onlyBottomPadding) {
          context.report({
            node,
            loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
            fix(fixer) {
              return fixer.insertTextAfter(tokenBeforeFirst, '\n');
            },
            message: ALWAYS_MESSAGE,
          });
        }

        if (!blockHasBottomPadding && !onlyTopPadding) {
          context.report({
            node,
            loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
            fix(fixer) {
              return fixer.insertTextBefore(tokenAfterLast, '\n');
            },
            message: ALWAYS_MESSAGE,
          });
        }
      } else {
        if (blockHasTopPadding && !onlyBottomPadding) {
          context.report({
            node,
            loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
            fix(fixer) {
              return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], '\n');
            },
            message: NEVER_MESSAGE,
          });
        }

        if (blockHasBottomPadding && !onlyTopPadding) {
          context.report({
            node,
            loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
            fix(fixer) {
              return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], '\n');
            },
            message: NEVER_MESSAGE,
          });
        }
      }
    }
function checkPadding ( node , type ) { const openBrace = getOpenBrace ( node ) ; const firstBlockToken = getFirstBlockToken ( openBrace ) ; const tokenBeforeFirst = sourceCode . getTokenBefore ( firstBlockToken , { includeComments : true } ) ; const closeBrace = sourceCode . getLastToken ( node ) ; const lastBlockToken = getLastBlockToken ( closeBrace ) ; const tokenAfterLast = sourceCode . getTokenAfter ( lastBlockToken , { includeComments : true } ) ; const blockHasTopPadding = isPaddingBetweenTokens ( tokenBeforeFirst , firstBlockToken ) ; const blockHasBottomPadding = isPaddingBetweenTokens ( lastBlockToken , tokenAfterLast ) ; const onlyTopPadding = context . options [ 0 ] [ type ] === 'top' ; const onlyBottomPadding = context . options [ 0 ] [ type ] === 'bottom' ; if ( requirePaddingFor ( node ) ) { if ( ! blockHasTopPadding && ! onlyBottomPadding ) { context . report ( { node , loc : { line : tokenBeforeFirst . loc . start . line , column : tokenBeforeFirst . loc . start . column } , fix ( fixer ) { return fixer . insertTextAfter ( tokenBeforeFirst , '\n' ) ; } , message : ALWAYS_MESSAGE , } ) ; } if ( ! blockHasBottomPadding && ! onlyTopPadding ) { context . report ( { node , loc : { line : tokenAfterLast . loc . end . line , column : tokenAfterLast . loc . end . column - 1 } , fix ( fixer ) { return fixer . insertTextBefore ( tokenAfterLast , '\n' ) ; } , message : ALWAYS_MESSAGE , } ) ; } } else { if ( blockHasTopPadding && ! onlyBottomPadding ) { context . report ( { node , loc : { line : tokenBeforeFirst . loc . start . line , column : tokenBeforeFirst . loc . start . column } , fix ( fixer ) { return fixer . replaceTextRange ( [ tokenBeforeFirst . range [ 1 ] , firstBlockToken . range [ 0 ] - firstBlockToken . loc . start . column ] , '\n' ) ; } , message : NEVER_MESSAGE , } ) ; } if ( blockHasBottomPadding && ! onlyTopPadding ) { context . report ( { node , loc : { line : tokenAfterLast . loc . end . line , column : tokenAfterLast . loc . end . column - 1 } , fix ( fixer ) { return fixer . replaceTextRange ( [ lastBlockToken . range [ 1 ] , tokenAfterLast . range [ 0 ] - tokenAfterLast . loc . start . column ] , '\n' ) ; } , message : NEVER_MESSAGE , } ) ; } } }
Checks the given BlockStatement node to be padded if the block is not empty.
@param {ASTNode} node The AST node of a BlockStatement.
@returns {void} undefined.
Checks the given BlockStatement node to be padded if the block is not empty .