Skip to content

Commit

Permalink
add no-multi-assign-on-declaration lint rule, phetsims/chipper#794
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 22, 2024
1 parent c359bd7 commit 3a5b28f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eslint/.eslintrc.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.'
} );
}
}
};
}
};

0 comments on commit 3a5b28f

Please sign in to comment.