Search code examples
visual-studio-2010configurationwarningsstylecopsuppress-warnings

How to add global warning rule suppression in StyleCop.Settings file?


I am getting 5k+ StyleCop warnings of different flavours. I am using Visual Studio 2010 Express edition, so there is no menu option to go to StyleCop settings or do suppressions for warnings from within Visual Studio. Only option left is to edit StyleCop.Settings file which I am attempting to do atm, StyleCop version I am using is 4.7.

My StyleCop.Settings file looks like this:

<StyleCopSettings Version="4.3">
  <GlobalSettings>
    <CollectionProperty Name="DeprecatedWords">
      <Value>preprocessor,pre-processor</Value>
      <Value>shortlived,short-lived</Value>
    </CollectionProperty>
  </GlobalSettings>
  <Parsers>
    <Parser ParserId="StyleCop.CSharp.CsParser">
      <ParserSettings>
        <CollectionProperty Name="GeneratedFileFilters">
          <Value>\.g\.cs$</Value>
          <Value>\.generated\.cs$</Value>
          <Value>\.g\.i\.cs$</Value>
        </CollectionProperty>
      </ParserSettings>
    </Parser>
  </Parsers>
  <Analyzers>
    <Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
      <AnalyzerSettings>
        <CollectionProperty Name="Hungarian">
          <Value>as</Value>
          <Value>do</Value>
          <Value>id</Value>
          <Value>if</Value>
          <Value>in</Value>
          <Value>is</Value>
          <Value>my</Value>
          <Value>no</Value>
          <Value>on</Value>
          <Value>to</Value>
          <Value>ui</Value>
        </CollectionProperty>
      </AnalyzerSettings>
    </Analyzer>
  </Analyzers>
</StyleCopSettings>

How would I need to edit settings file to suppress all warnings that are within CSharp.Ordering and CSharp.Documentation, or do it code by code (SA1202, SA1600)? I don't mind any solution.

SA1202 : CSharp.Ordering : All private methods must be placed after all public methods.     
SA1600 : CSharp.Documentation : The method must have a documentation header.    

Solution

  • Solved myself, in your StyleCop installation folder, same folder where StyleCop.Settings file is (in my case its C:\Program Files\StyleCop 4.7).
    There should be a file named StyleCopSettingsEditor.exe. Drag and drop StyleCop.Settings onto StyleCopSettingsEditor.exe this should launch the application and open the window shown in screenshot below.

    enter image description here

    You can edit settings by group or by specific code.

    For those who do not have ability to use editor for whatever reason, XML below shows how StyleCop.Settings file looks after editing.

    <StyleCopSettings Version="105">
      <GlobalSettings>
        <CollectionProperty Name="DeprecatedWords">
          <Value>preprocessor,pre-processor</Value>
          <Value>shortlived,short-lived</Value>
        </CollectionProperty>
      </GlobalSettings>
      <Parsers>
        <Parser ParserId="StyleCop.CSharp.CsParser">
          <ParserSettings>
            <CollectionProperty Name="GeneratedFileFilters">
              <Value>\.g\.cs$</Value>
              <Value>\.generated\.cs$</Value>
              <Value>\.g\.i\.cs$</Value>
            </CollectionProperty>
          </ParserSettings>
        </Parser>
      </Parsers>
      <Analyzers>
        <Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
          <AnalyzerSettings>
            <CollectionProperty Name="Hungarian">
              <Value>as</Value>
              <Value>do</Value>
              <Value>id</Value>
              <Value>if</Value>
              <Value>in</Value>
              <Value>is</Value>
              <Value>my</Value>
              <Value>no</Value>
              <Value>on</Value>
              <Value>to</Value>
              <Value>ui</Value>
            </CollectionProperty>
          </AnalyzerSettings>
        </Analyzer>
        <Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
          <Rules>
            <Rule Name="ElementsMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PartialElementsMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="EnumerationItemsMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DocumentationMustContainValidXml">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementDocumentationMustHaveSummary">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PartialElementDocumentationMustHaveSummary">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementDocumentationMustHaveSummaryText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PartialElementDocumentationMustHaveSummaryText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementDocumentationMustNotHaveDefaultSummary">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementParametersMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementParameterDocumentationMustMatchElementParameters">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementParameterDocumentationMustDeclareParameterName">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementParameterDocumentationMustHaveText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementReturnValueMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementReturnValueDocumentationMustHaveText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="VoidReturnValueMustNotBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="GenericTypeParametersMustBeDocumented">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="GenericTypeParametersMustBeDocumentedPartialClass">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="GenericTypeParameterDocumentationMustMatchTypeParameters">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="GenericTypeParameterDocumentationMustDeclareParameterName">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="GenericTypeParameterDocumentationMustHaveText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PropertySummaryDocumentationMustMatchAccessors">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PropertySummaryDocumentationMustOmitSetAccessorWithRestrictedAccess">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementDocumentationMustNotBeCopiedAndPasted">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="SingleLineCommentsMustNotUseDocumentationStyleSlashes">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DocumentationTextMustNotBeEmpty">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DocumentationTextMustContainWhitespace">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DocumentationMustMeetCharacterPercentage">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ConstructorSummaryDocumentationMustBeginWithStandardText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DestructorSummaryDocumentationMustBeginWithStandardText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DocumentationHeadersMustNotContainBlankLines">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="IncludedDocumentationXPathDoesNotExist">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="IncludeNodeDoesNotContainValidFileAndPath">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="InheritDocMustBeUsedWithInheritingClass">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementDocumentationMustBeSpelledCorrectly">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileMustHaveHeader">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderMustShowCopyright">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderMustHaveCopyrightText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderMustContainFileName">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderFileNameDocumentationMustMatchFileName">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderMustHaveValidCompanyText">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
          </Rules>
          <AnalyzerSettings />
        </Analyzer>
        <Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
          <Rules>
            <Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementsMustAppearInTheCorrectOrder">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ElementsMustBeOrderedByAccess">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ConstantsMustAppearBeforeFields">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="StaticElementsMustAppearBeforeInstanceElements">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="DeclarationKeywordsMustFollowOrder">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="ProtectedMustComeBeforeInternal">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="PropertyAccessorsMustFollowOrder">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="EventAccessorsMustFollowOrder">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="StaticReadonlyElementsMustAppearBeforeStaticNonReadonlyElements">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
            <Rule Name="InstanceReadonlyElementsMustAppearBeforeInstanceNonReadonlyElements">
              <RuleSettings>
                <BooleanProperty Name="Enabled">False</BooleanProperty>
              </RuleSettings>
            </Rule>
          </Rules>
          <AnalyzerSettings />
        </Analyzer>
      </Analyzers>
    </StyleCopSettings>