-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Detecting redeclaration of p5.js reserved constants and functions #5351
Conversation
This is a draft PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! It is throwing some fetching errors when running locally and a "Range Error" on the editor. I have a couple of questions about style of the messages that we can talk about. It might be good to start adding tests to catch errors sooner than later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is coming out great. Some parts of the code can be improved but I think the most important is the analysis logic: there are some cases the code doesn't catch yet
|
||
const IS_LOCAL = document.location.origin.includes('file://'); | ||
|
||
if (typeof IS_MINIFIED !== 'undefined' || IS_LOCAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest making a variable with a descriptive name for this check (a.k.a. "what is this condition checking for?")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this for all variables across the file: for example instead of ele say element or whatever ele stands for. instead of arr say elementArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will update the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress! My main comment is please use descriptive variable names even if they are verbose. We do this to ensure human readability of the code particularly for novice contributors. We cannot have arrays called arr
or strings called str
. Also for variables like elements give a descriptive name.
const checkForConstsAndFuncs = arr => { | ||
let foundMatch = false; | ||
|
||
for (let i = 0; i < arr.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of arr
use a descriptive name for the array variablesArray
. We do this in p5.js to make the code more accessible to new contributors and to other contributors that might be trying to understand what you are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will make the changes soon
for (let i = 0; i < arr.length; i++) { | ||
//ignoreFunction contains the list of functions to be ignored | ||
if (!ignoreFunction.includes(arr[i])) { | ||
const keyArr = Object.keys(p5Constructors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyArray
instead of keyArr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some minor code suggestions, see what you think
//the setup and draw function. If a match is found then | ||
//to prevent further potential reporting we will exit immidiately | ||
let moveAhead = globalConstFuncCheck(); | ||
if (!moveAhead) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can use if (moveAhead) return
to avoid extra indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress! Good job documenting the sketch_reader.js. Let's wait for @ghalestrilo feedback and then we can see if we're ready to merge :)
@@ -211,6 +245,8 @@ line(0, 0, 100, 100, x3, Math.PI); | |||
* All the colors are checked for being color blind friendly. | |||
* More elaborate ascii is always welcome! | |||
* Extend Global Error catching. This means catching errors that the browser is throwing to the console and matching them with friendly messages. `fesErrorMonitor()` does this for a select few kinds of errors but help in supporting more is welcome :) | |||
* Improve `sketch_reader.js`'s code reading and variable/function name extracting functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be more detailed about what you mean with this. Why do we need this?
@@ -211,6 +245,8 @@ line(0, 0, 100, 100, x3, Math.PI); | |||
* All the colors are checked for being color blind friendly. | |||
* More elaborate ascii is always welcome! | |||
* Extend Global Error catching. This means catching errors that the browser is throwing to the console and matching them with friendly messages. `fesErrorMonitor()` does this for a select few kinds of errors but help in supporting more is welcome :) | |||
* Improve `sketch_reader.js`'s code reading and variable/function name extracting functionality. | |||
* `sketch_reader.js` can be extended and new features can be added to it to better aid the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new features such as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the changes. Please have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make some edits to limitations and thoughts for the future. Try to be as specific as you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I don't see anything that has to change now before merging.
With the updates to the documentation I think this branch is ready
Great job on the tests!
Resolves #5350
Changes:
sketch_reader.js
contains the code that will help the FES detect redeclaration of p5.js constants and functions.Screenshots of the change:
Detection of p5.js reserved function:
Detection of p5.js reserved constant
PR Checklist
npm run lint
passes