如何在StyleCop.Settings文件中添加全局警告规则抑制?

时间:2014-06-24 09:19:10

标签: visual-studio-2010 configuration warnings stylecop suppress-warnings

我收到5k +不同口味的StyleCop警告。我正在使用Visual Studio 2010 Express版本,因此没有菜单选项可以转到StyleCop设置或禁止在Visual Studio中发出警告。只剩下选项是编辑我试图做的StyleCop.Settings文件,我使用的StyleCop版本是4.7。

我的StyleCop.Settings文件如下所示:

<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>

我如何编辑设置文件以取消CSharp.OrderingCSharp.Documentation内的所有警告,或按代码(SA1202, SA1600进行编码)?我不介意任何解决方案。

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

1 个答案:

答案 0 :(得分:6)

在您的StyleCop安装文件夹中解决了我自己StyleCop.Settings文件所在的文件夹(在我的情况下为C:\Program Files\StyleCop 4.7)。
应该有一个名为StyleCopSettingsEditor.exe的文件。将StyleCop.Settings拖放到StyleCopSettingsEditor.exe这将启动应用程序并打开下面屏幕截图中显示的窗口。

enter image description here

您可以按组或按特定代码编辑设置。

对于那些因任何原因无法使用编辑器的人,下面的XML显示编辑后StyleCop.Settings文件的外观。

<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>