-
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 lint rule for toFixed, consolidate bad-text implementations, phet…
- Loading branch information
Showing
3 changed files
with
41 additions
and
33 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
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,29 @@ | ||
// Copyright 2019, University of Colorado Boulder | ||
/* eslint-disable */ | ||
|
||
/** | ||
* Bad text testing function for testing bad text in the project. Supports bad text as string or regex | ||
* @param {Array.<string|Object>} badTexts - if object, should look like {name: {string}, regex: {Regexp}} | ||
* @param {Object} context - eslinting context given from the engine | ||
*/ | ||
module.exports = ( badTexts, context ) => { | ||
'use strict'; | ||
|
||
return node => { | ||
const sourceCode = context.getSourceCode(); | ||
const text = sourceCode.text; | ||
badTexts.forEach( badText => { | ||
let failedText = null; | ||
if ( badText.regex instanceof RegExp && badText.regex.test( text ) ) { | ||
failedText = badText.name; | ||
} | ||
if ( text.indexOf( badText ) >= 0 ) { | ||
failedText = badText; | ||
} | ||
failedText && context.report( { | ||
node: node, | ||
message: 'File contains bad text: \'' + failedText + '\'' | ||
} ); | ||
} ); | ||
}; | ||
}; |