From 001b40257a79c283dcd6c83e24432b1817f2fd5b Mon Sep 17 00:00:00 2001 From: zepumph Date: Wed, 12 Dec 2018 14:22:55 -0900 Subject: [PATCH] change let -> const if not reassigned, https://github.com/phetsims/tasks/issues/973 --- js/HeaterCoolerBack.js | 10 +++---- js/HeaterCoolerFront.js | 20 ++++++------- js/accessibility/UtteranceTests.js | 22 +++++++------- .../describers/BorderAlertsDescriber.js | 18 +++++------ js/accessibility/describers/DirectionEnum.js | 2 +- .../describers/MovementDescriber.js | 30 +++++++++---------- js/accessibility/nodes/A11yGrabDragNode.js | 4 +-- 7 files changed, 53 insertions(+), 53 deletions(-) diff --git a/js/HeaterCoolerBack.js b/js/HeaterCoolerBack.js index f499f78aa..d186ecf53 100644 --- a/js/HeaterCoolerBack.js +++ b/js/HeaterCoolerBack.js @@ -50,24 +50,24 @@ define( require => { }, options ); // Dimensions for the rest of the stove, dependent on the desired stove width. - let burnerOpeningHeight = DEFAULT_WIDTH * OPENING_HEIGHT_SCALE; + const burnerOpeningHeight = DEFAULT_WIDTH * OPENING_HEIGHT_SCALE; // Create the inside bowl of the burner, which is an ellipse. - let burnerInteriorShape = new Shape() + const burnerInteriorShape = new Shape() .ellipse( DEFAULT_WIDTH / 2, burnerOpeningHeight / 4, DEFAULT_WIDTH / 2, burnerOpeningHeight / 2, 0, 0, Math.PI, false ); - let burnerInterior = new Path( burnerInteriorShape, { + const burnerInterior = new Path( burnerInteriorShape, { stroke: 'black', fill: new LinearGradient( 0, 0, DEFAULT_WIDTH, 0 ) .addColorStop( 0, options.baseColor.darkerColor( 0.5 ) ) .addColorStop( 1, options.baseColor.brighterColor( 0.5 ) ) } ); - let fireNode = new Image( fireImage, { + const fireNode = new Image( fireImage, { centerX: burnerInterior.centerX, top: burnerInterior.bottom, scale: DEFAULT_WIDTH / DEFAULT_WIDTH } ); - let iceNode = new Image( iceImage, { + const iceNode = new Image( iceImage, { centerX: burnerInterior.centerX, top: burnerInterior.bottom, scale: DEFAULT_WIDTH / DEFAULT_WIDTH diff --git a/js/HeaterCoolerFront.js b/js/HeaterCoolerFront.js index bc9ab415d..51911f567 100644 --- a/js/HeaterCoolerFront.js +++ b/js/HeaterCoolerFront.js @@ -69,18 +69,18 @@ define( require => { // Dimensions for the rest of the stove, dependent on the specified stove width. Empirically determined, and could // be made into options if needed. - let height = DEFAULT_WIDTH * 0.75; - let burnerOpeningHeight = DEFAULT_WIDTH * HeaterCoolerBack.OPENING_HEIGHT_SCALE; - let bottomWidth = DEFAULT_WIDTH * 0.80; + const height = DEFAULT_WIDTH * 0.75; + const burnerOpeningHeight = DEFAULT_WIDTH * HeaterCoolerBack.OPENING_HEIGHT_SCALE; + const bottomWidth = DEFAULT_WIDTH * 0.80; // Create the body of the stove. - let stoveBodyShape = new Shape() + const stoveBodyShape = new Shape() .ellipticalArc( DEFAULT_WIDTH / 2, burnerOpeningHeight / 4, DEFAULT_WIDTH / 2, burnerOpeningHeight / 2, 0, 0, Math.PI, false ) .lineTo( ( DEFAULT_WIDTH - bottomWidth ) / 2, height + burnerOpeningHeight / 2 ) .ellipticalArc( DEFAULT_WIDTH / 2, height + burnerOpeningHeight / 4, bottomWidth / 2, burnerOpeningHeight, 0, Math.PI, 0, true ).lineTo( DEFAULT_WIDTH, burnerOpeningHeight / 2 ); - let stoveBody = new Path( stoveBodyShape, { + const stoveBody = new Path( stoveBodyShape, { stroke: 'black', fill: new LinearGradient( 0, 0, DEFAULT_WIDTH, 0 ) .addColorStop( 0, options.baseColor.brighterColor( 0.5 ) ) @@ -88,13 +88,13 @@ define( require => { } ); // Create the label strings and scale them to support translations. - let titleOptions = { font: options.labelFont, maxWidth: options.labelMaxWidth }; - let heatTitle = new Text( options.heatLabel, titleOptions ); - let coolTitle = new Text( options.coolLabel, titleOptions ); - let titles = [ heatTitle, coolTitle ]; + const titleOptions = { font: options.labelFont, maxWidth: options.labelMaxWidth }; + const heatTitle = new Text( options.heatLabel, titleOptions ); + const coolTitle = new Text( options.coolLabel, titleOptions ); + const titles = [ heatTitle, coolTitle ]; // Scale the titles to fit within the bucket front if necessary. - let maxTitleWidth = Math.max( coolTitle.width, heatTitle.width ); + const maxTitleWidth = Math.max( coolTitle.width, heatTitle.width ); if ( maxTitleWidth > bottomWidth / 2 ) { titles.forEach( function( title ) { title.scale( ( bottomWidth / 2 ) / maxTitleWidth ); diff --git a/js/accessibility/UtteranceTests.js b/js/accessibility/UtteranceTests.js index 1cdcd4954..04a68baa6 100644 --- a/js/accessibility/UtteranceTests.js +++ b/js/accessibility/UtteranceTests.js @@ -14,7 +14,7 @@ define( require => { const Utterance = require( 'SCENERY_PHET/accessibility/Utterance' ); const utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' ); - var sleepTiming = null; + let sleepTiming = null; // helper es6 functions from https://stackoverflow.com/questions/33289726/combination-of-async-function-await-settimeout/33292942 function timeout( ms ) { @@ -30,7 +30,7 @@ define( require => { var alerts = []; - var intervalID = null; + let intervalID = null; QUnit.module( 'Utterance', { before() { @@ -67,12 +67,12 @@ define( require => { assert.ok( true, 'first test' ); - let alert = 'hi'; - utteranceQueue.addToBack( alert ); + const myAlert = 'hi'; + utteranceQueue.addToBack( myAlert ); await sleep( () => { - assert.ok( alerts[ 0 ] === alert, 'basic utteranceQueue test' ); + assert.ok( alerts[ 0 ] === myAlert, 'basic utteranceQueue test' ); } ); utteranceQueue.addToBack( 'alert' ); @@ -134,18 +134,18 @@ define( require => { QUnit.test( 'Utterance options', async assert => { - var alert = new Utterance( { + const alert = new Utterance( { alert: [ '1', '2', '3' ] } ); - let alert4 = () => { + const alert4 = () => { utteranceQueue.addToBack( alert ); utteranceQueue.addToBack( alert ); utteranceQueue.addToBack( alert ); utteranceQueue.addToBack( alert ); }; - let testOrder = ( messageSuffix ) => { + const testOrder = ( messageSuffix ) => { // newest at lowest index because of unshift assert.ok( alerts[ 3 ] === '1', 'Array order1' + messageSuffix ); @@ -165,12 +165,12 @@ define( require => { QUnit.test( 'Utterance loopAlerts', async assert => { - var alert = new Utterance( { + const alert = new Utterance( { alert: [ '1', '2', '3' ], loopAlerts: true } ); - let alert7 = () => { + const alert7 = () => { utteranceQueue.addToBack( alert ); utteranceQueue.addToBack( alert ); utteranceQueue.addToBack( alert ); @@ -180,7 +180,7 @@ define( require => { utteranceQueue.addToBack( alert ); }; - let testOrder = ( messageSuffix ) => { + const testOrder = ( messageSuffix ) => { // newest at lowest index assert.ok( alerts[ 6 ] === '1', 'Array order1' + messageSuffix ); diff --git a/js/accessibility/describers/BorderAlertsDescriber.js b/js/accessibility/describers/BorderAlertsDescriber.js index ede8887c9..9dabf57e7 100644 --- a/js/accessibility/describers/BorderAlertsDescriber.js +++ b/js/accessibility/describers/BorderAlertsDescriber.js @@ -19,12 +19,12 @@ define( ( require ) => { const utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' ); // a11y strings - let leftBorderAlertString = SceneryPhetA11yStrings.leftBorderAlert.value; - let rightBorderAlertString = SceneryPhetA11yStrings.rightBorderAlert.value; - let topBorderAlertString = SceneryPhetA11yStrings.topBorderAlert.value; - let bottomBorderAlertString = SceneryPhetA11yStrings.bottomBorderAlert.value; + const leftBorderAlertString = SceneryPhetA11yStrings.leftBorderAlert.value; + const rightBorderAlertString = SceneryPhetA11yStrings.rightBorderAlert.value; + const topBorderAlertString = SceneryPhetA11yStrings.topBorderAlert.value; + const bottomBorderAlertString = SceneryPhetA11yStrings.bottomBorderAlert.value; - let DEFAULT_TOP_BORDER_ALERT = topBorderAlertString; + const DEFAULT_TOP_BORDER_ALERT = topBorderAlertString; /** * Responsible for alerting when the temperature increases @@ -68,7 +68,7 @@ define( ( require ) => { alertAtBorder( position, keyCode ) { let alertDirection; - let bordersTouching = []; + const bordersTouching = []; // at left now, but wasn't last location if ( position.x === this.bounds.left ) { @@ -93,7 +93,7 @@ define( ( require ) => { // corner case if ( bordersTouching.length > 1 ) { keyCode = keyCode || -1; - let possibleDirection = DirectionEnum.keyCodeToDirection( keyCode ); + const possibleDirection = DirectionEnum.keyCodeToDirection( keyCode ); // if the keyCode matches a border direction, use that instead of another wall that we may also be touching if ( possibleDirection && bordersTouching.indexOf( possibleDirection ) >= 0 ) { @@ -108,7 +108,7 @@ define( ( require ) => { // Then we are potentially going to alert if ( alertDirection ) { assert && assert( DirectionEnum.isRelativeDirection( alertDirection ), `unsupported direction: ${alertDirection}` ); - let borderAlert = this[ alertDirection ]; + const borderAlert = this[ alertDirection ]; assert && assert( borderAlert instanceof BorderAlert, 'sanity check' ); borderAlert.alert(); @@ -171,7 +171,7 @@ define( ( require ) => { getAlert() { let alert = this._alert; if ( Array.isArray( alert ) ) { - let index = Util.clamp( this._numberOfTimesAlerted, 0, alert.length - 1 ); + const index = Util.clamp( this._numberOfTimesAlerted, 0, alert.length - 1 ); alert = alert[ index ]; } return alert; diff --git a/js/accessibility/describers/DirectionEnum.js b/js/accessibility/describers/DirectionEnum.js index a32876a1e..39a61db6d 100644 --- a/js/accessibility/describers/DirectionEnum.js +++ b/js/accessibility/describers/DirectionEnum.js @@ -15,7 +15,7 @@ define( function( require ) { const sceneryPhet = require( 'SCENERY_PHET/sceneryPhet' ); // It is important that the key and value are the same, so that either way you can access the values of the enum. - let DirectionEnum = { + const DirectionEnum = { LEFT: 'LEFT', RIGHT: 'RIGHT', UP: 'UP', diff --git a/js/accessibility/describers/MovementDescriber.js b/js/accessibility/describers/MovementDescriber.js index a79161b0c..88de28a03 100644 --- a/js/accessibility/describers/MovementDescriber.js +++ b/js/accessibility/describers/MovementDescriber.js @@ -22,20 +22,20 @@ define( require => { const utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' ); // a11y strings - let downString = SceneryPhetA11yStrings.down.value; - let leftString = SceneryPhetA11yStrings.left.value; - let rightString = SceneryPhetA11yStrings.right.value; - let upString = SceneryPhetA11yStrings.up.value; + const downString = SceneryPhetA11yStrings.down.value; + const leftString = SceneryPhetA11yStrings.left.value; + const rightString = SceneryPhetA11yStrings.right.value; + const upString = SceneryPhetA11yStrings.up.value; // constants // in radians - threshold for diagonal movement is +/- 15 degrees from diagonals - let DIAGONAL_MOVEMENT_THRESHOLD = 15 * Math.PI / 180; + const DIAGONAL_MOVEMENT_THRESHOLD = 15 * Math.PI / 180; // mapping from alerting direction to the radian range that fills that space in the unit circle. // The diagnal directions take up the middle third of each quadrant, such that each "outside" third is in the range for // a relative (primary) direction. Therefore each diagonal direction is 1/9 of the Unit circle, and each primary direction // is 2/9 of the unit circle. - let DIRECTION_MAP = { + const DIRECTION_MAP = { UP: new Range( -3 * Math.PI / 4 + DIAGONAL_MOVEMENT_THRESHOLD, -Math.PI / 4 - DIAGONAL_MOVEMENT_THRESHOLD ), DOWN: new Range( Math.PI / 4 + DIAGONAL_MOVEMENT_THRESHOLD, 3 * Math.PI / 4 - DIAGONAL_MOVEMENT_THRESHOLD ), RIGHT: new Range( -Math.PI / 4 + DIAGONAL_MOVEMENT_THRESHOLD, Math.PI / 4 - DIAGONAL_MOVEMENT_THRESHOLD ), @@ -48,7 +48,7 @@ define( require => { UP_RIGHT: new Range( -Math.PI / 4 - DIAGONAL_MOVEMENT_THRESHOLD, -Math.PI / 4 + DIAGONAL_MOVEMENT_THRESHOLD ), DOWN_RIGHT: new Range( Math.PI / 4 - DIAGONAL_MOVEMENT_THRESHOLD, Math.PI / 4 + DIAGONAL_MOVEMENT_THRESHOLD ) }; - let DIRECTION_MAP_KEYS = Object.keys( DIRECTION_MAP ); + const DIRECTION_MAP_KEYS = Object.keys( DIRECTION_MAP ); if ( assert ) { DIRECTION_MAP_KEYS.forEach( direction => { @@ -56,7 +56,7 @@ define( require => { } ); } - let DEFAULT_MOVEMENT_ALERTS = { + const DEFAULT_MOVEMENT_ALERTS = { LEFT: leftString, RIGHT: rightString, UP: upString, @@ -92,7 +92,7 @@ define( require => { if ( assert ) { for ( let i = 0; i < this.movementAlertKeys.length; i++ ) { - let key = this.movementAlertKeys[ i ]; + const key = this.movementAlertKeys[ i ]; assert( DirectionEnum.keys.indexOf( key ) >= 0, `unexpected key: ${key}. Keys should be the same as those in DirectionEnum` ); assert( AlertableDef.isAlertableDef( options.movementAlerts[ key ] ) ); } @@ -158,10 +158,10 @@ define( require => { */ alertDirectionalMovement() { - let newLocation = this.locationProperty.get(); + const newLocation = this.locationProperty.get(); if ( !newLocation.equals( this.lastAlertedLocation ) ) { - let directions = this.getDirections( newLocation, this.lastAlertedLocation ); + const directions = this.getDirections( newLocation, this.lastAlertedLocation ); // make sure that these alerts exist if ( assert ) { @@ -185,9 +185,9 @@ define( require => { getDirections( pointA, pointB ) { let direction; - let dx = pointA.x - pointB.x; - let dy = pointA.y - pointB.y; - let angle = Math.atan2( dy, dx ); + const dx = pointA.x - pointB.x; + const dy = pointA.y - pointB.y; + const angle = Math.atan2( dy, dx ); // atan2 wraps around Math.PI, so special check for moving left from absolute value if ( DIRECTION_MAP.LEFT.contains( Math.abs( angle ) ) ) { @@ -196,7 +196,7 @@ define( require => { // otherwise, angle will be in one of the ranges in DIRECTION_MAP for ( let i = 0; i < DIRECTION_MAP_KEYS.length; i++ ) { - let entry = DIRECTION_MAP[ DIRECTION_MAP_KEYS[ i ] ]; + const entry = DIRECTION_MAP[ DIRECTION_MAP_KEYS[ i ] ]; if ( entry.contains( angle ) ) { direction = DirectionEnum[ DIRECTION_MAP_KEYS[ i ] ]; break; diff --git a/js/accessibility/nodes/A11yGrabDragNode.js b/js/accessibility/nodes/A11yGrabDragNode.js index e92df3cd4..72fcaa889 100644 --- a/js/accessibility/nodes/A11yGrabDragNode.js +++ b/js/accessibility/nodes/A11yGrabDragNode.js @@ -153,7 +153,7 @@ define( require => { this.dragFocusHighlight.makeDashed(); // if ever we update the node's focusHighlight, then update the grab button's too to keep in syn. - let onHighlightChange = () => { + const onHighlightChange = () => { this.dragFocusHighlight.setShape( this.grabFocusHighlight.shape ); }; this.grabFocusHighlight.highlightChangedEmitter.addListener( onHighlightChange ); @@ -212,7 +212,7 @@ define( require => { this.listenersForGrab = options.listenersForGrab.concat( grabButtonListener ); node.addInputListener( grabButtonListener ); - let dragDivListener = { + const dragDivListener = { // Release the draggable on 'enter' key, tracking that we have released the draggable with this key so that // we don't immediately catch the 'click' event while the enter key is down on the button