-
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 support for sim specific bad text, phetsims/chipper#728
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2019, University of Colorado Boulder | ||
/* eslint-disable */ | ||
|
||
/** | ||
* NOTE: this file is a duplicate of bad-text.js, but it is only run on sim specific code, if you are looking for | ||
* adding general bad text, see `./bad-text.js` | ||
* | ||
* Lint detector for invalid text. Checks the entire file and does not correctly report line number. | ||
* Lint is disabled for this file so the bad texts aren't themselves flagged. | ||
* | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
* @author Michael Kauzmann (PhET Interactive Simulations) | ||
*/ | ||
module.exports = function( context ) { | ||
'use strict'; | ||
|
||
var badTextsForSimCode = [ | ||
|
||
'Math.round', | ||
'Math.random', | ||
'_.shuffle', | ||
'_.sample', | ||
'_.random', | ||
'new Random()', | ||
|
||
// IE doesn't support: | ||
'Number.parseInt()', | ||
'Array.prototype.find' | ||
|
||
]; | ||
|
||
// NOTE: this code is duplicated in `bad-text.js`, don't edit this without updating there too | ||
return { | ||
Program: function( node ) { | ||
var sourceCode = context.getSourceCode(); | ||
var text = sourceCode.text; | ||
badTextsForSimCode.forEach( function( badText ) { | ||
if ( text.indexOf( badText ) >= 0 ) { | ||
context.report( { | ||
node: node, | ||
message: 'File contains bad text: \'' + badText + '\'' | ||
} ); | ||
} | ||
} ) | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = [ | ||
// JSON Schema for rule options goes here | ||
]; |
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
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,15 @@ | ||
// Copyright 2018, University of Colorado Boulder | ||
// @author Michael Kauzmann | ||
|
||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
/** | ||
* Eslint config applied only to sims that are completely written in es6, with no es5 code. | ||
*/ | ||
module.exports = { | ||
extends: './.eslintrc.js', | ||
rules: { | ||
'bad-sim-text': 2 | ||
} | ||
}; |