Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use semicolons to terminate fields in type StringType. #1208

Closed
pixelzoom opened this issue Mar 16, 2022 · 4 comments
Closed

Use semicolons to terminate fields in type StringType. #1208

pixelzoom opened this issue Mar 16, 2022 · 4 comments

Comments

@pixelzoom
Copy link
Contributor

{{REPO}}String.js (e.g in geometricOpticsStrings.ts) is generated by grunt modulify and contains the definiton of StringType. StringType currently uses commas to separate fields in type StringsType definition. PhET convention is to terminate fields with semicolons.

@samreid
Copy link
Member

samreid commented Mar 17, 2022

Here is the proposed solution for this issue. Can you please test/review it before I apply it to all repos?

Index: js/grunt/modulify.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/grunt/modulify.js b/js/grunt/modulify.js
--- a/js/grunt/modulify.js	(revision 2677c6192110ae9a2722fc7c73598408f3e075e3)
+++ b/js/grunt/modulify.js	(date 1647531219048)
@@ -321,8 +321,20 @@
     }
   }
 
-  const text = JSON.stringify( structure, null, 2 );
-  return replace( replace( text, '"', '\'' ), '\'{{STRING}}\'', 'string' );
+  let text = JSON.stringify( structure, null, 2 );
+
+  // Use single quotes instead of the double quotes from JSON
+  text = replace( text, '"', '\'' );
+
+  text = replace( text, '\'{{STRING}}\'', 'string' );
+
+  // Add ; to the last in the list
+  text = replace( text, ': string\n', ': string;\n' );
+
+  // Use ; instead of ,
+  text = replace( text, ',', ';' );
+
+  return text;
 };
 
 /**

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Mar 17, 2022

I tested with geometricOpticsStrings.ts and it looks correct. There's a minor concern that if anyone uses a comma in a string key (which they shouldn't be doing, afaik) then this implementation will break the key. I'm not sure where it would be handled in modulify.js, but could you add a check to verify that no key contains ';' ?

@pixelzoom pixelzoom removed their assignment Mar 17, 2022
samreid added a commit to phetsims/atomic-interactions that referenced this issue May 7, 2022
samreid added a commit to phetsims/area-model-multiplication that referenced this issue May 7, 2022
samreid added a commit to phetsims/balancing-chemical-equations that referenced this issue May 7, 2022
samreid added a commit to phetsims/area-model-algebra that referenced this issue May 7, 2022
samreid added a commit to phetsims/area-model-common that referenced this issue May 7, 2022
samreid added a commit to phetsims/build-a-molecule that referenced this issue May 7, 2022
samreid added a commit to phetsims/circuit-construction-kit-ac-virtual-lab that referenced this issue May 7, 2022
samreid added a commit to phetsims/circuit-construction-kit-common that referenced this issue May 7, 2022
samreid added a commit to phetsims/circuit-construction-kit-dc-virtual-lab that referenced this issue May 7, 2022
samreid added a commit to phetsims/balancing-act that referenced this issue May 7, 2022
samreid added a commit to phetsims/build-an-atom that referenced this issue May 7, 2022
samreid added a commit to phetsims/collision-lab that referenced this issue May 7, 2022
samreid added a commit to phetsims/area-model-introduction that referenced this issue May 7, 2022
samreid added a commit to phetsims/fractions-common that referenced this issue May 7, 2022
samreid added a commit to phetsims/fractions-equality that referenced this issue May 7, 2022
samreid added a commit to phetsims/trig-tour that referenced this issue May 7, 2022
samreid added a commit to phetsims/wave-on-a-string that referenced this issue May 7, 2022
samreid added a commit to phetsims/resistance-in-a-wire that referenced this issue May 7, 2022
samreid added a commit to phetsims/bumper that referenced this issue May 7, 2022
samreid added a commit to phetsims/plinko-probability that referenced this issue May 7, 2022
samreid added a commit to phetsims/under-pressure that referenced this issue May 7, 2022
samreid added a commit to phetsims/natural-selection that referenced this issue May 7, 2022
samreid added a commit to phetsims/ohms-law that referenced this issue May 7, 2022
samreid added a commit to phetsims/number-line-integers that referenced this issue May 7, 2022
samreid added a commit to phetsims/make-a-ten that referenced this issue May 7, 2022
samreid added a commit to phetsims/waves-intro that referenced this issue May 7, 2022
samreid added a commit to phetsims/projectile-motion that referenced this issue May 7, 2022
samreid added a commit to phetsims/pendulum-lab that referenced this issue May 7, 2022
samreid added a commit to phetsims/molecule-polarity that referenced this issue May 7, 2022
samreid added a commit to phetsims/tambo that referenced this issue May 7, 2022
samreid added a commit to phetsims/gravity-and-orbits that referenced this issue May 7, 2022
samreid added a commit to phetsims/ph-scale that referenced this issue May 7, 2022
samreid added a commit to phetsims/tappi that referenced this issue May 7, 2022
samreid added a commit to phetsims/rutherford-scattering that referenced this issue May 7, 2022
samreid added a commit to phetsims/blast that referenced this issue May 7, 2022
samreid added a commit to phetsims/john-travoltage that referenced this issue May 7, 2022
samreid added a commit to phetsims/xray-diffraction that referenced this issue May 7, 2022
samreid added a commit to phetsims/isotopes-and-atomic-mass that referenced this issue May 7, 2022
@samreid
Copy link
Member

samreid commented May 7, 2022

OK I pushed the changes, ran grunt modulify on everything and added assertions there are no semicolon, comma or space characters in string key tokens. I tested by adding these bad characters in some string keys and running grunt modulify--it errored as expected. @pixelzoom would you like to review? Please close if all is well.

@samreid samreid assigned pixelzoom and unassigned samreid May 7, 2022
@pixelzoom
Copy link
Contributor Author

👍🏻 closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants