Skip to content

Commit

Permalink
standard
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Oct 29, 2020
1 parent 42f0368 commit 8d0b08f
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 66 deletions.
22 changes: 11 additions & 11 deletions rules/array-bracket-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = {
},

create: function (context) {
var spaced = context.options[0] === 'always'
var either = context.options[0] === 'either'
const spaced = context.options[0] === 'always'
const either = context.options[0] === 'either'

/**
* Determines whether an option is set, relative to the spacing option.
Expand All @@ -34,7 +34,7 @@ module.exports = {
return context.options[1] != null ? context.options[1][option] === !spaced : false
}

var options = {
const options = {
either,
spaced,
singleElementException: isOptionSet('singleValue'),
Expand Down Expand Up @@ -119,8 +119,8 @@ module.exports = {
* @returns {boolean}
*/
function isEvenlySpacedAndNotTooLong (node, start, end) {
var expectedSpace = start[1].range[0] - start[0].range[1]
var endSpace = end[1].range[0] - end[0].range[1]
const expectedSpace = start[1].range[0] - start[0].range[1]
const endSpace = end[1].range[0] - end[0].range[1]
return endSpace === expectedSpace && endSpace <= 1
}

Expand All @@ -134,19 +134,19 @@ module.exports = {
return
}

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

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

var closingBracketMustBeSpaced =
const closingBracketMustBeSpaced =
(options.objectsInArraysException && penultimate.value === '}') ||
(options.arraysInArraysException && penultimate.value === ']') ||
(options.singleElementException && node.elements.length === 1)
Expand Down
16 changes: 8 additions & 8 deletions rules/computed-property-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = {
},

create: function (context) {
var propertyNameMustBeSpaced = context.options[0] === 'always' // default is "never"
var propertyNameMustBeEven = context.options[0] === 'even' // default is "never"
const propertyNameMustBeSpaced = context.options[0] === 'always' // default is "never"
const propertyNameMustBeEven = context.options[0] === 'even' // default is "never"

// --------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -100,13 +100,13 @@ module.exports = {
return
}

var property = node[propertyName]
const 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
const before = context.getTokenBefore(property)
const first = context.getFirstToken(property)
const last = context.getLastToken(property)
const after = context.getTokenAfter(property)
let startSpace, endSpace

if (propertyNameMustBeEven) {
if (!isSameLine(before, after)) {
Expand Down
9 changes: 5 additions & 4 deletions rules/no-callback-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @returns {boolean} True if there is a chance it contains an Error obj
*/
function couldBeError (node) {
let exprs
switch (node.type) {
case 'Identifier':
case 'CallExpression':
Expand All @@ -28,7 +29,7 @@ function couldBeError (node) {
return couldBeError(node.right)

case 'SequenceExpression':
var exprs = node.expressions
exprs = node.expressions
return exprs.length !== 0 && couldBeError(exprs[exprs.length - 1])

case 'LogicalExpression':
Expand All @@ -54,7 +55,7 @@ module.exports = {
},

create: function (context) {
var callbackNames = context.options[0] || ['callback', 'cb']
const callbackNames = context.options[0] || ['callback', 'cb']

function isCallback (name) {
return callbackNames.indexOf(name) > -1
Expand All @@ -63,8 +64,8 @@ module.exports = {
return {

CallExpression: function (node) {
var errorArg = node.arguments[0]
var calleeName = node.callee.name
const errorArg = node.arguments[0]
const calleeName = node.callee.name

if (errorArg && !couldBeError(errorArg) && isCallback(calleeName)) {
context.report(node, 'Unexpected literal in error position of callback.')
Expand Down
56 changes: 28 additions & 28 deletions rules/object-curly-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = {
},

create: function (context) {
var spaced = context.options[0] === 'always'
var either = context.options[0] === 'either'
const spaced = context.options[0] === 'always'
const either = context.options[0] === 'either'

/**
* Determines whether an option is set, relative to the spacing option.
Expand All @@ -34,7 +34,7 @@ module.exports = {
return context.options[1] != null ? context.options[1][option] === !spaced : false
}

var options = {
const options = {
spaced,
either,
arraysInObjectsException: isOptionSet('arraysInObjects'),
Expand Down Expand Up @@ -118,8 +118,8 @@ module.exports = {
* @returns {boolean}
*/
function isEvenlySpacedAndNotTooLong (node, start, end) {
var expectedSpace = start[1].range[0] - start[0].range[1]
var endSpace = end[1].range[0] - end[0].range[1]
const expectedSpace = start[1].range[0] - start[0].range[1]
const endSpace = end[1].range[0] - end[0].range[1]
return endSpace === expectedSpace && endSpace <= 1
}

Expand All @@ -133,7 +133,7 @@ module.exports = {
* @returns {void}
*/
function validateBraceSpacing (node, first, second, penultimate, last) {
var closingCurlyBraceMustBeSpaced =
const closingCurlyBraceMustBeSpaced =
(options.arraysInObjectsException && penultimate.value === ']') ||
(options.objectsInObjectsException && penultimate.value === '}')
? !options.spaced
Expand Down Expand Up @@ -186,13 +186,13 @@ module.exports = {
return
}

var firstSpecifier = node.properties[0]
var lastSpecifier = node.properties[node.properties.length - 1]
const firstSpecifier = node.properties[0]
const lastSpecifier = node.properties[node.properties.length - 1]

var first = context.getTokenBefore(firstSpecifier)
var second = context.getFirstToken(firstSpecifier)
var penultimate = context.getLastToken(lastSpecifier)
var last = context.getTokenAfter(lastSpecifier)
const first = context.getTokenBefore(firstSpecifier)
const second = context.getFirstToken(firstSpecifier)
let penultimate = context.getLastToken(lastSpecifier)
let last = context.getTokenAfter(lastSpecifier)

// support trailing commas
if (last.value === ',') {
Expand All @@ -205,15 +205,15 @@ module.exports = {

// import {y} from 'x'
ImportDeclaration: function (node) {
var firstSpecifier = node.specifiers[0]
var lastSpecifier = node.specifiers[node.specifiers.length - 1]
const firstSpecifier = node.specifiers[0]
const lastSpecifier = node.specifiers[node.specifiers.length - 1]

// don't do anything for namespace or default imports
if (firstSpecifier && lastSpecifier && firstSpecifier.type === 'ImportSpecifier' && lastSpecifier.type === 'ImportSpecifier') {
var first = context.getTokenBefore(firstSpecifier)
var second = context.getFirstToken(firstSpecifier)
var penultimate = context.getLastToken(lastSpecifier)
var last = context.getTokenAfter(lastSpecifier)
const first = context.getTokenBefore(firstSpecifier)
const second = context.getFirstToken(firstSpecifier)
const penultimate = context.getLastToken(lastSpecifier)
const last = context.getTokenAfter(lastSpecifier)

validateBraceSpacing(node, first, second, penultimate, last)
}
Expand All @@ -225,12 +225,12 @@ module.exports = {
return
}

var firstSpecifier = node.specifiers[0]
var lastSpecifier = node.specifiers[node.specifiers.length - 1]
var first = context.getTokenBefore(firstSpecifier)
var second = context.getFirstToken(firstSpecifier)
var penultimate = context.getLastToken(lastSpecifier)
var last = context.getTokenAfter(lastSpecifier)
const firstSpecifier = node.specifiers[0]
const lastSpecifier = node.specifiers[node.specifiers.length - 1]
const first = context.getTokenBefore(firstSpecifier)
const second = context.getFirstToken(firstSpecifier)
const penultimate = context.getLastToken(lastSpecifier)
const last = context.getTokenAfter(lastSpecifier)

validateBraceSpacing(node, first, second, penultimate, last)
},
Expand All @@ -241,10 +241,10 @@ module.exports = {
return
}

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

validateBraceSpacing(node, first, second, penultimate, last)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/array-bracket-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
// Requirements
// ------------------------------------------------------------------------------

var RuleTester = require('eslint').RuleTester
var rule = require('../rules/array-bracket-even-spacing')
var parserOptions = { ecmaVersion: 2018, sourceType: 'module' }
const RuleTester = require('eslint').RuleTester
const rule = require('../rules/array-bracket-even-spacing')
const parserOptions = { ecmaVersion: 2018, sourceType: 'module' }

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester()
const ruleTester = new RuleTester()
ruleTester.run('array-bracket-even-spacing', rule, {
valid: [

Expand Down
8 changes: 4 additions & 4 deletions tests/computed-property-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
// Requirements
// ------------------------------------------------------------------------------

var RuleTester = require('eslint').RuleTester
var rule = require('../rules/computed-property-even-spacing')
const RuleTester = require('eslint').RuleTester
const rule = require('../rules/computed-property-even-spacing')

var parserOptions = { ecmaVersion: 2018, sourceType: 'module' }
const parserOptions = { ecmaVersion: 2018, sourceType: 'module' }

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester()
const ruleTester = new RuleTester()
ruleTester.run('computed-property-even-spacing', rule, {
valid: [

Expand Down
6 changes: 3 additions & 3 deletions tests/no-callback-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// Requirements
// ------------------------------------------------------------------------------

var RuleTester = require('eslint').RuleTester
var rule = require('../rules/no-callback-literal')
const RuleTester = require('eslint').RuleTester
const rule = require('../rules/no-callback-literal')

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester()
const ruleTester = new RuleTester()
ruleTester.run('no-callback-literal', rule, {
valid: [

Expand Down
8 changes: 4 additions & 4 deletions tests/object-curly-even-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
// Requirements
// ------------------------------------------------------------------------------

var RuleTester = require('eslint').RuleTester
var rule = require('../rules/object-curly-even-spacing')
var parserOptions = { ecmaVersion: 2018, sourceType: 'module' }
const RuleTester = require('eslint').RuleTester
const rule = require('../rules/object-curly-even-spacing')
const parserOptions = { ecmaVersion: 2018, sourceType: 'module' }

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester()
const ruleTester = new RuleTester()
ruleTester.run('object-curly-even-spacing', rule, {
valid: [

Expand Down

0 comments on commit 8d0b08f

Please sign in to comment.