rules/object-curly-even-spacing.js
function validateBraceSpacing (node, first, second, penultimate, last) {
      var closingCurlyBraceMustBeSpaced =
      (options.arraysInObjectsException && penultimate.value === ']') ||
      (options.objectsInObjectsException && penultimate.value === '}')
        ? !options.spaced : options.spaced

      // we only care about evenly spaced things
      if (options.either) {
        // newlines at any point means return
        if (!isSameLine(first, last)) {
          return
        }

        // confirm that the object expression/literal is spaced evenly
        if (!isEvenlySpacedAndNotTooLong(node, [first, second], [penultimate, last])) {
          context.report(node, 'Expected consistent spacing')
        }

        return
      }

      // { and key are on same line
      if (isSameLine(first, second)) {
        if (options.spaced && !isSpaced(first, second)) {
          reportRequiredBeginningSpace(node, first)
        }
        if (!options.spaced && isSpaced(first, second)) {
          reportNoBeginningSpace(node, first)
        }
      }

      // final key and } ore on the same line
      if (isSameLine(penultimate, last)) {
        if (closingCurlyBraceMustBeSpaced && !isSpaced(penultimate, last)) {
          reportRequiredEndingSpace(node, last)
        }
        if (!closingCurlyBraceMustBeSpaced && isSpaced(penultimate, last)) {
          reportNoEndingSpace(node, last)
        }
      }
    }
function validateBraceSpacing (node, first, second, penultimate, last) {
      var closingCurlyBraceMustBeSpaced =
      (options.arraysInObjectsException && penultimate.value === ']') ||
      (options.objectsInObjectsException && penultimate.value === '}')
        ? !options.spaced : options.spaced

      // we only care about evenly spaced things
      if (options.either) {
        // newlines at any point means return
        if (!isSameLine(first, last)) {
          return
        }

        // confirm that the object expression/literal is spaced evenly
        if (!isEvenlySpacedAndNotTooLong(node, [first, second], [penultimate, last])) {
          context.report(node, 'Expected consistent spacing')
        }

        return
      }

      // { and key are on same line
      if (isSameLine(first, second)) {
        if (options.spaced && !isSpaced(first, second)) {
          reportRequiredBeginningSpace(node, first)
        }
        if (!options.spaced && isSpaced(first, second)) {
          reportNoBeginningSpace(node, first)
        }
      }

      // final key and } ore on the same line
      if (isSameLine(penultimate, last)) {
        if (closingCurlyBraceMustBeSpaced && !isSpaced(penultimate, last)) {
          reportRequiredEndingSpace(node, last)
        }
        if (!closingCurlyBraceMustBeSpaced && isSpaced(penultimate, last)) {
          reportNoEndingSpace(node, last)
        }
      }
    }
function validateBraceSpacing ( node , first , second , penultimate , last ) { var closingCurlyBraceMustBeSpaced = ( options . arraysInObjectsException && penultimate . value === ']' ) || ( options . objectsInObjectsException && penultimate . value === '}' ) ? ! options . spaced : options . spaced // we only care about evenly spaced things if ( options . either ) { // newlines at any point means return if ( ! isSameLine ( first , last ) ) { return } // confirm that the object expression/literal is spaced evenly if ( ! isEvenlySpacedAndNotTooLong ( node , [ first , second ] , [ penultimate , last ] ) ) { context . report ( node , 'Expected consistent spacing' ) } return } // { and key are on same line if ( isSameLine ( first , second ) ) { if ( options . spaced && ! isSpaced ( first , second ) ) { reportRequiredBeginningSpace ( node , first ) } if ( ! options . spaced && isSpaced ( first , second ) ) { reportNoBeginningSpace ( node , first ) } } // final key and } ore on the same line if ( isSameLine ( penultimate , last ) ) { if ( closingCurlyBraceMustBeSpaced && ! isSpaced ( penultimate , last ) ) { reportRequiredEndingSpace ( node , last ) } if ( ! closingCurlyBraceMustBeSpaced && isSpaced ( penultimate , last ) ) { reportNoEndingSpace ( node , last ) } } }
Determines if spacing in curly braces is valid.
@param {ASTNode} node The AST node to check.
@param {Token} first The first token to check (should be the opening brace)
@param {Token} second The second token to check (should be first after the opening brace)
@param {Token} penultimate The penultimate token to check (should be last before closing brace)
@param {Token} last The last token to check (should be closing brace)
@returns {void}
Determines if spacing in curly braces is valid .