-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add no-multi-assign-on-declaration lint rule, phetsims/chipper#794
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
} ); | ||
} | ||
} | ||
}; | ||
} | ||
}; |