Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sublime-jslint: any way to ignore specific code sections?

I've got a ton of JS spaghetti that is in dire need of a good scrubbing. I've already configured sublimetext2 via package Control to use sublime-jslint, and I've passed the necessary command-line switches to jslint4java-2.0.1 so it knows how to do its magic. Problem is, these files contain some third party code pasted in. I cannot move this code outside of the file, because it is time-critical and needs to be loaded before anything else.

I looked into the jslint4java documentation and could not find a way to make it ignore a specific section of a script. I've searched through the site, and the only things about ignoring code regions that I could find were for jslint web version.

So, my question is: are there any ways to make it ignore a specific region of a javascript file? I'd rather not ignore the warnings if I can somehow sandbox that portion so jslint doesn't shout at me.

Thanks in advance.

like image 522
Please treat your mods well. Avatar asked Aug 20 '12 15:08

Please treat your mods well.


1 Answers

JSLint uses control comments as it is parsing to control its behavior. One method would be to disable all of the relevant ones before the third-party script. After the last line of the script, you would have to enable them again. Unfortunately, there is no control comment to disable linting as a whole.

A second option would be to put it into a separate file, which you explicitly state you do not want to do. However, it is sometimes possible to know whether this script is loaded depending on your situation.

This may not apply to you, but it may apply to someone else reading this question.

  • If you place the script above any other scripts on the page, it will always be loaded before any following scripts will execute.
  • If you are only using specific functions or variables that are solely defined in the other file, then you can check if the type is what you expected

Here is an example function that checks if the necessary function/var is loaded (won't work if the function or var is defined elsewhere). It checks 10 times over a period of 5 seconds

  • If you are calling both scripts dynamically, or cannot control their order, and you can't be certain that these vars/funcs weren't defined elsewhere, you can encapsulate all of your dependent code in a function and use an ajax callback to execute the code.

This is an example using plain JavaScript to handle AJAX Once this script is loaded with AJAX, use the second parameter to the function in the example to call your dependent code.

This is the best help I have to offer.

like image 135
johnrom Avatar answered Nov 09 '22 02:11

johnrom