Undefined Variable Declaration

Hello, I have the code: const queue = new Map();

But Map is undefed. Can anyone help?

It’ll just be a linter warning. So long as the code is valid, it will still work.

You can specify global variables at the top of your file to make this warning go away - see https://eslint.org/docs/user-guide/configuring#specifying-globals

Hello @Gareth,

Linter errors due to Specifying Globals can be confusing for beginners who just learned how to use libraries.

From a pedagogical point of view, shouldn’t this rule (or maybe all linter rules) be turned off on a beginner friendly platform like Glitch?

Linter errors could still be activated with a .eslintrc file.

We’ve since updated our linting rules so this specific issue should no longer be a problem - my response was a work around useful at the time of posting.

However, I’m interested to understand more about that perspective. Globals aside, linting would seem to be useful for beginners to reinforce learning correct syntax and avoiding confusing runtime issues resulting from incorrect syntax.

Hello Gareth,

it seems this rule is still active: see https://glitch.com/edit/#!/hello-ml5js?path=script.js:4:66

This is weird since i had no errors with jQuery on different examples.

Globals aside, linting would seem to be useful for beginners to reinforce learning correct syntax and avoiding confusing runtime issues resulting from incorrect syntax

Agree, yet i believe that only true errors preventing running the script (like forgetting a ; in a for loop, or a } in a css file ) should show an error hint, while ESLint could show a warn hint.
This way beginners would know about their errors and could also learn about “best practices”.

More over, ESLint messages can be confusing: in the case of the Specifying Globals rule ‘XXX’ is not defined, beginners don’t understand that the message is in the context of this script (I imported my XXX correctly in my html file, why is XXX not found?). Message warning could be “XXX is not defined in this script”.

Initiatives like Processing and p5.js are doing great work on trying to make errors more understandable for beginners: Friendly Error System for p5.js

Re-thinking ESLint messages could add even more friendliness to the already friendly platform that Glitch is.

I was referring specifically to the Map issue. But thanks for taking the time to provide that feedback. I’ll share it with the team to talk through!

1 Like

This issue with Specifying Globals rule iseven more flagrant when using p5js: https://glitch.com/edit/#!/p5js-hello-p5-animation?path=sketch.js:2:9

Agree with the linting issues with the p5 library. What’s the best way to fix this so that we don’t see all these linting errors in code using the p5.js library? I’m working with some students to help them transfer code they wrote on Khan Academy over to run on Glitch using p5.js. The code works fine but all the lint errors are distracting

hi dave - you’ll want to specify the global variables (including function names) at the top of the file so the linter doesn’t put red dot errors alongside them throughout the code. for example:

/* global fill, text, rect */

or /*eslint no-undef: 0*/ to turn off this rule

1 Like

Took the survey for how next glitch might look and this would be great to have a setting to turn eslint on/off 'cause this is really confusing for a lot of beginners (and I’m speaking as a teacher with ~1500 new glitch users/year) @jenn

Hello @MAKIO135,

Be sure to create a new thread next time instead of bumping an old one :slight_smile:

This is related to my answers 2 years ago, but I do understand

1 Like