Detect duplicate code within ASP.NET MVC project in Visual Studio - javascript

Is there any way at all to detect duplicate code within ASP.NET MVC project in Visual Studio 2013 Professional???
I want to detect duplicate JavaScript functions within the cshtml files in the Views.
I've been searching forever and can't find a viable solution.

Our JavaScript CloneDR code duplication detector should be able to do this. (This obviously isn't part of VS 2013.)
Its parser can read plain Javascript, and/or html-like pages that contain JavaScript chunks in Script tags, and/or HTML script attributes (e.g., OnXXX= ). You can hand it lots of files and it will find clones across the files.
You can see examples of what it detects at the link.

Related

How can I access embedded ASP.NET GlobalResources in JavaScript?

I'm working on a legacy ASP.NET project, which I'm trying to massage into shape slowly, but I can't make significant changes without it all collapsing like a chocolate finger house....
I've tried to find a solution for this, but failed miserably due to the specific mix of terminology ("javascript", "embedded" and/or "resource" just give me information as to how to embed a .js file...), and the fact that it's probably a weird way of doing things.
The project makes use of App_GlobalResources for translatable strings, which is used in C# code behind, the markup and in some of the JavaScript. For example:
HTML:
Text="<%$Resources: Resources, MeasuresLabel %>"
JS:
setDialogTitle('summaryDialog', physicalElementName, Resources.Resources.Summary);
This was all working fine, until we started using NUnit for some integration testing. To make the Resources.resx available to NUnit I've followed Scott Allen's suggestion, which works for NUnit but means that the above Resources.Resources is undefined.
So, my question is with this embedded file, how can I make it accessible to the JavaScript (or is there a better way I can make it available to NUnit)?
There's an the added complication due to the code I want to access it with being in separate .js files, rather than within script tags in the .aspx files.
EDIT
After looking at it some more, the real challenge is the properties that are accessed in the JS are static. Due to the number of places these are referenced, it's not practical to add a variable for each string that's being used.
I think that JS files aren't going through the ASP.NET engine and they are served as they are, that's why Resources.Resources.Summary isn't defined in your case, while it will work when embedded inside <script> tag in .aspx file.
The only way I know around this would be to store the used resource values in global javascript variables on the .aspx page and then use them in loaded JS files.

Intellij idea Javascript formatting and highlighting

I am new to developing webapps in Intellij so this may be a simple question. How do I get it to properly display Javascript syntax when I am editing scripts within an HTML page. For example when I create an external file with a .js extension it properly formats the Javascript, but when I have in in-file Javascript function it fails to pick up on it and displays it as plain text. Is this a limitation of the community edition?
It is most likely a limitation of the comunity edition. If you go to the comparison page you will notice a few differences:

Visual Studio: Cleaning up abandonent javascript functions

I have a web application in visual studio, it has several JavaScript, jQuery files, third libraries and custom files.
I am looking for any tool which will help me remove methods are not called anywhere. This is for custom code files added by another coder.
Current Approach
Copy function name - search for it, and remove methods manually.

ms:script tags in XSLT

I am attempting to migrate an ASP Classic application to .Net 4.0 (4.5 would also be acceptable). The application is responsible for performing XSL Transformations using Javascript extension functions. The ASP Classic application currently uses MSXML 4.0 to perform the transformations.
I am running into problems in .Net when I try and use the XslCompiledTransform class to process a transform that includes javascript extensions. It works for simple examples but we have a fairly extensive javascript library and I am seeing error as the test cases become increasingly complex. The most frustrating of these errors are syntax errors, for example the .Net parser doesn't seem to like statements outside of functions.
Can anyone tell me which class is used to parse and compile the javascript extensions and if there is thorough documentation anywhere. Also can the the javascript processor object be replaced with a custom object (in a similar manner to a UriResolver).
Also, is it possible to use the parser rules to have Visual Studio highlight javascript syntax errors when viewing the file. I am pretty sure it already does this for javascript code that is used in web pages and such, but the syntax rules seem to be different in XSLT.
AFAIR XslCompiledTransform uses CodeDom to compile embedded scripts. The way it works is that XslCompiledTransform creates a code file that is then passed to CodeDom for compilation. I believe MSXML uses a different JavaScript engine than the one used by CodeDom. Hence the compilation problem. In addition (it's been a while since I looked at it) there may be some additional processing happening to make the scripts compilable (I remember that for scripts in C# there was a class created and all functions were put to this class).
Note that the assemblies created by CodeDom are loaded to the appdomain where the transformation is executed. This may lead to OutOfMemory exceptions since the CLR does not allow to unload assemblies - I wrote about this some time ago here: http://blogs.msdn.com/b/xmlteam/archive/2011/09/26/effective-xml-part-5-something-went-really-wrong-outofmemoryexception-and-stackoverflowexception-thrown-when-using-xslcompiledtransform.aspx

What VS 2010 project for a plain HTML and JS project

What VS 2010 project template would you use for a plain HTML and JS project, no ASP or other code. Just plain vanilla HTML / JS. I am using an empty Web project ("ASP.net empty Web Application"), still giving me unnecessary files and directories. Is there anything better?
This question is not about extensions for JS, such as Visual Studio Javascript extensions feature comparison .
-- Update as of 15. August --
I have deleted the extra directories and references to the extend possible. The bin folder gets recreated whenever the application is build, but I can solve this on Solution level by switching of the build (Configuration properties). The webconfig is required for debugging - I cannot get rid of this one - so this is the best I get until now.
Damn - obj and bin directories are recreated when closing and re-opening VS2010 (preparing solution stage). So I have to live with some overhead of files / directories.
-- As of 18.August --
Guess there is no better way, delete as much as possible and live with the remaining "trash".
Visual Studio Web Development is orientated to ASP.NET projects creation, but you can build without any problem, HTML & JS applications *deleting the extra directories* created for ASP.NET apps, which need that.
Best regards.
Ángel Manuel.
Have you considered creating a web site in visual studio instead of using a web project? File -> New -> Web Site. It's still directed towards asp.net development but it might be more what you are looking for.
I'd just use a text editor/hilighter like Notepad++ :P

Categories

Resources