ReSharper with StyleCop Configuration - resharper

My understanding is that running StyleCop as a ReSharper extension uses the Analyzer technology built into VS 2015 and, in this way, it differs from downloading and installing StyleCop as a standalone program. When I previously installed StyleCop as a standalone program, I had access to a StyleCop .Settings file that let me use the StyleCop dialog box for selecting certain options. Among those options was a Company Information tab, into which you can place Company Name and a Copyright notice:
StyleCop Settings Documentation for the Company Information Tab
When ReSharper shows a StyleCop rule that needs attention and it has to do with adding a XML summary comment to the top of my class, ReSharper places the comment text for me. However, there is a space for Company Name and that value is always blank. This means that I must modify it manually, and that's tedious.
Question:
How do I tell ReSharper to populate the Company Name field with a certain value? Can I do that on a solution basis or does that Company Name field get defined globally?
Thank you.

If you're using StyleCop for ReSharper, it's actually using the same StyleCop parser that the command line uses, and not the VS2015 analyzers (unless you're actually using StyleCopAnalyzers). However, inserting comments and rewriting code is all ReSharper code. The plugin will still use your existing stylecop.settings files, and the company name comes from there. You can edit the file with the settings editor from the normal install of StyleCop.

Related

Is there a way to make ReSharper check for correct file headers

Update: Using StyleCop for ReSharper Plugin did the trick for code analysis inside VS. But unfortunately it seems that ReSharper plugins don't work in ReSharper command line inspections.
Is there a way to make ReSharper check for correct file headers just like classic StyleCop did. I'm aware that there is a way to define file headers to be inserted in new files, but we are using Resharper command line inspections to check a rather big legacy codebase. So it would be helpful if there was an automatic check for correct file headers.
I'm referring to StyleCop rules SA1633 up to SA1649.
This isn't exacly an answer to your question but you can use editorconfig to increase the error level during build.
Refer to roslyn editorconfig

%(AdditionalIncludeDirectories) meaning

Think this will be rather simple but somehow I could not find a reference saying about this.
In the MSVC Include directories, there is an Additional Include Directories setting. The setting reads like this
..\Project1; %(AdditionalIncludeDirectories)
Understand the first part is the path for the program to search for additional program header includes. What about " %(AdditionalIncludeDirectories) " ? what does it mean?
It does not seem to be a macro which I understand is headed by "$" eg $MACRO
Thanks
Answer
In the documentation for Working with Project Properties there is a section on "item macros":
Item macros
Has the syntax %(name). For a file, an item macro applies only to that fileā€”for example, you can use %(AdditionalIncludeDirectories) to specify include directories that apply only to a particular file. This kind of item macro corresponds to an ItemGroup metadata in MSBuild. When it's used in the context of a project configuration, an item macro applies to all files of a certain type. For example, the C/C++ Preprocessor Definitions configuration property can take a %(PreprocessorDefinitions) item macro that applies to all .cpp files in the project. This kind of item macro corresponds to an ItemDefinitionGroup metadata in MSBuild. For more information, see Item Definitions.
Discussion
I had exactly the same problem in a project I am taking over from a former developer : his Additional Include Directories are C:\Users\t-tshmit\Downloads\DirectXTK;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)
And oddly the %(AdditionalIncludeDirectories) element is not included in the edit box
Looking around the web I could not find much on this, but it is clearly a pattern in use, for example the screenshot used in http://www.steptools.com/support/stdev_docs/help/settings_vc10.html may contain the %(AdditionalIncludeDirectories) element.
The documentation for both the Additional Include Directories compiler options and the AdditionalIncludeDirectories VCCL Compiler Tool property contain no mention of this %(NAME) pattern.
https://learn.microsoft.com/en-us/cpp/build/reference/common-macros-for-build-commands-and-properties?view=vs-2019
They are called "item metadata macros."
The build system for C++ was significantly changed between Visual
Studio 2008 and Visual Studio 2010. Many macros used in earlier
project types have been changed to new ones. These macros are no
longer used or have been replaced by one or more equivalent properties
or item metadata macro (%(name)) values. Macros that are marked
"migrated" can be updated by the project migration tool. If the
project that contains the macro is migrated from Visual Studio 2008 or
earlier to Visual Studio 2010, Visual Studio converts the macro to the
equivalent current macro. Later versions of Visual Studio can't
convert projects from Visual Studio 2008 and earlier to the new
project type. You must convert these projects in two steps; first
convert them to Visual Studio 2010, and then convert the result to
your newer version of Visual Studio. For more information, see
Overview of potential upgrade issues.

How to get XML comments to appear in Visual Studio Class Wizard decriptions

I have put XML comments in a C++ source file that IntelliSense appears to pick up and use. It creates a project xml file, and IntelliSense works when I edit the original source file (showing me comments when I'm selecting a member function or entering parameters).
But, when I go to the Class Wizard in Visual Studio 2012 Express, the entered descriptions don't appear anywhere (on the methods, for example, down at the bottom of the dialog, where description remains sadly empty). For that matter, IntelliSense only works in the original file(s), so when using a call in a separate file, none of my XML comments get picked up. Why does it only work in the original source file? What have I neglected to do?
I don't think you've neglected to do anything, unfortunately.
The Class Wizard was built long before Visual Studio supported XML doc comments, so it's more likely that no one remembered/cared to go back add support for them to the Class Wizard dialog.
In my experience, although it sounds like you've had slightly better luck, XML doc comments are not particularly well supported when using C++. For example, VS 2012 was the first version to support them in IntelliSense (and even that is incomplete). You get nothing in VS 2010 and earlier versions, despite the fact that they'll happily output a project XML file. That pathetic lack of support, combined with the angle bracket tax, drove me to switch to Doxygen when writing C++ code.

Disable Automatic File Header Creation (ReSharper and StyleCop)

I recently installed R# 6.1 (C# version, not Full) with StyleCop 4.7.34.0 (with the R# plugin). When adding a new class to a project, the file header information is automatically added. How do you disable this?
I've turned off the checkbox for "Insert text into documentation and file headers" within the R# options for StyleCop (Options > Tools > StyleCop > Headers section).... but still no luck.
I've also turned off StyleCop rules SA1633 to SA1640 that requires the header documentation.
I found this related post that suggests:
ReSharper -> Options -> Tools section -> Code Cleanup -> select StyleCop profile -> Documentation section -> untick 1600
but I don't have a "Code Cleanup" node in my tools section. Not sure if the fact that I'm using a "C#" version of R# has something to do with it.
The problem is actually because of this:
http://stylecop.codeplex.com/discussions/348351/
When you try to uncheck the StyleCop settings under Code Cleanup (Options > Code Editing > Code Cleanup > StyleCop > 1600 and 1633-1641) and click Save it does not actually save the changes! This seems to be a bug in ReSharper.
The only workaround i've found is to make a new profile (Add) and immediately uncheck 1600 then click Save. This will have to be set as the Profile to use on silent cleanup. Good luck
EDIT: here are the settings for my profile that is set as the 'silent cleanup' one. It does not add the headers. hope that helps
I had this problem and found that the issue was not ReSharpers global StyleCop settings (arserbin3s answer); but the project specific ones.
Right click on your existing project and select "StyleCop Settings".
First step
From there deselect "Documentation Rules" (or the specific rules you desire).
Second step
Finally, I had to close and open Visual Studio. This prevented Resharper refactors from writing the headers and documentation.
You may have different context menu options to me.
Either way, the key is that StyleCop can be project specific.
stylecop.codeplex.com/wikipage?title=Managing%20StyleCop%20Project%20Settings

How to add custom code analysis in ReSharper

I'm new to ReSharper.
For those who uses Resharper, is there a way I can add custom code analysis rules?
For example I might have a rule say All private variables should start with letter "m". How can I add this to Resharper so if I violate this, it can shows as a warning or an error?
I know the question is old, but for all folks coming from google like me:
Resharper -> Options -> Code inspections -> Custom Patterns
There you can create your own rules for highlighting patterns or offering substitutions. This is for ReSharper 8. I'm not sure from which version this option is there.
Just to expand on what #AakashM notes above: this can be specified in ReSharper Options | Languages | (either Common or C# or whatever) | Naming Style.
If you click on Advanced Settings, and then double-click on one of the "entity descriptions", there is a far larger selection of possible entities (including events, namespaces etc) , together with access rights (private, protected, etc) and so on, for which you can define prefix, suffix and casing rules.
You can write your own plugins for ReSharper. Take a look at here:
http://stylecopforresharper.codeplex.com/
This is similar to what you're asking for. It might even do what you want. Not sure since I'm not a big StyleCop user.
Also take a look at the first in my series of blog posts coming on ReSharper plugins:
http://hadihariri.com/2010/01/12/writing-plug-ins-for-resharper-part-1-of-undefined/

Resources