6

Visual studio seems intent that my javascript code is bad, mostly because it has no knowledge of jquery or some plugins I am using. Therefore, every time I compile my product it gives me a lot of warnings, most of them are incorrect ($ is not defined, window is not defined, etc...).

I have /// <reference path="" /> tags setup in my javascript with intellisense working properly so I know these are just not real issues.

How can I disable these warnings?

edit to be clear, I need these disabled because it's causing 100+ warnings that are making me lose sight of REAL c# warnings.

2

5 Answers 5

5

I had the exact same issue you were having: 100s of incorrect errors every save. For me the issue was with Chirpy, which was a prerequisite for another extension. For whatever reason on my end, Chirpy was not in my Extension Manager so it took me a while to find.

Check and see if you have it installed. If so disable JSHint.

  1. Tool -> Options
  2. Chirpy -> JSHint
  3. Uncheck: Run JS Hint
0
4
+25

try this and let me know if it works.

Enter the options through Tools > Options.

In the tree to the left, choose Text Editor > JScript > Miscellaneous. Uncheck "Show syntax errors".

4
  • Well that's annoying. That even turning that off every time I save it still generating the warnings.
    – KallDrexx
    Commented May 4, 2012 at 15:07
  • what kind of add-ons do you have installed? I've noticed some horrible things happening with various add-ons
    – Rob Allen
    Commented May 7, 2012 at 21:07
  • I only have the jscript editor extensions (which I uninstalled and still got the issue) and nuget. Although I didn't try uninstalling then unchecking that option, let me try that.
    – KallDrexx
    Commented May 8, 2012 at 12:40
  • Nope, even without jscript editor extensions those options still don't take effect :(
    – KallDrexx
    Commented May 8, 2012 at 12:43
1

I don't have a javascript source file on the computer I'm on at the moment to test this, but you may be able to use the #pragma command to disable particular warnings:

#pragma warning disable will disable all warnings, and #pragma warning restore will restore all warnings when placed at the end of your code block. You can also tell it to disable only particular warnings, such as #pragma warning disable 0219,0168.

http://abhijitjana.net/2010/08/27/how-to-suppress-complier-warning-using-pragma-warning-directives-in-visual-studio/

3
  • If I put that in the javascript though my javascript will have errors
    – KallDrexx
    Commented May 1, 2012 at 18:36
  • I thought that might be the case. :-(
    – MCattle
    Commented May 1, 2012 at 18:53
  • Just reviewing my answer, and I think you could get around the JavaScript errors by encasing the #pragma in a JavaScript comment block before and after the #pragma line.
    – MCattle
    Commented Jul 11, 2016 at 15:07
0

Interesting I am not able to reproduce your issue in neither VS2010 "website" project nor vs2010 "web application" project. It has to do with the add-ons that you installed. Probably you may have a setting in that add-on (who ever is causing this) to disable warnings.

To me the warning sounds like the add-on (who ever is causing this) is not intelligent enough. Try the below changes and see if that helps.

  1. If you have master page then try move the jquery*.js script reference from master page to your actual page
  2. Move all your javascript code into a js file instead of writing it them under script tag

Thanks,

Esen

0

What about this one?

To disable a single compiler warning

With a project selected in Solution Explorer, on the Project menu, click Properties.

Click the Compile tab.

In the Warning configurations table, set the Notification value for the warning to None.

or perhaps this one

Tools > Options > Text Editor > JScript > Misc > Show errors as warnings( uncheck only this )

Not the answer you're looking for? Browse other questions tagged or ask your own question.