Skip to content

Commit

Permalink
add no-multi-assign-on-declaration lint rule, #794
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 7, 2019
1 parent c5322f5 commit 2c9ece8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions eslint/.eslintrc.js
Expand Up @@ -136,6 +136,9 @@ module.exports = {
'property-visibility-annotation': 0,
'no-property-in-require-statement': 2,

// disallow assignment within variable declaration, see https://github.com/phetsims/chipper/issues/794
'no-multi-assign-on-declaration': 2,

// permit only one var declaration per line, see #390
'one-var': [
2,
Expand Down
33 changes: 33 additions & 0 deletions eslint/rules/no-multi-assign-on-declaration.js
@@ -0,0 +1,33 @@
// Copyright 2019, University of Colorado Boulder

/**
* @fileoverview Don't allow assignment within a variable declaration
* @author Stewart Rand (original author of eslint file)
* @author Michael Kauzmann (PhET Interactive Simulations)
*
* This rule was adapted straight from eslint's no-multi-assign, and adapted/simplified for PhET purposes, see
* original file: https://github.com/eslint/eslint/blob/7ad86de/lib/rules/no-multi-assign.js
*/

/* eslint-env node */

'use strict';

module.exports = {
create( context ) {
return {

// run on any AssignmentExpression node
AssignmentExpression( node ) {

// if within a variable declaration, error out
if ( node.parent.type === 'VariableDeclarator' ) {
context.report( {
node: node,
message: 'Unexpected chained assignment when declaring variable.'
} );
}
}
};
}
};
3 changes: 2 additions & 1 deletion js/grunt/getStringMap.js
Expand Up @@ -78,7 +78,8 @@ module.exports = function( locales, phetLibs ) {
grunt.log.debug( `missing string file: ${stringsFilename}` );
fileContents = {};
}
const fileMap = repoStringMap[ repository.name ][ locale ] = {};
const fileMap = {};
repoStringMap[ repository.name ][ locale ] = fileMap;

for ( const stringKeyMissingPrefix in fileContents ) {
const stringData = fileContents[ stringKeyMissingPrefix ];
Expand Down

0 comments on commit 2c9ece8

Please sign in to comment.