Skip to content

Commit

Permalink
add .js suffix in node code, #407
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 8, 2024
1 parent bb3acfc commit a9d6b13
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 76 deletions.
10 changes: 0 additions & 10 deletions js/eslint/phet-rules/bad-sim-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ module.exports = {
id: '.toFixed(', // support regex with english names this way
regex: new RegExp( '(?<!Utils)\\.toFixed\\(' ) // NOTE: eslint parsing breaks when using regex syntax like `/regex/`
},

{
id: 'Import from statements require a *.js suffix',
predicate: line => {
if ( line.trim().indexOf( 'import ' ) === 0 && line.includes( ' from ' ) && ( !line.includes( '.js' ) && !line.includes( '.mjs' ) ) ) {
return false;
}
return true;
}
},
{
id: 'Import statements require a *.js suffix',
predicate: line => {
Expand Down
17 changes: 16 additions & 1 deletion js/eslint/phet-rules/bad-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


const getBadTextTester = require( './getBadTextTester.js' );
const _ = require( 'lodash' );

module.exports = {
create: function( context ) {
Expand Down Expand Up @@ -148,7 +149,21 @@ module.exports = {
},

// Prefer _.assignIn() which returns the object in its type doc, https://github.com/phetsims/tasks/issues/1130
' = _.extend('
' = _.extend(',

// It would probably be better to use a third-party plugin, but alas, we use this. See https://github.com/phetsims/perennial/issues/407
{
id: 'Import from statements require a *.js suffix',
predicate: line => {
if ( line.trim().startsWith( 'import ' ) && !/.\.\w+'/.test( line.trim() ) &&
_.every( [ ' from ', '/' ], string => line.includes( string ) ) && // includes
_.every( [ '.js', '.mjs', '@', '{', 'node_modules' ], string => !line.includes( string ) ) // doesn't includes
) {
return false;
}
return true;
}
}
];

return {
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/decaf/buildDecaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

import getPreloads from './getPreloads';
import getPreloads from './getPreloads.js';
import fs from 'fs';

const assert = require( 'assert' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import check from '../check.js';
import getOption from './util/getOption.ts';
import getRepo from './util/getRepo';
import getRepo from './util/getRepo.js';

export const checkTask = ( async () => check( {
repo: getRepo(),
Expand Down
4 changes: 2 additions & 2 deletions js/grunt/tasks/checkout-main-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/


import checkoutMainAll from '../checkoutMainAll';
import getOption from './util/getOption';
import checkoutMainAll from '../checkoutMainAll.js';
import getOption from './util/getOption.js';

( async () => checkoutMainAll( getOption( 'branch' ) ) )();
2 changes: 1 addition & 1 deletion js/grunt/tasks/checkout-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import checkoutMain from '../../common/checkoutMain';
import checkoutMain from '../../common/checkoutMain.js';
import getOption from './util/getOption.ts';

( async () => {
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/checkout-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import checkoutRelease from '../../common/checkoutRelease';
import checkoutRelease from '../../common/checkoutRelease.js';
import getOption from './util/getOption.ts';

( async () => {
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/checkout-shas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
import assert from 'assert';
import grunt from 'grunt';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import checkoutDependencies from '../../common/checkoutDependencies';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import checkoutDependencies from '../../common/checkoutDependencies.js';
import getOption from './util/getOption.js';

( async () => {
assert( getOption( 'repo' ), 'Requires specifying a repository with --repo={{REPOSITORY}}' );
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/checkout-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import checkoutTarget from '../../common/checkoutTarget';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import checkoutTarget from '../../common/checkoutTarget.js';
import getOption from './util/getOption.js';

( async () => {
const repo = getOption( 'repo' );
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/checkout-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import checkoutTimestamp from '../../common/checkoutTimestamp';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import checkoutTimestamp from '../../common/checkoutTimestamp.js';
import getOption from './util/getOption.js';

( async () => {
const repo = getOption( 'repo' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/cherry-pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import cherryPick from '../cherryPick';
import cherryPick from '../cherryPick.js';
import getOption from './util/getOption.ts';

( async () => {
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/clone-missing-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
* TODO: ASK DEVS: Delete this grunt task, SR MK think it doesn't belong in formal API (it should just be part of a full thing), https://github.com/phetsims/chipper/issues/1461
*/

import cloneMissingRepos from '../../common/cloneMissingRepos';
import cloneMissingRepos from '../../common/cloneMissingRepos.js';

( async () => cloneMissingRepos() )();
6 changes: 3 additions & 3 deletions js/grunt/tasks/create-one-off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import createOneOff from '../createOneOff';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import createOneOff from '../createOneOff.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/create-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*/

import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import createRelease from '../createRelease';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import createRelease from '../createRelease.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/create-sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import createSim from '../createSim';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import createSim from '../createSim.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
4 changes: 2 additions & 2 deletions js/grunt/tasks/deploy-decaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import deployDecaf from '../decaf/deployDecaf';
import getOption from './util/getOption';
import deployDecaf from '../decaf/deployDecaf.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
4 changes: 2 additions & 2 deletions js/grunt/tasks/deploy-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import deployImages from '../deployImages';
import getOption from './util/getOption';
import deployImages from '../deployImages.js';
import getOption from './util/getOption.js';

( async () => {
console.log( getOption( 'simulation' ) );
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import dev from '../dev';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import dev from '../dev.js';
import getOption from './util/getOption.js';

( async () => {
const repo = getOption( 'repo' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import generateData from '../generateData';
import generateData from '../generateData.js';

( async () => generateData() )();
2 changes: 1 addition & 1 deletion js/grunt/tasks/maintenance-check-branch-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import winston from 'winston';
import Maintenance from '../../common/Maintenance';
import Maintenance from '../../common/Maintenance.js';

winston.default.transports.console.level = 'error';

Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/maintenance-create-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import assert from 'assert';
import winston from 'winston';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import Maintenance from '../../common/Maintenance.js';
import getOption from './util/getOption';
import getOption from './util/getOption.js';

winston.default.transports.console.level = 'error';

Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/maintenance-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Lists out the current maintenance process state
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import Maintenance from '../../common/Maintenance';
import Maintenance from '../../common/Maintenance.js';

// TODO: Does this belong in grunt? See https://github.com/phetsims/chipper/issues/1461
( async () => Maintenance.list() )();
2 changes: 1 addition & 1 deletion js/grunt/tasks/maintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/
// TODO: Do these maintenance entry points belong in grunt? See https://github.com/phetsims/chipper/issues/1461

import Maintenance from '../../common/Maintenance';
import Maintenance from '../../common/Maintenance.js';

( async () => Maintenance.startREPL() )();
6 changes: 3 additions & 3 deletions js/grunt/tasks/npm-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import npmUpdate from '../../common/npmUpdate';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import npmUpdate from '../../common/npmUpdate.js';
import getOption from './util/getOption.js';

( async () => {
const repo = getOption( 'repo' );
Expand Down
8 changes: 4 additions & 4 deletions js/grunt/tasks/one-off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/

import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import getBranch from '../../common/getBranch';
import dev from '../dev';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import getBranch from '../../common/getBranch.js';
import dev from '../dev.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/print-phet-io-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import getPhetioLinks from '../../common/getPhetioLinks';
import getPhetioLinks from '../../common/getPhetioLinks.js';

( async () => {
const phetioLinks = await getPhetioLinks();
Expand Down
8 changes: 4 additions & 4 deletions js/grunt/tasks/production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import markSimAsPublished from '../../common/markSimAsPublished';
import production from '../production';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import markSimAsPublished from '../../common/markSimAsPublished.js';
import production from '../production.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import production from '../production';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import production from '../production.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/rc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/

import assert from 'assert';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import rc from '../rc';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import rc from '../rc.js';
import getOption from './util/getOption.js';

( async () => {
const repo = getOption( 'repo' );
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/release-branch-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import assert from 'assert';
import _ from 'lodash';
import winston from 'winston';
import assertIsValidRepoName from '../../common/assertIsValidRepoName';
import Maintenance from '../../common/Maintenance';
import getOption from './util/getOption';
import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import Maintenance from '../../common/Maintenance.js';
import getOption from './util/getOption.js';

( async () => {

Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/sha-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import assertIsValidRepoName from '../../common/assertIsValidRepoName.js';
import shaCheck from '../shaCheck';
import shaCheck from '../shaCheck.js';
import getOption from './util/getOption.ts';

( async () => {
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/test-grunt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

import testGruntOptions from './util/testGruntOptions';
import testGruntOptions from './util/testGruntOptions.js';

testGruntOptions();
2 changes: 1 addition & 1 deletion js/grunt/tasks/util/getRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import grunt from 'grunt';
import path from 'path';
import process from 'process';
import { Repo } from '../../../common/PerennialTypes.js';
import getOption from './getOption';
import getOption from './getOption.js';

/**
* Get the repo by processing from multiple locations (command line options and package).
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/util/testGruntOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

import getOption from './getOption';
import getOption from './getOption.js';

/**
* Test that grunt parses options as expected.
Expand Down
Loading

0 comments on commit a9d6b13

Please sign in to comment.