Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convince WebStorm that my userscript loads jQuery?

I have a userscript that loads jQuery using the @require directive in the metadata block:

// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js

I guess WebStorm doesn't "know" about userscripts, so it has no idea that that, say, $ is a function that will already be defined by the time I reference it in my userscript.

Can I make WebStorm believe that my file effectively has the contents of jquery.min.js inlined at the top of the file, so that it'll stop giving me warnings about $ being undefined? e.g. can I maybe place a local copy of jquery.min.js in a local folder somewhere and tell WebStorm that it can assume all declarations made in that file?

like image 611
senshin Avatar asked Oct 19 '25 13:10

senshin


1 Answers

Thanks to hobbs for his comment - JetBrains has a documentation page for Configuring JavaScript Libraries.

What I did was:

  1. Download the development version of jQuery 2.1.3 (the "official" JetBrains version of jQuery is 2.0.0).
  2. Go to Settings > Languages & Frameworks > JavaScript > Libraries.
  3. Click Add. In the menu that pops up:
    1. Name it something.
    2. Add (green plus button) the downloaded jquery-2.1.3.js file.
    3. Set Type to Debug.

And now WebStorm believes that my userscript loads jQuery. Hooray!

like image 132
2 revssenshin Avatar answered Oct 22 '25 05:10

2 revssenshin