Preventing Items from being analyzed in ReSharper

With the imminent release of ReSharper 6, and support for JavaScript as well as CSS, we’ve had a few people ask us how to prevent ReSharper 6 from detecting issues in certain files that are not supported, for instance .less. Although many operations are available for these types of files, including “Move To Folder” (and consequent reference updates), analysis is not currently available.

Eliminating Items from Analysis

ReSharper allows us to completely exclude specific files and folders from Analysis. Currently, it does not support file masks, so we cannot tell it to ignore all *.less files. What we can do however is place all files of a certain type into a folder and add that folder to be excluded. To do this, we first move the specific files by using the “Move To Folder” refactoring and create a new folder called less for instance (which can be created using the same dialogue box).

In order to now exclude this folder, we need to go to ReSharper | Options | Code Inspection |Settings

SNAGHTML2c0fc9

and click on the Edit Items to Skip button.  This now provides us the ability to add specific files and/or folders to list of items to skip.

SNAGHTML2d02ce

We then click on Add Folder and select the newly created folder (less).  Once we do that, all analysis on the skipped items will stop. Obviously this is available for any kind of file so you can add anything there.

Note: You can also add/remove files and folders quickly by pressing the shortcut key Ctrl+Shift+Alt+8.

In the case of CSS/.less, if you still see squiggles under certain elements, that is Visual Studio error highlighting, not ReSharper. You can turn that off using Tools | Options | Text Editor | CSS | Miscellaneous.

Generated Code

Below the previous menu option, there is another entry Generated Code:

image

How is this different from the above? The entries on this page, which do allow masks (as well as regions), do get analyzed, yet no hints, warnings, suggestions or quick fixes are offered since it does not make much sense. However, and this is important, files still do get analysed to provide error information and completion. This is what makes Generated Code different from Items to Skip.

Note: In ReSharper 6 and below, Generated File Masks and Generated Code Regions are GLOBAL and not Solution based. However, they can only be edited when a solution is open. This will be solved in a future release along with other improvements in the area of settings across solutions/projects.

This entry was posted in ReSharper Tips&Tricks and tagged , . Bookmark the permalink.

16 Responses to Preventing Items from being analyzed in ReSharper

  1. Markus Springweiler says:

    How do I disable URL recognition especially within Razor-html files? This really is nearly a shopstopper for us because we cannot use quick-fixes (alt+return) within these files because there always is some wrong url-quick-fix showing somewhere which would be executed then.
    Also just writing any href/src value is nearly impossible.

    Of course it’s fine to have this feature but there are projects where the links are relative to something else and not the project you are working on, because the project itself dynamically becomes an MVC area at runtime:
    http://orchard.codeplex.com/SourceControl/list/changesets?branch=default

  2. Gordon Freeman says:

    It would be nice to have a way to exclude unit test projects from reference counting but not from refactorings. If a method in a regular project is used only by a unit test (typically there was other uses before but they god suppressed) I’d like to see it marked as unused. But if I exclude the test project from Resharper analysis using Items to achieve this, then the files within this test project are going to be completely excluded from any refactoring. Am I missing something?

  3. Hadi Hariri says:

    @Markus,

    Are you talking about relative URL’s since I don’t seem to be having any problems writing out absolute URL’s. Relative ones are highlighted if it’s not found but it does not prevent me from applying quick fixes to other elements.

    If it’s this issue: http://youtrack.jetbrains.net/issue/RSRP-270873

    then we are aware of it and we’ll be providing a fix for 6.1. Unfortunately can’t make it into 6.0. The workaround as Sergey points out right now is to hit Ecape and then hit the quick-fix. Please also vote for this issue.

  4. Vasiliy Aksyonov says:

    Will items can be skipped by masks in future like generated code now?

  5. Vasiliy Aksyonov says:

    Also make possible to select two or more files at the time.

  6. Dennis says:

    What about looking at the System.CodeDom.Compiler.GeneratedCodeAttribute to ignore code?
    And one of the major sources of autogen code is *.resx.cs, so please add to the default.

  7. Joe White says:

    @Gordon, that sounds like an awesome suggestion — I’d also like to see code highlighted as “unused” if it’s only used from a test project. It’d be a bit tricky to get right, though. Occasionally it’s valuable to have, say, a constructor that’s only used by tests, or a method that surfaces some internal state just so it can be tested; and those shouldn’t be a warning.

    But if there’s an entire class, and it’s not in a test project but is only used by test projects, then a warning would be very cool. If you write this up in YouTrack and post a link here, I’ll vote for it.

  8. Albert Weinert says:

    A better way is, add Less and Sass support ;)

  9. Hadi Hariri says:

    @Vasilly

    Yes. WE hope to add the feature to remove items based on masks.

  10. Hadi Hariri says:

    @Albert,

    I think LEss is already filed in YouTrack….

  11. Albert Weinert says:

    @Hadi i found it, was not easy (less is so common) …

  12. Shatl says:

    +1 for exclude unit test projects from reference counting but not from refactorings

  13. Rui Lima says:

    If we have the following structure:

    [OpenSourceLibraries]
    [SolutionFolder]
    mySolution.sln
    [MyProject1]
    [MyProject2]

    When in mySolution.sln I can’t exclude dir OpenSourceLibraries. I select it but even so the selection is ignored

  14. Krunoslav says:

    I have a Silverlight unit test project that I disabled in re-sharper by specifying its root directory. But re-sharper still analyzes all of its issues in *.cs files.
    Funny enough, when I do “suppress with a comment’ thing, it still issues warnings nevertheless.

    In other words, bugger…
    What we see is not what we get, eh ?

    Full Version, Build 5.1.1753.4

  15. Hadi Hariri says:

    @Kruoslav

    could you please log a bug with steps to reproduce on http://youtrack.jetbrains.net?

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>