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 b9170ba commit b5b81b4
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 215 deletions.
6 changes: 3 additions & 3 deletions eslint/rules/copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function( context ) {

Program: function checkCopyright( node ) {
// Get the whole source code, not for node only.
var comments = context.getSourceCode().getAllComments();
const comments = context.getSourceCode().getAllComments();

if ( !comments || comments.length === 0 ) {
context.report( {
Expand All @@ -28,8 +28,8 @@ module.exports = function( context ) {
else {
// years must be between 2000 and 2099, inclusive. A script can be used to check that the dates
// match the GitHub creation and last-modified dates
var isDateRangeOK = /^ Copyright 20\d\d-20\d\d, University of Colorado Boulder$/.test( comments[ 0 ].value );
var isSingleDateOK = /^ Copyright 20\d\d, University of Colorado Boulder$/.test( comments[ 0 ].value );
const isDateRangeOK = /^ Copyright 20\d\d-20\d\d, University of Colorado Boulder$/.test( comments[ 0 ].value );
const isSingleDateOK = /^ Copyright 20\d\d, University of Colorado Boulder$/.test( comments[ 0 ].value );
if ( !isDateRangeOK && !isSingleDateOK ) {
context.report( {
node: node,
Expand Down
8 changes: 4 additions & 4 deletions eslint/rules/dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function( context ) {

// the following holds the possible ways to register various PhET listeners and observers
// TODO: derivedProperty
var OBSERVER_REGISTRATIONS = {
const OBSERVER_REGISTRATIONS = {
LINK: 'link',
LAZY_LINK: 'lazyLink',
ON: 'on',
Expand All @@ -33,13 +33,13 @@ module.exports = function( context ) {
node.expression.callee &&
node.expression.callee.property &&
node.expression.callee.property.name ) {
var calleeName = node.expression.callee.property.name;
for ( var key in OBSERVER_REGISTRATIONS ) {
const calleeName = node.expression.callee.property.name;
for ( const key in OBSERVER_REGISTRATIONS ) {
if( OBSERVER_REGISTRATIONS.hasOwnProperty( key ) ) {
if( calleeName === OBSERVER_REGISTRATIONS[ key ] ) {
// we have found an observer registration, start at the root and look through its tokens for dispose
var disposeFound = false;
var rootNode = context.getSourceCode().ast;
const rootNode = context.getSourceCode().ast;
if( rootNode &&
rootNode.tokens ) {
rootNode.tokens.forEach( function( token ) {
Expand Down
4 changes: 2 additions & 2 deletions eslint/rules/no-html-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module.exports = function( context ) {
'use strict';

// names of the native JavaScript constructors that clash with PhET type names
var nativeConstructors = [ 'Image', 'Range', 'Text', 'Node', 'Event' ];
const nativeConstructors = [ 'Image', 'Range', 'Text', 'Node', 'Event' ];

// list of all types that are declared in the file that have the same name as a native JavaScript constructor
var declaredTypes = [];
const declaredTypes = [];

/**
* Add a type to declared types if the 'declaration' node has a name which is equal to
Expand Down
4 changes: 2 additions & 2 deletions eslint/rules/phet-io-require-contains-ifphetio.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ module.exports = function( context ) {
node.declarations[ 0 ].init.arguments.length > 0 &&
node.declarations[ 0 ].init.callee.name === 'require' ) {

var rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;
const rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;

// If there is a PHET_IO import, but ifphetio! isn't the first part of the require
if ( rhs && rhs.indexOf( 'PHET_IO/' ) >= 0 && rhs.indexOf( 'ifphetio!' ) !== 0 ) {


// This regex will match 'phet-io' plus either a '/' or a '\' afterwards.
var regex = /phet-io[/\\]/;
const regex = /phet-io[/\\]/;

// Don't check this rule in the phet-io repo
// Match returns null if it doesn't find anything
Expand Down
10 changes: 5 additions & 5 deletions eslint/rules/property-visibility-annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = function( context ) {
AssignmentExpression: function propertyVisibilityAnnotation( node ) {

if ( node.left && node.left && node.left.object && node.left.object.type === 'ThisExpression' ) {
var leadingComments = node.parent.leadingComments;
var i;
var a;
const leadingComments = node.parent.leadingComments;
let i;
let a;
var isAnnotated = false;
if ( leadingComments ) {
for ( i = 0; i < leadingComments.length; i++ ) {
Expand All @@ -31,7 +31,7 @@ module.exports = function( context ) {
}
}

var trailingComments = node.parent.trailingComments;
const trailingComments = node.parent.trailingComments;
if ( trailingComments ) {
for ( i = 0; i < trailingComments.length; i++ ) {
a = trailingComments[ i ];
Expand All @@ -43,7 +43,7 @@ module.exports = function( context ) {
}

if ( node.parent && node.parent.parent && node.parent.parent.parent ) {
var parentFunction = node.parent.parent.parent;
const parentFunction = node.parent.parent.parent;
if ( parentFunction.id && parentFunction.id.name ) {
if ( parentFunction.type === 'FunctionDeclaration' && parentFunction.id.name[ 0 ].toUpperCase() === parentFunction.id.name[ 0 ] ) {
if ( !isAnnotated ) {
Expand Down
8 changes: 4 additions & 4 deletions eslint/rules/require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ module.exports = function( context ) {
node.declarations[ 0 ].init.arguments.length > 0 ) {
if ( node.declarations[ 0 ].init &&
node.declarations[ 0 ].init.callee.name === 'require' ) {
var lhs = node.declarations[ 0 ].id.name;
var rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;
const lhs = node.declarations[ 0 ].id.name;
const rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;

if ( rhs && rhs.indexOf( '!' ) < 0 ) {
var lastSlash = rhs.lastIndexOf( '/' );
var tail = rhs.substring( lastSlash + 1 );
const lastSlash = rhs.lastIndexOf( '/' );
const tail = rhs.substring( lastSlash + 1 );

if ( tail !== lhs ) {

Expand Down
16 changes: 8 additions & 8 deletions eslint/rules/string-require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = function( context ) {

// Adapted from Stack Overflow, see http://stackoverflow.com/questions/25085306/javascript-space-separated-string-to-camelcase
function toCamelCase( string ) {
var out = '';
let out = '';

// Add whitespace after each digit so that strings like myString1pattern will get camelcased with uppercase P
var withWhitespaceAfterDigits = string.replace( /\d/g, function( a ) {return a + ' ';} ).trim();
const withWhitespaceAfterDigits = string.replace( /\d/g, function( a ) {return a + ' ';} ).trim();

// Split on whitespace, remove whitespace and uppercase the first word in each term
withWhitespaceAfterDigits.split( ' ' ).forEach( function( element, index ) {
Expand Down Expand Up @@ -47,19 +47,19 @@ module.exports = function( context ) {
node.declarations[ 0 ].init.arguments.length > 0 ) {
if ( node.declarations[ 0 ].init &&
node.declarations[ 0 ].init.callee.name === 'require' ) {
var varName = node.declarations[ 0 ].id.name;
var rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;
const varName = node.declarations[ 0 ].id.name;
const rhs = node.declarations[ 0 ].init.arguments[ 0 ].value;

if ( rhs && rhs.indexOf( 'string!' ) === 0 ) {

var lastSlash = rhs.lastIndexOf( '/' );
var key = rhs.substring( lastSlash + 1 );
const lastSlash = rhs.lastIndexOf( '/' );
const key = rhs.substring( lastSlash + 1 );

// Convert various separators to whitespace
var withWhitespace = key.replace( /\./g, ' ' ).replace( /-/g, ' ' ).replace( /_/g, ' ' );
const withWhitespace = key.replace( /\./g, ' ' ).replace( /-/g, ' ' ).replace( /_/g, ' ' );

// Convert whitespace delimited string to camel case and append string suffix
var desiredVarName = toCamelCase( withWhitespace ) + 'String';
const desiredVarName = toCamelCase( withWhitespace ) + 'String';

if ( varName !== desiredVarName ) {
context.report( {
Expand Down
14 changes: 7 additions & 7 deletions eslint/rules/todo-should-have-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ module.exports = function( context ) {
'use strict';

// Whitelist of directories to check that TODOs have GitHub issues
var directoriesToRequireIssues = [ /joist[/\\]js/ ];
const directoriesToRequireIssues = [ /joist[/\\]js/ ];

return {

Program: function checkTodoShouldHaveIssue( node ) {

// Check whether the given directory matches the whitelist
var directoryShouldBeChecked = false;
let directoryShouldBeChecked = false;
for ( var i = 0; i < directoriesToRequireIssues.length; i++ ) {
var d = directoriesToRequireIssues[ i ];
const d = directoriesToRequireIssues[ i ];
if ( context.getFilename().match( d ) ) {
directoryShouldBeChecked = true;
break;
}
}

if ( directoryShouldBeChecked ) {
var comments = context.getSourceCode().getAllComments();
const comments = context.getSourceCode().getAllComments();

if ( comments ) {
for ( i = 0; i < comments.length; i++ ) {
var comment = comments[ i ];
const comment = comments[ i ];

if ( comment.value.indexOf( 'TODO' ) >= 0 ) {

// '#' followed by any number of digits
var missingIssueNumber = comment.value.search( /#\d+/ ) === -1;
var missingLink = comment.value.indexOf( 'https://github.com/phetsims/' ) === -1;
const missingIssueNumber = comment.value.search( /#\d+/ ) === -1;
const missingLink = comment.value.indexOf( 'https://github.com/phetsims/' ) === -1;

if ( missingLink && missingIssueNumber ) {
context.report( {
Expand Down
2 changes: 1 addition & 1 deletion js/common/ChipperConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(function() {

var ChipperConstants = {
const ChipperConstants = {

// Locale to use when no locale is specified
FALLBACK_LOCALE: 'en',
Expand Down
12 changes: 6 additions & 6 deletions js/common/ChipperStringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

(function() {

var ChipperStringUtils = {
const ChipperStringUtils = {

/**
* Pad LTR/RTL language values with unicode embedding marks (see https://github.com/phetsims/joist/issues/152)
Expand Down Expand Up @@ -66,7 +66,7 @@
* @returns {string} a new string
*/
replaceFirst: function( str, find, replaceWith ) {
var idx = str.indexOf( find );
const idx = str.indexOf( find );
if ( str.indexOf( find ) !== -1 ) {
return str.slice( 0, idx ) + replaceWith + str.slice( idx + find.length );
}
Expand All @@ -85,9 +85,9 @@
*/
replacePlaceholders: function( str, mapping ) {
Object.keys( mapping ).forEach( function( key ) {
var replacement = mapping[ key ];
const replacement = mapping[ key ];
key = '{{' + key + '}}';
var index;
let index;
while ( ( index = str.indexOf( key ) ) >= 0 ) {
str = str.slice( 0, index ) + replacement + str.slice( index + key.length );
}
Expand All @@ -107,8 +107,8 @@
* @returns {array} - the whole line containing the matched substring
*/
firstLineThatContains: function( string, find ) {
var findRE = '.*' + find.replace( /[-/\\^$*+?.()|[\]{}]/g, '\\$&' ) + '.*';
var theReturn = string.match( new RegExp( findRE, 'g' ) );
const findRE = '.*' + find.replace( /[-/\\^$*+?.()|[\]{}]/g, '\\$&' ) + '.*';
const theReturn = string.match( new RegExp( findRE, 'g' ) );
return theReturn ? theReturn[ 0 ] : null;
}
};
Expand Down
Loading

0 comments on commit b5b81b4

Please sign in to comment.