Skip to content

Commit

Permalink
add setTimeout/Interval lint rules, and escape a few usages, phetsims…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 8, 2019
1 parent 89b0a66 commit 29b844f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions eslint/rules/bad-sim-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ module.exports = function( context ) {
'ptions = _.extend(',
'onfig = _.extend('

// In sims, don't allow setTimout and setInterval calls coming from window, see https://github.com/phetsims/phet-info/issues/59
// TODO: comment back in when all lint errors are taken care of, https://github.com/phetsims/phet-info/issues/59
// {
// id: 'setTimeout(',
// regex: /(window\.| )setTimeout\(/
// },
// {
// id: 'setInterval(',
// regex: /(window\.| )setInterval\(/
// }

// DOT/Util.toFixed or DOT/Util.toFixedNumber should be used instead of toFixed.
// JavaScript's toFixed is notoriously buggy. Behavior differs depending on browser,
// because the spec doesn't specify whether to round or floor.
// TODO: comment back in when all issues are done, https://github.com/phetsims/chipper/issues/737
// TODO: comment back in when all lint errors are taken care of, https://github.com/phetsims/chipper/issues/737
// {
// id: '.toFixed(', // support regex with english names this way
// regex: new RegExp( '(?<!Util)\\.toFixed\\(' )
// regex: /(?<!Util)\.toFixed\(/
// }
];

Expand Down
2 changes: 1 addition & 1 deletion js/initialize-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
* testing a sim for robustness, and allowing others to reproduce slow-behavior bugs.
*/
window.phet.chipper.makeEverythingSlow = function() {
window.setInterval( function() { sleep( 64 ); }, 16 );
window.setInterval( function() { sleep( 64 ); }, 16 ); // eslint-disable-line bad-sim-text
};
window.phet.chipper.makeRandomSlowness = function() {
window.setInterval( function() { sleep( Math.ceil( 100 + Math.random() * 200 ) ); }, Math.ceil( 100 + Math.random() * 200 ) ); // eslint-disable-line bad-sim-text
Expand Down

0 comments on commit 29b844f

Please sign in to comment.