Skip to content

Commit

Permalink
add reopenIssuesFromTODOs.js, phetsims/chipper#946
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 22, 2024
1 parent 464ce15 commit 6da5b60
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions eslint/rules/todo-should-have-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
* @copyright 2015 University of Colorado Boulder
*/

const process = require( 'process' );
const path = require( 'path' );
const fs = require( 'fs' );

const issueShorthandRegex = /#(\d+)/;
const urlRegex = /https:\/\/github.com\/phetsims\/[^\s]*/;
const filename = 'issuesFromTODOs.txt';
const todoIssuesFilepath = path.resolve( __dirname, `../../dist/${filename}` );

module.exports = function( context ) {
return {

Program: function() {
const filename = context.getFilename();

// Explicitly ignore files from the simula-rasa repo. simula-rasa is the template for new simulations that are
// created using 'grunt create-sim'. simula-rasa's code contains TODOs that should be addressed by the creator
Expand All @@ -30,8 +40,8 @@ module.exports = function( context ) {
if ( comment.value.indexOf( 'TODO' ) >= 0 ) {

// '#' followed by any number of digits
const missingIssueNumber = comment.value.search( /#\d+/ ) === -1;
const missingLink = comment.value.indexOf( 'https://github.com/phetsims/' ) === -1;
const missingIssueNumber = comment.value.search( issueShorthandRegex ) === -1;
const missingLink = comment.value.search( urlRegex ) === -1;

if ( missingLink && missingIssueNumber ) {
context.report( {
Expand All @@ -40,6 +50,24 @@ module.exports = function( context ) {
message: `TODO should have an issue: ${comment.value}`
} );
}
else if ( process.env.saveTODOIssues ) {
let url = null;
const urlMatch = comment.value.match( urlRegex );
if ( urlMatch ) {
url = urlMatch[ 0 ];
}

const issueShorthandRegex = /#(\d+)/;
const issueShorthandMatch = comment.value.match( issueShorthandRegex );
const repoNameMatch = filename.match( /[\\/]([\w-]+)[\\/]js[\\/]/ );
if ( issueShorthandMatch && repoNameMatch ) {
url = `https://github.com/phetsims/${repoNameMatch[ 1 ]}/issues/${issueShorthandMatch[ 1 ]}`;
}

if ( url ) {
fs.writeFileSync( todoIssuesFilepath, fs.readFileSync( todoIssuesFilepath ).toString() + `${url}\n` );
}
}
}
}
}
Expand Down

0 comments on commit 6da5b60

Please sign in to comment.