rules/array-bracket-even-spacing.js
function validateArraySpacing (node) {
      if (node.elements.length === 0) {
        return
      }

      var first = context.getFirstToken(node)
      var second = context.getFirstToken(node, 1)
      var penultimate = context.getLastToken(node, 1)
      var last = context.getLastToken(node)

      var openingBracketMustBeSpaced =
      (options.objectsInArraysException && second.value === '{') ||
      (options.arraysInArraysException && second.value === '[') ||
      (options.singleElementException && node.elements.length === 1)
        ? !options.spaced : options.spaced

      var closingBracketMustBeSpaced =
      (options.objectsInArraysException && penultimate.value === '}') ||
      (options.arraysInArraysException && penultimate.value === ']') ||
      (options.singleElementException && node.elements.length === 1)
        ? !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
      }

      if (isSameLine(first, second)) {
        if (openingBracketMustBeSpaced && !isSpaced(first, second)) {
          reportRequiredBeginningSpace(node, first)
        }
        if (!openingBracketMustBeSpaced && isSpaced(first, second)) {
          reportNoBeginningSpace(node, first)
        }
      }

      if (isSameLine(penultimate, last)) {
        if (closingBracketMustBeSpaced && !isSpaced(penultimate, last)) {
          reportRequiredEndingSpace(node, last)
        }
        if (!closingBracketMustBeSpaced && isSpaced(penultimate, last)) {
          reportNoEndingSpace(node, last)
        }
      }
    }
function validateArraySpacing (node) {
      if (node.elements.length === 0) {
        return
      }

      var first = context.getFirstToken(node)
      var second = context.getFirstToken(node, 1)
      var penultimate = context.getLastToken(node, 1)
      var last = context.getLastToken(node)

      var openingBracketMustBeSpaced =
      (options.objectsInArraysException && second.value === '{') ||
      (options.arraysInArraysException && second.value === '[') ||
      (options.singleElementException && node.elements.length === 1)
        ? !options.spaced : options.spaced

      var closingBracketMustBeSpaced =
      (options.objectsInArraysException && penultimate.value === '}') ||
      (options.arraysInArraysException && penultimate.value === ']') ||
      (options.singleElementException && node.elements.length === 1)
        ? !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
      }

      if (isSameLine(first, second)) {
        if (openingBracketMustBeSpaced && !isSpaced(first, second)) {
          reportRequiredBeginningSpace(node, first)
        }
        if (!openingBracketMustBeSpaced && isSpaced(first, second)) {
          reportNoBeginningSpace(node, first)
        }
      }

      if (isSameLine(penultimate, last)) {
        if (closingBracketMustBeSpaced && !isSpaced(penultimate, last)) {
          reportRequiredEndingSpace(node, last)
        }
        if (!closingBracketMustBeSpaced && isSpaced(penultimate, last)) {
          reportNoEndingSpace(node, last)
        }
      }
    }
function validateArraySpacing ( node ) { if ( node . elements . length === 0 ) { return } var first = context . getFirstToken ( node ) var second = context . getFirstToken ( node , 1 ) var penultimate = context . getLastToken ( node , 1 ) var last = context . getLastToken ( node ) var openingBracketMustBeSpaced = ( options . objectsInArraysException && second . value === '{' ) || ( options . arraysInArraysException && second . value === '[' ) || ( options . singleElementException && node . elements . length === 1 ) ? ! options . spaced : options . spaced var closingBracketMustBeSpaced = ( options . objectsInArraysException && penultimate . value === '}' ) || ( options . arraysInArraysException && penultimate . value === ']' ) || ( options . singleElementException && node . elements . length === 1 ) ? ! 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 } if ( isSameLine ( first , second ) ) { if ( openingBracketMustBeSpaced && ! isSpaced ( first , second ) ) { reportRequiredBeginningSpace ( node , first ) } if ( ! openingBracketMustBeSpaced && isSpaced ( first , second ) ) { reportNoBeginningSpace ( node , first ) } } if ( isSameLine ( penultimate , last ) ) { if ( closingBracketMustBeSpaced && ! isSpaced ( penultimate , last ) ) { reportRequiredEndingSpace ( node , last ) } if ( ! closingBracketMustBeSpaced && isSpaced ( penultimate , last ) ) { reportNoEndingSpace ( node , last ) } } }
Validates the spacing around array brackets
@param {ASTNode} node - The node we're checking for spacing
@returns {void}
Validates the spacing around array brackets