IntelliJ unresolved function or method with jQuery - javascript

I've been fighting with $ being marked as unresolved function or method when IntelliJ is doing it's analysis. I tried downloading the jQuery library as part of IntelliJ and set the scope to global, but it still doesn't work. I'm currently using jquery 12.1.6.
Is there a way to get IntelliJ to realize that the $ is defined globally?

The jQuery v1.11.0 shows exactly the same behaviour here as well. At the same time previous version 1.10.2 works fine in IDE (no warnings).
I think it has something to do with "AMD-fy jQuery source" ticket (http://bugs.jquery.com/ticket/14113) -- looks like IDE has some issues figuring out this style.
If you wish (and can) -- roll back to jQuery v1.10.2 (which is like half a year old, which means it's stable and still good to use).
Hopefully IDE will be able to properly parse this new jQuery style in next release.
Actual ticket: http://youtrack.jetbrains.com/issue/WEB-10908

Related

How does jQuery Migrate plugin look for old code?

Just a conceptual question. Does the migrate plugin search through the javascript files pulled in by the browser? Or does the migrate plugin only look through code that is being executed by the server?
I need to use the jquery migrate plugin to update my code to the latest version of jquery. I'm trying to replace all instances of code stripped away in previous version and replace it with the latest ones.
From jQuery migrate docs:
Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used.
That way you can spot and fix what otherwise would have been errors, until you no longer need jQuery Migrate and can remove it.
Does it look through your files? No. It only warns when deprecated methods have been called from within your code

How to detect global variables with the sonar javascript plugin

We're trying to detect usage of global variables in our js code by using a sonar analysis. It seems that this rule was present in old versions of the javascript plugin, but not anymore (we're using version 1.2 of the plugin).
Are we doing something wrong ? Or is there a way to use XPath to mimic this rule ?
Thanks in advance
Previous version of the Sonar Javascript plugin was based on JSLint, and JSLint has a check for global variables. However, in the newest versions of the Sonar Javascript plugin, we removed JSLint and implemented our own parser and rules. This is why you don't get violations on this now.
Currently, we haven't implemented this rule but it's in our backlog (see http://jira.codehaus.org/browse/SONARPLUGINS-1821). Feel free to vote for it to push it up to the top of the backlog!
I'm not familiar with Sonar, but you can detect globals using this nifty little bookmarklet; or you could use the source code to work the results into your testing or CI framework, etc, etc.

How should one link to a jQuery library: always link to the latest library or not?

What happened is that we have a page that was previously working then all of sudden some scripts no longer work (for some reason). We figured out that we needed to use the latest jQuery library to fix the problem.
So we were thinking to just link to http://code.jquery.com/jquery-latest.min.js so that it's always updated.
However, we are also aware that if we will always use the latest jQuery library, the new version might cause some problems on other older scripts.
What is the best way to link the jQuery library then to minimize these types of issues?
Save the stable version of the library to your local/server and link to it. That's all.
It is a bad idea to link to http://code.jquery.com/jquery-latest.min.js
Jquery latest version always available in,
http://code.jquery.com/jquery-latest.js
For Latest Min Jquery, use
http://code.jquery.com/jquery-latest.min.js
To get latest jquery from other hosts, follow jquerylatest.com

jQuery / Prototype conflict: only in webkit, in bookmarklet

I most likely have the same problem as in this question:
Weird Chrome prototype/jQuery conflict
Basically it appears Prototype is conflicting with jQuery in Safari and Chrome. The solution in the question was to include prototype first, however I can't do that: I'm using jQuery loaded in my bookmarklet, and so some sites it is used on will always have Prototype already loaded. Now let's ignore for the moment the wisdom of using jQuery in the bookmarklet. It seems to me there should be a solution here (though I can't find it), for these reasons:
1) This conflict does not appear to occur at all in Firefox.
2) Though the question linked to above cites a page stipulating that jQuery should be included first, I no longer find that reference there. So maybe it is not current?
Error Example: once jQuery is loaded (e.g. you can test it's version -1.4.4), if you try in the firebug console:
jQuery('p:')
#yields => []
#or
jQuery('p:first')
# yields => TypeError: Object #<an Object> has no method 'find'
Some other notes:
-I have tried noConflict(). This does not seem to work at all.
-I never refer to '$' in my code, but only use 'jQuery'
-Using jQuery from the Google CDN
-Moving all the bookmarklet code into a frame would be very difficult, if possible at all, so I'd rather not go there.
Thanks for your help!
I had to do this for a client project, and ran into the exact same issue. After some research it looks like the conflict doesn't exist in 1.4.2, but does in 1.4.3 (I'm not sure about later versions). I downgraded to 1.4.2 and my bookmarklet now works on pages with Prototype.
Third comment here:
http://forum.jquery.com/topic/jquery-conflicts-with-prototype-and-the-fix
I believe that this is now fixed in jquery 1.5+ ....

Is there a good javascript plugin for visual studio?

I think that Visual Studio's biggest let down is the Javascript editor. I have been told to use Aptana as an editor for my javascript files, but I would prefer to stick with visual studio if possible.
I have read other similar plugin posts, but none focus specifically on Javascript.
VS2010 may offer some improvements, but will they be up to Apatana standards? I have briefly tested the beta, but I'm not overly impressed.
Is there anything out there that will bring Javascript closer to c# development? Considering the wide spread use of Javascript I think there must be something....... I hope! :)
Many thanks in advance... this is something that has always bugged me!
There's a couple recent plugins that may be helpful :
From Microsoft :
JScript Editor Extensions
Brace Matching
Outlining / Cold-folding
Current Word Highlighting
IntelliSense Doc-Comments Support
JSEnhancements
Outlining and matching braces highlighting
(I wouldn't think installing both of these is a good idea - and the Microsoft plugin has more features so try that one first)
VS is a pretty good IDE (especially when coupled with Resharper) but not so hot with Javascript. The debugger is good and there's the JSLint plugin but other than that I'm not sure. Aptana (based on Eclipse) is an excellent javascript IDE but it doesn't like it much when the javascript is embedded in aspx files (unless they updated the support recently). So far I'm not sure there's an ideal .net platform IDE for both client and server side stuff just yet.
Update: Resharper 6 added pretty good JavaScript support - so now I'd recommend that combination if you're doing a lot of debugging across client and server at the same time. If you're focussing on pure client code then I find WebStorm to be an excellent JavaScript/HTML IDE - even better than Aptana.
I'd really like to recommend Webstorm. It does not! treat your JS as text files.
Its a full blown JS editor and has become my favourite JS editor working in parallel with VS to handle my server side stuff.
WS has actual object intellisense across JS files. That means when I press . (dot) it shows me the functions on that objects, even if its located physically in another file.
It will recognize my objects (or their type if you will) created in other JS files referred to in the file I'm working on.
I have 'Find usages' on JS functions
I have 'find all references' on JS object / function / class / variable or whatever you want to search on. In the end its all objects but Webstorm knows this.
If I change the short/cut to F12, I can press F12 on my function call and it will jump to the implementation of that JS functon. Even if its located in another file.
Ofc. you have code folding and colouring, extract method and other neat code re factoring, overview creating tools.
Oh. And by the way.
I'd like to kill off a rumour going around in the cloud on forums I come across from time to time, looking for better ways to handle JS.
reSharper DO NOT SUPPORT JAVASCRIPT! A little piece of me dies every time I read some guy repeating what he saw on the reSharper site. It may have a some poor intellisense and some low level syntax check, but that has nothing to do with support.
Notepad++ supports JS better than VS in my opinion.
Münster
Don't forget to grab Chirpy to handle minifying your scripts in VS.
If you use Visual Studio, add the
/// <reference path="myOtherJsFile.js" />
directive at top of your js files and install Web Essentials you get pretty decent (but not perfect) intellisense, go to definition by using F12 and find all references (sort of..) by using SHIFT+F12

Categories

Resources