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

Detecting redeclaration of p5.js reserved constants and functions #5351

Merged
merged 17 commits into from
Aug 12, 2021

Conversation

Aloneduckling
Copy link
Contributor

@Aloneduckling Aloneduckling commented Jul 14, 2021

Resolves #5350

Changes:

  • The new file sketch_reader.js contains the code that will help the FES detect redeclaration of p5.js constants and functions.
  • Inline documentation is included
  • Unit tests are included

Screenshots of the change:

Detection of p5.js reserved function:
image

Detection of p5.js reserved constant
image

PR Checklist

@Aloneduckling
Copy link
Contributor Author

This is a draft PR

Copy link
Member

@lm-n lm-n left a 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.

src/app.js Show resolved Hide resolved
translations/en/translation.json Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
@lm-n lm-n requested a review from ghalestrilo July 25, 2021 19:11
Copy link
Contributor

@ghalestrilo ghalestrilo left a 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) {
Copy link
Contributor

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?")

Copy link
Member

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

Copy link
Contributor Author

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

src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
Copy link
Member

@lm-n lm-n left a 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++) {
Copy link
Member

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.

Copy link
Contributor Author

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

src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyArray instead of keyArr

src/core/friendly_errors/sketch_reader.js Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ghalestrilo ghalestrilo left a 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

src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
//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) {
Copy link
Contributor

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

Copy link
Contributor Author

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

src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
src/core/friendly_errors/sketch_reader.js Outdated Show resolved Hide resolved
Copy link
Member

@lm-n lm-n left a 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 :)

@Aloneduckling Aloneduckling changed the title Detecting reassignment of p5.js reserved constants and functions Detecting redeclaration of p5.js reserved constants and functions Aug 9, 2021
@@ -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.
Copy link
Member

@lm-n lm-n Aug 9, 2021

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new features such as

Copy link
Contributor Author

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

Copy link
Member

@lm-n lm-n left a 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.

Copy link
Contributor

@ghalestrilo ghalestrilo left a 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!

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

Successfully merging this pull request may close these issues.

GSoC'21(FES): Detecting reassignment of p5.js reserved constants and functions
3 participants