rules/computed-property-even-spacing.js
function checkSpacing (propertyName) {
      return function (node) {
        if (!node.computed) {
          return
        }

        var property = node[propertyName]

        var before = context.getTokenBefore(property)
        var first = context.getFirstToken(property)
        var last = context.getLastToken(property)
        var after = context.getTokenAfter(property)
        var startSpace, endSpace

        if (propertyNameMustBeEven) {
          if (!isSameLine(before, after)) {
            context.report(node, 'Expected "[" and "]" to be on the same line')
            return
          }
          startSpace = first.loc.start.column - before.loc.end.column
          endSpace = after.loc.start.column - last.loc.end.column

          if (startSpace !== endSpace || startSpace > 1) {
            context.report(node, 'Expected 1 or 0 spaces around "[" and "]"')
          }

          return
        }

        if (isSameLine(before, first)) {
          if (propertyNameMustBeSpaced) {
            if (!isSpaced(before, first) && isSameLine(before, first)) {
              reportRequiredBeginningSpace(node, before)
            }
          } else {
            if (isSpaced(before, first)) {
              reportNoBeginningSpace(node, before)
            }
          }
        }

        if (isSameLine(last, after)) {
          if (propertyNameMustBeSpaced) {
            if (!isSpaced(last, after) && isSameLine(last, after)) {
              reportRequiredEndingSpace(node, after)
            }
          } else {
            if (isSpaced(last, after)) {
              reportNoEndingSpace(node, after)
            }
          }
        }
      }
    }
function checkSpacing (propertyName) {
      return function (node) {
        if (!node.computed) {
          return
        }

        var property = node[propertyName]

        var before = context.getTokenBefore(property)
        var first = context.getFirstToken(property)
        var last = context.getLastToken(property)
        var after = context.getTokenAfter(property)
        var startSpace, endSpace

        if (propertyNameMustBeEven) {
          if (!isSameLine(before, after)) {
            context.report(node, 'Expected "[" and "]" to be on the same line')
            return
          }
          startSpace = first.loc.start.column - before.loc.end.column
          endSpace = after.loc.start.column - last.loc.end.column

          if (startSpace !== endSpace || startSpace > 1) {
            context.report(node, 'Expected 1 or 0 spaces around "[" and "]"')
          }

          return
        }

        if (isSameLine(before, first)) {
          if (propertyNameMustBeSpaced) {
            if (!isSpaced(before, first) && isSameLine(before, first)) {
              reportRequiredBeginningSpace(node, before)
            }
          } else {
            if (isSpaced(before, first)) {
              reportNoBeginningSpace(node, before)
            }
          }
        }

        if (isSameLine(last, after)) {
          if (propertyNameMustBeSpaced) {
            if (!isSpaced(last, after) && isSameLine(last, after)) {
              reportRequiredEndingSpace(node, after)
            }
          } else {
            if (isSpaced(last, after)) {
              reportNoEndingSpace(node, after)
            }
          }
        }
      }
    }
function checkSpacing ( propertyName ) { return function ( node ) { if ( ! node . computed ) { return } var property = node [ propertyName ] var before = context . getTokenBefore ( property ) var first = context . getFirstToken ( property ) var last = context . getLastToken ( property ) var after = context . getTokenAfter ( property ) var startSpace , endSpace if ( propertyNameMustBeEven ) { if ( ! isSameLine ( before , after ) ) { context . report ( node , 'Expected "[" and "]" to be on the same line' ) return } startSpace = first . loc . start . column - before . loc . end . column endSpace = after . loc . start . column - last . loc . end . column if ( startSpace !== endSpace || startSpace > 1 ) { context . report ( node , 'Expected 1 or 0 spaces around "[" and "]"' ) } return } if ( isSameLine ( before , first ) ) { if ( propertyNameMustBeSpaced ) { if ( ! isSpaced ( before , first ) && isSameLine ( before , first ) ) { reportRequiredBeginningSpace ( node , before ) } } else { if ( isSpaced ( before , first ) ) { reportNoBeginningSpace ( node , before ) } } } if ( isSameLine ( last , after ) ) { if ( propertyNameMustBeSpaced ) { if ( ! isSpaced ( last , after ) && isSameLine ( last , after ) ) { reportRequiredEndingSpace ( node , after ) } } else { if ( isSpaced ( last , after ) ) { reportNoEndingSpace ( node , after ) } } } } }
Returns a function that checks the spacing of a node on the property name
that was passed in.
@param {String} propertyName The property on the node to check for spacing
@returns {Function} A function that will check spacing on a node
Returns a function that checks the spacing of a node on the property name that was passed in .