Skip to content

Commit

Permalink
var -> const using eslint auto fix, phetsims/tasks#1012
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Sep 19, 2019
1 parent 97f2f4c commit 4c24376
Show file tree
Hide file tree
Showing 41 changed files with 1,027 additions and 1,027 deletions.
20 changes: 10 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module.exports = function( grunt ) {
'use strict';

grunt.registerTask( 'doc-dot', 'Generates Documentation', function() {
var indexHTML = '';
var contentHTML = '';
let indexHTML = '';
let contentHTML = '';

var localTypeIds = {
const localTypeIds = {
BinPacker: 'binPacker',
Bin: 'binPacker-bin',
Bounds2: 'bounds2',
Expand Down Expand Up @@ -54,21 +54,21 @@ module.exports = function( grunt ) {
Vector4: 'vector4'
};

var externalTypeURLs = {
const externalTypeURLs = {
Events: '../../axon/doc#events',
Shape: '../../kite/doc#shape'
};

function docFile( file, baseName, typeNames ) {
var codeFile = fs.readFileSync( file, 'utf8' );
var program = esprima.parse( codeFile, {
const codeFile = fs.readFileSync( file, 'utf8' );
const program = esprima.parse( codeFile, {
attachComment: true
} );
var doc = extractDocumentation( program );
const doc = extractDocumentation( program );
if ( baseName === 'ConvexHull2' ) { // for testing
// console.log( JSON.stringify( doc, null, 2 ) );
}
var htmlDoc = documentationToHTML( doc, baseName, typeNames, localTypeIds, externalTypeURLs );
const htmlDoc = documentationToHTML( doc, baseName, typeNames, localTypeIds, externalTypeURLs );

indexHTML += htmlDoc.indexHTML;
contentHTML += htmlDoc.contentHTML;
Expand All @@ -87,9 +87,9 @@ module.exports = function( grunt ) {
docFile( 'js/Vector3.js', 'Vector3', [ 'Vector3' ] );
docFile( 'js/Vector4.js', 'Vector4', [ 'Vector4' ] );

var template = fs.readFileSync( 'doc/template.html', 'utf8' );
const template = fs.readFileSync( 'doc/template.html', 'utf8' );

var html = template.replace( '{{API_INDEX}}', indexHTML ).replace( '{{API_CONTENT}}', contentHTML );
let html = template.replace( '{{API_INDEX}}', indexHTML ).replace( '{{API_CONTENT}}', contentHTML );

html = beautify_html( html, { indent_size: 2 } );

Expand Down
28 changes: 14 additions & 14 deletions js/BinPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ define( require => {
*/
allocate: function( width, height ) {
// find a leaf bin that has available room (or null)
var bin = this.rootBin.findAvailableBin( width, height );
const bin = this.rootBin.findAvailableBin( width, height );

if ( bin ) {
// split it into a sized sub-bin for our purpose that we will use, and other bins for future allocations
var sizedBin = bin.split( width, height );
const sizedBin = bin.split( width, height );

// mark our bin as used
sizedBin.use();
Expand All @@ -91,9 +91,9 @@ define( require => {
* @returns {string}
*/
toString: function() {
var result = '';
let result = '';

var padding = '';
let padding = '';

function binTree( bin ) {
result += padding + bin.toString() + '\n';
Expand Down Expand Up @@ -155,8 +155,8 @@ define( require => {
}
// If we have been split, check our children
else if ( this.isSplit ) {
for ( var i = 0; i < this.children.length; i++ ) {
var result = this.children[ i ].findAvailableBin( width, height );
for ( let i = 0; i < this.children.length; i++ ) {
const result = this.children[ i ].findAvailableBin( width, height );
if ( result ) {
return result;
}
Expand Down Expand Up @@ -193,8 +193,8 @@ define( require => {
this.isSplit = true;

// locations of the split
var splitX = this.bounds.minX + width;
var splitY = this.bounds.minY + height;
const splitX = this.bounds.minX + width;
const splitY = this.bounds.minY + height;

/*
* How an area is split (for now). In the future, splitting more after determining what we need to fit next would
Expand All @@ -212,11 +212,11 @@ define( require => {
* * *
* ************************************
*/
var mainBounds = new Bounds2( this.bounds.minX, this.bounds.minY, splitX, splitY );
var rightBounds = new Bounds2( splitX, this.bounds.minY, this.bounds.maxX, splitY );
var bottomBounds = new Bounds2( this.bounds.minX, splitY, this.bounds.maxX, this.bounds.maxY );
const mainBounds = new Bounds2( this.bounds.minX, this.bounds.minY, splitX, splitY );
const rightBounds = new Bounds2( splitX, this.bounds.minY, this.bounds.maxX, splitY );
const bottomBounds = new Bounds2( this.bounds.minX, splitY, this.bounds.maxX, this.bounds.maxY );

var mainBin = new dot.BinPacker.Bin( mainBounds, this );
const mainBin = new dot.BinPacker.Bin( mainBounds, this );
this.children.push( mainBin );

// only add right/bottom if they take up area
Expand Down Expand Up @@ -264,8 +264,8 @@ define( require => {

// Bail out if a single child isn't able to be collapsed. If it is not split or used, it won't have any children
// or needs.
for ( var i = 0; i < this.children.length; i++ ) {
var child = this.children[ i ];
for ( let i = 0; i < this.children.length; i++ ) {
const child = this.children[ i ];

if ( child.isSplit || child.isUsed ) {
return;
Expand Down
16 changes: 8 additions & 8 deletions js/BinPackerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ define( require => {
QUnit.module( 'BinPacker' );

QUnit.test( 'Entire BinPacker allocation', function( assert ) {
var p = new BinPacker( new Bounds2( 0, 0, 1, 1 ) );
var bin = p.allocate( 1, 1 );
const p = new BinPacker( new Bounds2( 0, 0, 1, 1 ) );
const bin = p.allocate( 1, 1 );
assert.ok( bin, 'Should have a bin' );
assert.ok( !p.allocate( 1, 1 ), 'Should not be able to fit another bin' );
} );

QUnit.test( 'Many bins', function( assert ) {
function checkNoOverlappingBins( array, containingBounds ) {
for ( var i = 0; i < array.length; i++ ) {
for ( let i = 0; i < array.length; i++ ) {
if ( array[ i ] ) {
assert.ok( array[ i ].bounds.intersection( containingBounds ).equals( array[ i ].bounds ), 'Bin containment in packer' );
for ( var j = 0; j < array.length; j++ ) {
for ( let j = 0; j < array.length; j++ ) {
if ( array[ i ] && array[ j ] ) {
assert.ok( !array[ i ].bounds.intersection( array[ j ] ).hasNonzeroArea(), 'Bin intersection' );
}
Expand All @@ -35,11 +35,11 @@ define( require => {
}
}

var bounds = new Bounds2( 0, 0, 1, 1 );
const bounds = new Bounds2( 0, 0, 1, 1 );

// manual selection
var p = new BinPacker( bounds );
var bins = [];
let p = new BinPacker( bounds );
let bins = [];
bins.push( p.allocate( 0.5, 0.5 ) );
bins.push( p.allocate( 0.7, 0.5 ) );
bins.push( p.allocate( 0.25, 0.25 ) );
Expand Down Expand Up @@ -160,7 +160,7 @@ define( require => {
}

// once empty, ensure we can allocate the full thing
var fullBin = p.allocate( 1, 1 );
const fullBin = p.allocate( 1, 1 );
assert.ok( fullBin, 'Allocation of full bin' );
} );
} );
44 changes: 22 additions & 22 deletions js/Bounds2.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define( require => {
const Vector2 = require( 'DOT/Vector2' );

// Temporary instances to be used in the transform method.
var scratchVector2 = new dot.Vector2( 0, 0 );
const scratchVector2 = new dot.Vector2( 0, 0 );

/**
* Creates a 2-dimensional bounds (bounding box).
Expand Down Expand Up @@ -327,8 +327,8 @@ define( require => {
return location;
}
else {
var xConstrained = Math.max( Math.min( location.x, this.maxX ), this.x );
var yConstrained = Math.max( Math.min( location.y, this.maxY ), this.y );
const xConstrained = Math.max( Math.min( location.x, this.maxX ), this.x );
const yConstrained = Math.max( Math.min( location.y, this.maxY ), this.y );
return new Vector2( xConstrained, yConstrained );
}
},
Expand Down Expand Up @@ -376,10 +376,10 @@ define( require => {
* @returns {boolean}
*/
intersectsBounds: function( bounds ) {
var minX = Math.max( this.minX, bounds.minX );
var minY = Math.max( this.minY, bounds.minY );
var maxX = Math.min( this.maxX, bounds.maxX );
var maxY = Math.min( this.maxY, bounds.maxY );
const minX = Math.max( this.minX, bounds.minX );
const minY = Math.max( this.minY, bounds.minY );
const maxX = Math.min( this.maxX, bounds.maxX );
const maxY = Math.min( this.maxY, bounds.maxY );
return ( maxX - minX ) >= 0 && ( maxY - minY >= 0 );
},

Expand All @@ -391,9 +391,9 @@ define( require => {
* @returns {number}
*/
minimumDistanceToPointSquared: function( point ) {
var closeX = point.x < this.minX ? this.minX : ( point.x > this.maxX ? this.maxX : null );
var closeY = point.y < this.minY ? this.minY : ( point.y > this.maxY ? this.maxY : null );
var d;
const closeX = point.x < this.minX ? this.minX : ( point.x > this.maxX ? this.maxX : null );
const closeY = point.y < this.minY ? this.minY : ( point.y > this.maxY ? this.maxY : null );
let d;
if ( closeX === null && closeY === null ) {
// inside, or on the boundary
return 0;
Expand All @@ -410,8 +410,8 @@ define( require => {
}
else {
// corner case
var dx = closeX - point.x;
var dy = closeY - point.y;
const dx = closeX - point.x;
const dy = closeY - point.y;
return dx * dx + dy * dy;
}
},
Expand All @@ -424,8 +424,8 @@ define( require => {
* @returns {number}
*/
maximumDistanceToPointSquared: function( point ) {
var x = point.x > this.getCenterX() ? this.minX : this.maxX;
var y = point.y > this.getCenterY() ? this.minY : this.maxY;
let x = point.x > this.getCenterX() ? this.minX : this.maxX;
let y = point.y > this.getCenterY() ? this.minY : this.maxY;
x -= point.x;
y -= point.y;
return x * x + y * y;
Expand Down Expand Up @@ -463,8 +463,8 @@ define( require => {
*/
equalsEpsilon: function( other, epsilon ) {
epsilon = epsilon !== undefined ? epsilon : 0;
var thisFinite = this.isFinite();
var otherFinite = other.isFinite();
const thisFinite = this.isFinite();
const otherFinite = other.isFinite();
if ( thisFinite && otherFinite ) {
// both are finite, so we can use Math.abs() - it would fail with non-finite values like Infinity
return Math.abs( this.minX - other.minX ) < epsilon &&
Expand Down Expand Up @@ -904,7 +904,7 @@ define( require => {
* amount of each.
*/
blend: function( bounds, ratio ) {
var t = 1 - ratio;
const t = 1 - ratio;
return new Bounds2(
t * this.minX + ratio * bounds.minX,
t * this.minY + ratio * bounds.minY,
Expand Down Expand Up @@ -1182,10 +1182,10 @@ define( require => {
return this;
}

var minX = this.minX;
var minY = this.minY;
var maxX = this.maxX;
var maxY = this.maxY;
const minX = this.minX;
const minY = this.minY;
const maxX = this.maxX;
const maxY = this.maxY;
this.set( dot.Bounds2.NOTHING );

// using mutable vector so we don't create excessive instances of Vector2 during this
Expand Down Expand Up @@ -1415,7 +1415,7 @@ define( require => {
*/
point: function( x, y ) {
if ( x instanceof dot.Vector2 ) {
var p = x;
const p = x;
return new Bounds2( p.x, p.y, p.x, p.y );
}
else {
Expand Down
8 changes: 4 additions & 4 deletions js/Bounds2Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define( require => {

QUnit.module( 'Bounds2' );

var epsilon = 0.00000001;
const epsilon = 0.00000001;

function approximateBoundsEquals( assert, a, b, msg ) {
assert.ok( Math.abs( a.minX - b.minX ) < epsilon, msg + ' minX: expected: ' + b.minX + ', result: ' + a.minX );
Expand All @@ -31,7 +31,7 @@ define( require => {
} );

QUnit.test( 'Basic', function( assert ) {
var bounds = new Bounds2( 1, 2, 3, 4 );
const bounds = new Bounds2( 1, 2, 3, 4 );
assert.ok( bounds.minX === 1, 'minX' );
assert.ok( bounds.minY === 2, 'minY' );
assert.ok( bounds.maxX === 3, 'maxX' );
Expand All @@ -45,7 +45,7 @@ define( require => {
} );

QUnit.test( 'Coordinates', function( assert ) {
var bounds = new Bounds2( 1, 2, 3, 4 );
const bounds = new Bounds2( 1, 2, 3, 4 );
assert.ok( !bounds.isEmpty(), 'isEmpty' );

assert.ok( !bounds.containsCoordinates( 0, 0 ), 'coordinates #1' );
Expand Down Expand Up @@ -88,7 +88,7 @@ define( require => {
approximateBoundsEquals( assert, C().roundedOut(), C().roundOut(), 'roundedOut / roundOut' );
approximateBoundsEquals( assert, C().roundedIn(), C().roundIn(), 'roundedIn / roundIn' );

var matrix = Matrix3.rotation2( Math.PI / 4 ).timesMatrix( Matrix3.translation( 11, -13 ) ).timesMatrix( Matrix3.scale( 2, 3.5 ) );
const matrix = Matrix3.rotation2( Math.PI / 4 ).timesMatrix( Matrix3.translation( 11, -13 ) ).timesMatrix( Matrix3.scale( 2, 3.5 ) );
approximateBoundsEquals( assert, A().transformed( matrix ), A().transform( matrix ), 'transformed / transform' );

approximateBoundsEquals( assert, A().dilated( 1.5 ), A().dilate( 1.5 ), 'dilated / dilate' );
Expand Down
18 changes: 9 additions & 9 deletions js/Bounds3.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ define( require => {
*/
equalsEpsilon: function( other, epsilon ) {
epsilon = epsilon !== undefined ? epsilon : 0;
var thisFinite = this.isFinite();
var otherFinite = other.isFinite();
const thisFinite = this.isFinite();
const otherFinite = other.isFinite();
if ( thisFinite && otherFinite ) {
// both are finite, so we can use Math.abs() - it would fail with non-finite values like Infinity
return Math.abs( this.minX - other.minX ) < epsilon &&
Expand Down Expand Up @@ -1141,16 +1141,16 @@ define( require => {
return this;
}

var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
var minZ = Number.POSITIVE_INFINITY;
var maxX = Number.NEGATIVE_INFINITY;
var maxY = Number.NEGATIVE_INFINITY;
var maxZ = Number.NEGATIVE_INFINITY;
let minX = Number.POSITIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
let minZ = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
let maxY = Number.NEGATIVE_INFINITY;
let maxZ = Number.NEGATIVE_INFINITY;

// using mutable vector so we don't create excessive instances of Vector2 during this
// make sure all 4 corners are inside this transformed bounding box
var vector = new dot.Vector3( 0, 0, 0 );
const vector = new dot.Vector3( 0, 0, 0 );

function withIt( vector ) {
minX = Math.min( minX, vector.x );
Expand Down
8 changes: 4 additions & 4 deletions js/Complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ define( require => {
* @returns {Complex}
*/
dividedBy: function( c ) {
var cMag = c.magnitudeSquared;
const cMag = c.magnitudeSquared;
return new Complex(
( this.real * c.real + this.imaginary * c.imaginary ) / cMag,
( this.imaginary * c.real - this.real * c.imaginary ) / cMag
Expand All @@ -182,7 +182,7 @@ define( require => {
* @returns {Complex}
*/
sqrtOf: function() {
var mag = this.magnitude;
const mag = this.magnitude;
return new Complex( Math.sqrt( ( mag + this.real ) / 2 ),
( this.imaginary >= 0 ? 1 : -1 ) * Math.sqrt( ( mag - this.real ) / 2 ) );
},
Expand Down Expand Up @@ -363,7 +363,7 @@ define( require => {
* @returns {Complex}
*/
divide: function( c ) {
var cMag = c.magnitudeSquared;
const cMag = c.magnitudeSquared;
return this.setRealImaginary(
( this.real * c.real + this.imaginary * c.imaginary ) / cMag,
( this.imaginary * c.real - this.real * c.imaginary ) / cMag
Expand Down Expand Up @@ -400,7 +400,7 @@ define( require => {
* @returns {Complex}
*/
sqrt: function() {
var mag = this.magnitude;
const mag = this.magnitude;
return this.setRealImaginary( Math.sqrt( ( mag + this.real ) / 2 ),
( this.imaginary >= 0 ? 1 : -1 ) * Math.sqrt( ( mag - this.real ) / 2 ) );
},
Expand Down
Loading

0 comments on commit 4c24376

Please sign in to comment.