Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent StyleCop warning of a Hungarian notation when prefix is valid

I have the following code:

var fxRate = new FxRate();

which is giving me the following StyleCop ReSharper warning:

The variable name 'fxRate' begins with a prefix that looks like Hungarian notation.

I have tried copying the Settings.StyleCop file to my solution folder and adding an entry for fx:

  <Analyzers>
    <Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
      <AnalyzerSettings>
        <CollectionProperty Name="Hungarian">
          ...
          <Value>fx</Value>
          ...

I've restarted VS but I still get the same warning. I am using the StyleCop ReSharper extension in VS2017.

How do I ensure 'fx' is a valid prefix in the solution (for all team members)?

like image 995
openshac Avatar asked Sep 06 '18 11:09

openshac


1 Answers

I am using VisualStudio 2017 with ReSharper 2018.2 and the corresponding StyleCop by JetBrains extension (Version 2018.2.0 - StyleCop.ReSharper.dll 5.0.6329.1 )


In our projects I have added the Settings.StyleCop file in the solution folder next to the solution file. To test your prefix I have added fx to my settings file and it worked out of the box.

My file contains the following analyzer rule.

<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
    <Rules>
        <Rule Name="FieldNamesMustNotUseHungarianNotation">
          <RuleSettings>
            <BooleanProperty Name="Enabled">True</BooleanProperty>
          </RuleSettings>
        </Rule>
    </Rules>
    <AnalyzerSettings>
        <CollectionProperty Name="Hungarian">
            ...             
            <Value>fx</Value>
            ..                
        </CollectionProperty>      
   </AnalyzerSettings>

And my Resharper configuration looks like this:

StyleCop Configuration


How do I ensure 'fx' is a valid prefix in the solution for all team members)?

In our projects we always check in the StyleCop settings file, so we ensure that the all members use the right one and we can keep it up-to-date for all.


In addition to the ReSharper Plugin you can also use the StyleCop Package found in the NuGet store and add it to your solution:

StyleCop - NugetPackage

The StyleCop team recommends to use the StyleCopAnalyzers over the StyleCop extension when using VisualStudio 2015 and later.

like image 181
Martin Backasch Avatar answered Nov 13 '22 13:11

Martin Backasch