提交 1b5b107c 编写于 作者: M manishv

DiagnosticDescriptor API changes and documentation comments: Change the...

DiagnosticDescriptor API changes and documentation comments: Change the DiagnosticDescriptor API as per the Diagnostics API review feedback. It now has following field with corresponding doc comments:

        /// <summary>
        /// Create a DiagnosticDescriptor, which provides description about a <see cref="Diagnostic"/>.
        /// </summary>
        /// <param name="id">A unique identifier for the diagnostic. For example, code analysis diagnostic ID "CA1001".</param>
        /// <param name="description">A short localizable description of the diagnostic. For example, for CA1001: "Types that own disposable fields should be disposable".</param>
        /// <param name="messageFormat">A localizable format message string, which can be passed as the first argument to <see cref="M:System.String.Format"/> when creating the diagnostic message with this descriptor.
        /// For example, for CA1001: "Implement IDisposable on '{0}' because it creates members of the following IDisposable types: '{1}'."</param>
        /// <param name="category">The category of the diagnostic (like Design, Naming etc.). For example, for CA1001: "Microsoft.Design".</param>
        /// <param name="defaultSeverity">Default severity of the diagnostic.</param>
        public DiagnosticDescriptor(string id, string description, string messageFormat, string category, DiagnosticSeverity defaultSeverity) (changeset 1211580)
上级 23a2430c
......@@ -1975,11 +1975,11 @@ private static bool FilterAndAppendDiagnostics(DiagnosticBag accumulator, IEnume
ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn),
d.Location as Location,
options,
d.Kind);
d.Category);
}
else
{
reportAction = GetDiagnosticReport(d.Severity, d.Id, d.WarningLevel, d.Location as Location, options, d.Kind);
reportAction = GetDiagnosticReport(d.Severity, d.Id, d.WarningLevel, d.Location as Location, options, d.Category);
}
switch (reportAction)
......
......@@ -5955,7 +5955,7 @@ abstract class CompilationStartedAnalyzer : ICompilationStartedAnalyzer
[DiagnosticAnalyzer]
class MockDiagnosticAnalyzer : CompilationStartedAnalyzer, ISymbolAnalyzer
{
internal static DiagnosticDescriptor Test01 = new DiagnosticDescriptor("Test01", "", "", "Throwing a test diagnostic for types declared", "", DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor Test01 = new DiagnosticDescriptor("Test01", "", "Throwing a test diagnostic for types declared", "", DiagnosticSeverity.Warning);
public ImmutableArray<SymbolKind> SymbolKindsOfInterest
{
......
......@@ -45,7 +45,7 @@ public TestDiagnostic(string id, string kind, DiagnosticSeverity severity, Locat
public override string Id { get { return id; } }
public override string Kind { get { return kind; } }
public override string Category { get { return kind; } }
public override Location Location { get { return location; } }
......@@ -123,7 +123,7 @@ internal override Diagnostic WithWarningAsError(bool isWarningAsError)
class ComplainAboutX : ISyntaxNodeAnalyzer<SyntaxKind>
{
private static readonly DiagnosticDescriptor CA9999_UseOfVariableThatStartsWithX =
new DiagnosticDescriptor(id: "CA9999", kind: "Test", name: "CA9999_UseOfVariableThatStartsWithX", messageTemplate: "Use of variable whose name starts with 'x': '{0}'", category: "Test", severity: DiagnosticSeverity.Warning);
new DiagnosticDescriptor(id: "CA9999", description: "CA9999_UseOfVariableThatStartsWithX", messageFormat: "Use of variable whose name starts with 'x': '{0}'", category: "Test", defaultSeverity: DiagnosticSeverity.Warning);
public ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
......
......@@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics
{
public partial class SuppressMessageAttributeTests
{
private const string TestDiagnosticKind = "Test";
private const string TestDiagnosticCategory = "Test";
private const string TestDiagnosticMessageTemplate = "{0}";
private abstract class AbstractMockAnalyzer : IDiagnosticAnalyzer
......@@ -234,10 +234,9 @@ private static DiagnosticDescriptor GetRule(string id)
{
return new DiagnosticDescriptor(
id,
TestDiagnosticKind,
id,
TestDiagnosticMessageTemplate,
TestDiagnosticKind,
TestDiagnosticCategory,
DiagnosticSeverity.Warning);
}
}
......
......@@ -61,20 +61,20 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>
throw new ArgumentNullException("descriptor");
}
var message = descriptor.MessageTemplate;
var message = descriptor.MessageFormat;
if (messageArgs != null)
{
message = string.Format(message, messageArgs);
}
return Create(descriptor.Id, descriptor.Kind, message, descriptor.Severity, warningLevel: descriptor.Severity == DiagnosticSeverity.Warning ? 1 : 0, isWarningAsError: false, location: location ?? Location.None, additionalLocations: additionalLocations);
return Create(descriptor.Id, descriptor.Category, message, descriptor.DefaultSeverity, warningLevel: descriptor.DefaultSeverity == DiagnosticSeverity.Warning ? 1 : 0, isWarningAsError: false, location: location ?? Location.None, additionalLocations: additionalLocations);
}
/// <summary>
/// Creates a <see cref="Diagnostic"/> instance.
/// </summary>
/// <param name="id">An identifier for the diagnostic. For diagnostics generated by the compiler, this will be a numeric code with a prefix such as "CS1001".</param>
/// <param name="kind">The kind of diagnostic. For diagnostics generated by the compiler, the kind will be "Compiler".</param>
/// <param name="category">The category of the diagnostic. For diagnostics generated by the compiler, the category will be "Compiler".</param>
/// <param name="message">The diagnostic message text.</param>
/// <param name="severity">The diagnostic severity.</param>
/// <param name="warningLevel">The warning level, between 1 and 4 if severity is <see cref="DiagnosticSeverity.Warning"/>; otherwise 0.</param>
......@@ -88,7 +88,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>
/// <returns>The <see cref="Diagnostic"/> instance.</returns>
public static Diagnostic Create(
string id,
string kind,
string category,
string message,
DiagnosticSeverity severity,
int warningLevel,
......@@ -101,9 +101,9 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>
throw new ArgumentNullException("id");
}
if (kind == null)
if (category == null)
{
throw new ArgumentNullException("kind");
throw new ArgumentNullException("category");
}
if (message == null)
......@@ -111,7 +111,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>
throw new ArgumentNullException("message");
}
return new SimpleDiagnostic(id, kind, message, severity, warningLevel, isWarningAsError, location ?? Location.None, additionalLocations: additionalLocations);
return new SimpleDiagnostic(id, category, message, severity, warningLevel, isWarningAsError, location ?? Location.None, additionalLocations: additionalLocations);
}
internal static Diagnostic Create(CommonMessageProvider messageProvider, int errorCode)
......@@ -130,9 +130,9 @@ internal static Diagnostic Create(CommonMessageProvider messageProvider, int err
public abstract string Id { get; }
/// <summary>
/// Gets the kind of diagnostic. For diagnostics generated by the compiler, the kind will be "Compiler".
/// Gets the category of diagnostic. For diagnostics generated by the compiler, the category will be "Compiler".
/// </summary>
public abstract string Kind { get; }
public abstract string Category { get; }
/// <summary>
/// Get the text of the message.
......
......@@ -15,20 +15,15 @@ public class DiagnosticDescriptor
public string Id { get; private set; }
/// <summary>
/// The kind of the diagnostic (like compiler, unnecessary etc.)
/// A short localizable description of the diagnostic.
/// </summary>
public string Kind { get; private set; }
public string Description { get; private set; }
/// <summary>
/// Name of the diagnostic.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The parameterized message of the diagnostic.
/// A localizable format message string, which can be passed as the first argument to <see cref="M:System.String.Format"/> when creating the diagnostic message with this descriptor.
/// </summary>
/// <returns></returns>
public string MessageTemplate { get; private set; }
public string MessageFormat { get; private set; }
/// <summary>
/// The category of the diagnostic (like Design, Naming etc.)
......@@ -36,22 +31,27 @@ public class DiagnosticDescriptor
public string Category { get; private set; }
/// <summary>
/// The severity of the diagnostic.
/// The default severity of the diagnostic.
/// </summary>
/// <returns></returns>
public DiagnosticSeverity Severity { get; private set; }
public DiagnosticSeverity DefaultSeverity { get; private set; }
/// <summary>
/// Create a DiagnosticDescriptor
/// Create a DiagnosticDescriptor, which provides description about a <see cref="Diagnostic"/>.
/// </summary>
public DiagnosticDescriptor(string id, string kind, string name, string messageTemplate, string category, DiagnosticSeverity severity)
/// <param name="id">A unique identifier for the diagnostic. For example, code analysis diagnostic ID "CA1001".</param>
/// <param name="description">A short localizable description of the diagnostic. For example, for CA1001: "Types that own disposable fields should be disposable".</param>
/// <param name="messageFormat">A localizable format message string, which can be passed as the first argument to <see cref="M:System.String.Format"/> when creating the diagnostic message with this descriptor.
/// For example, for CA1001: "Implement IDisposable on '{0}' because it creates members of the following IDisposable types: '{1}'."</param>
/// <param name="category">The category of the diagnostic (like Design, Naming etc.). For example, for CA1001: "Microsoft.Design".</param>
/// <param name="defaultSeverity">Default severity of the diagnostic.</param>
public DiagnosticDescriptor(string id, string description, string messageFormat, string category, DiagnosticSeverity defaultSeverity)
{
this.Id = id;
this.Kind = kind;
this.Name = name;
this.Description = description;
this.Category = category;
this.MessageTemplate = messageTemplate;
this.Severity = severity;
this.MessageFormat = messageFormat;
this.DefaultSeverity = defaultSeverity;
}
}
}
......@@ -62,7 +62,7 @@ public override string Id
get { return this.Info.MessageIdentifier; }
}
public override string Kind
public override string Category
{
get { return "Compiler"; }
}
......
......@@ -19,7 +19,7 @@ public abstract partial class Diagnostic
internal sealed class SimpleDiagnostic : Diagnostic, ISerializable
{
private readonly string id;
private readonly string kind;
private readonly string category;
private readonly string message;
private readonly DiagnosticSeverity severity;
private readonly int warningLevel;
......@@ -27,7 +27,7 @@ internal sealed class SimpleDiagnostic : Diagnostic, ISerializable
private readonly Location location;
private readonly ImmutableList<Location> additionalLocations;
internal SimpleDiagnostic(string id, string kind, string message, DiagnosticSeverity severity,
internal SimpleDiagnostic(string id, string category, string message, DiagnosticSeverity severity,
int warningLevel, bool isWarningAsError, Location location,
IEnumerable<Location> additionalLocations)
{
......@@ -43,7 +43,7 @@ internal sealed class SimpleDiagnostic : Diagnostic, ISerializable
}
this.id = id;
this.kind = kind;
this.category = category;
this.message = message;
this.severity = severity;
this.warningLevel = warningLevel;
......@@ -55,7 +55,7 @@ internal sealed class SimpleDiagnostic : Diagnostic, ISerializable
private SimpleDiagnostic(SerializationInfo info, StreamingContext context)
{
this.id = info.GetString("id");
this.kind = info.GetString("kind");
this.category = info.GetString("category");
this.message = info.GetString("message");
this.severity = (DiagnosticSeverity)info.GetInt32("severity");
this.warningLevel = info.GetInt32("warningLevel");
......@@ -67,7 +67,7 @@ private SimpleDiagnostic(SerializationInfo info, StreamingContext context)
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("id", this.id);
info.AddValue("kind", this.kind);
info.AddValue("category", this.category);
info.AddValue("message", this.message);
info.AddValue("severity", (int)this.severity);
info.AddValue("warningLevel", this.warningLevel);
......@@ -81,9 +81,9 @@ public override string Id
get { return this.id; }
}
public override string Kind
public override string Category
{
get { return this.kind; }
get { return this.category; }
}
public override string GetMessage(CultureInfo culture = null)
......@@ -150,7 +150,7 @@ internal override Diagnostic WithLocation(Location location)
if (location != this.location)
{
return new SimpleDiagnostic(this.id, this.kind, this.message, this.severity, this.warningLevel, this.isWarningAsError, location, this.additionalLocations);
return new SimpleDiagnostic(this.id, this.category, this.message, this.severity, this.warningLevel, this.isWarningAsError, location, this.additionalLocations);
}
return this;
......@@ -160,7 +160,7 @@ internal override Diagnostic WithWarningAsError(bool isWarningAsError)
{
if (this.isWarningAsError != isWarningAsError)
{
return new SimpleDiagnostic(this.id, this.kind, this.message, this.severity, this.warningLevel, isWarningAsError, this.location, this.additionalLocations);
return new SimpleDiagnostic(this.id, this.category, this.message, this.severity, this.warningLevel, isWarningAsError, this.location, this.additionalLocations);
}
return this;
......
......@@ -448,10 +448,9 @@ private static DiagnosticDescriptor GetDiagnosticDescriptor(string analyzerName,
{
return new DiagnosticDescriptor(DiagnosticId,
CodeAnalysisResources.CompilerAnalyzerFailure,
DiagnosticId,
string.Format(CodeAnalysisResources.CompilerAnalyzerThrows, analyzerName, message),
category: DiagnosticId,
severity: DiagnosticSeverity.Info);
category: "Compiler",
defaultSeverity: DiagnosticSeverity.Info);
}
}
}
......@@ -31,7 +31,7 @@ public abstract class TestDiagnosticAnalyzer<TSyntaxKind> :
protected static readonly ImmutableArray<string> AllInterfaceMemberNames = ImmutableArray<string>.Empty.AddRange(typeof(TestDiagnosticAnalyzer<TSyntaxKind>).GetInterfaces().SelectMany(i => GetInterfaceMemberNames(i)));
protected static readonly DiagnosticDescriptor DefaultDiagnostic =
new DiagnosticDescriptor("CA7777", "Test", "CA7777_AnalyzerTestDiagnostic", "I'm here for test purposes", "Test", DiagnosticSeverity.Warning);
new DiagnosticDescriptor("CA7777", "CA7777_AnalyzerTestDiagnostic", "I'm here for test purposes", "Test", DiagnosticSeverity.Warning);
private static ImmutableArray<T> GetAllEnumValues<T>()
{
......
......@@ -5591,8 +5591,8 @@ Class MockDiagnosticAnalyzer
Inherits MockAbstractDiagnosticAnalyzer
Implements ISymbolAnalyzer
Friend Shared Test01 As DiagnosticDescriptor = New DiagnosticDescriptor("Test01", "", "", "Throwing a test1 diagnostic for types declared", "", DiagnosticSeverity.Warning)
Friend Shared Test03 As DiagnosticDescriptor = New DiagnosticDescriptor("Test03", "", "", "Throwing a test3 diagnostic for types declared", "", DiagnosticSeverity.Warning)
Friend Shared Test01 As DiagnosticDescriptor = New DiagnosticDescriptor("Test01", "", "Throwing a test1 diagnostic for types declared", "", DiagnosticSeverity.Warning)
Friend Shared Test03 As DiagnosticDescriptor = New DiagnosticDescriptor("Test03", "", "Throwing a test3 diagnostic for types declared", "", DiagnosticSeverity.Warning)
Public Overrides Function OnCompilationStarted(compilation As Compilation, addDiagnostic As Action(Of Diagnostic), cancellationToken As CancellationToken) As ICompilationEndedAnalyzer
Return Nothing
......
......@@ -64,7 +64,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
End Get
End Property
Public Overrides ReadOnly Property Kind As String
Public Overrides ReadOnly Property Category As String
Get
Return m_id
End Get
......@@ -104,7 +104,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
Friend Overrides Function WithWarningAsError(isWarningAsError As Boolean) As Diagnostic
If isWarningAsError AndAlso Severity = DiagnosticSeverity.Warning Then
Return New TestDiagnostic(Id, Kind, DiagnosticSeverity.Error, m_location, m_message, isWarningAsError, m_arguments)
Return New TestDiagnostic(Id, Category, DiagnosticSeverity.Error, m_location, m_message, isWarningAsError, m_arguments)
Else
Return Me
End If
......@@ -140,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
End Get
End Property
Private Shared ReadOnly CA9999_UseOfVariableThatStartsWithX As DiagnosticDescriptor = New DiagnosticDescriptor(id:="CA9999", kind:="Test", name:="CA9999_UseOfVariableThatStartsWithX", messageTemplate:="Use of variable whose name starts with 'x': '{0}'", category:="Test", severity:=DiagnosticSeverity.Warning)
Private Shared ReadOnly CA9999_UseOfVariableThatStartsWithX As DiagnosticDescriptor = New DiagnosticDescriptor(id:="CA9999", description:="CA9999_UseOfVariableThatStartsWithX", messageFormat:="Use of variable whose name starts with 'x': '{0}'", category:="Test", defaultSeverity:=DiagnosticSeverity.Warning)
Private ReadOnly Property IDiagnosticAnalyzer_SupportedDiagnostics() As ImmutableArray(Of DiagnosticDescriptor) Implements IDiagnosticAnalyzer.SupportedDiagnostics
Get
......
......@@ -33,7 +33,7 @@
<Name>CSharpCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\Core\FxCopRulesDiagnosticAnalyzers.csproj">
<Project>{ABD37A20-C734-4B09-91FE-BEC5DB82938A}</Project>
<Project>{90D2AB08-A2D4-4F77-BE9C-0476B7066BCB}</Project>
<Name>FxCopRulesDiagnosticAnalyzers</Name>
</ProjectReference>
<ProjectReference Include="..\..\Workspaces\Core\Workspaces.csproj">
......
......@@ -15,14 +15,12 @@ public class AssemblyAttributesDiagnosticAnalyzer : ICompilationStartedAnalyzer
internal const string CA1014RuleName = "CA1014";
internal static DiagnosticDescriptor CA1016Rule = new DiagnosticDescriptor(CA1016RuleName,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.AssembliesShouldBeMarkedWithAssemblyVersionAttribute,
FxCopRulesResources.AssembliesShouldBeMarkedWithAssemblyVersionAttribute,
FxCopDiagnosticCategory.Design,
DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor CA1014Rule = new DiagnosticDescriptor(CA1014RuleName,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MarkAssembliesWithCLSCompliantAttribute,
FxCopRulesResources.MarkAssembliesWithCLSCompliantAttribute,
FxCopDiagnosticCategory.Design,
......
......@@ -20,7 +20,6 @@ public abstract class CA1001DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
internal const string IDisposable = "System.IDisposable";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.TypesThatOwnDisposableFieldsShouldBeDisposable,
FxCopRulesResources.TypeOwnsDisposableFieldButIsNotDisposable,
FxCopDiagnosticCategory.Design,
......
......@@ -16,7 +16,6 @@ public abstract class CA1003DiagnosticAnalyzer : ICompilationStartedAnalyzer
internal const string RuleId = "CA1003";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(
RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.UseGenericEventHandlerInstances,
FxCopRulesResources.UseGenericEventHandlerInstances,
FxCopDiagnosticCategory.Design,
......
......@@ -35,19 +35,16 @@ public abstract class CA1008DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
internal const string RuleId = "CA1008";
internal static DiagnosticDescriptor RuleRename = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.EnumsShouldHaveZeroValue,
FxCopRulesResources.EnumsShouldZeroValueFlagsRename,
FxCopDiagnosticCategory.Design,
DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor RuleMultipleZero = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.EnumsShouldHaveZeroValue,
FxCopRulesResources.EnumsShouldZeroValueFlagsMultipleZero,
FxCopDiagnosticCategory.Design,
DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor RuleNoZero = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.EnumsShouldHaveZeroValue,
FxCopRulesResources.EnumsShouldZeroValueNotFlagsNoZeroValue,
FxCopDiagnosticCategory.Design,
......
......@@ -21,7 +21,6 @@ public abstract class CA1012DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1012";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.AbstractTypesShouldNotHavePublicConstructors,
FxCopRulesResources.TypeIsAbstractButHasPublicConstructors,
FxCopDiagnosticCategory.Design,
......
......@@ -15,7 +15,6 @@ public abstract class CA1017DiagnosticAnalyzer : ICompilationStartedAnalyzer
{
internal const string RuleId = "CA1017";
internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MarkAllAssembliesWithComVisible,
"{0}",
FxCopDiagnosticCategory.Design,
......
......@@ -19,7 +19,6 @@ public abstract class CA1018DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1018";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.CustomAttrShouldHaveAttributeUsage,
FxCopRulesResources.MarkAttributesWithAttributeUsage,
FxCopDiagnosticCategory.Design,
......
......@@ -22,7 +22,6 @@ public abstract class CA1019DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1019";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.DefineAccessorsForAttributeArguments,
"{0}",
FxCopDiagnosticCategory.Design,
......
......@@ -21,7 +21,6 @@ public abstract class CA1024DiagnosticAnalyzer : ICodeBlockStartedAnalyzer
{
internal const string RuleId = "CA1024";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.UsePropertiesWhereAppropriate,
FxCopRulesResources.ChangeToAPropertyIfAppropriate,
FxCopDiagnosticCategory.Design,
......
......@@ -15,7 +15,6 @@ public abstract class CA1060DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1060";
internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MovePInvokesToNativeMethodsClass,
FxCopRulesResources.MovePInvokesToNativeMethodsClass,
FxCopDiagnosticCategory.Design,
......
......@@ -34,14 +34,12 @@ public abstract class EnumWithFlagsDiagnosticAnalyzer : AbstractNamedTypeAnalyze
internal const string RuleNameForExportAttribute = "EnumWithFlagsAttributeRules";
internal static DiagnosticDescriptor Rule1027 = new DiagnosticDescriptor(RuleIdMarkEnumsWithFlags,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MarkEnumsWithFlags,
FxCopRulesResources.MarkEnumsWithFlagsMessage,
FxCopDiagnosticCategory.Design,
DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor Rule2217 = new DiagnosticDescriptor(RuleIdDoNotMarkEnumsWithFlags,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.DoNotMarkEnumsWithFlags,
FxCopRulesResources.DoNotMarkEnumsWithFlagsMessage,
FxCopDiagnosticCategory.Design,
......
......@@ -17,13 +17,11 @@ public class StaticTypeRulesDiagnosticAnalyzer : AbstractNamedTypeAnalyzer
internal const string CA1052RuleId = "CA1052";
internal const string CA1053RuleId = "CA1053";
internal static readonly DiagnosticDescriptor CA1052Rule = new DiagnosticDescriptor(CA1052RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.StaticHolderTypesShouldBeStaticOrNotInheritable,
FxCopRulesResources.StaticHolderTypeIsNotStatic,
FxCopDiagnosticCategory.Usage,
DiagnosticSeverity.Warning);
internal static readonly DiagnosticDescriptor CA1053Rule = new DiagnosticDescriptor(CA1053RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.StaticHolderTypesShouldNotHaveConstructors,
FxCopRulesResources.StaticHolderTypesShouldNotHaveConstructorsMessage,
FxCopDiagnosticCategory.Usage,
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FxCopAnalyzers
{
internal static class FxCopConstants
{
public const string DiagnosticKind = "FxCop";
}
}
......@@ -9,7 +9,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{ABD37A20-C734-4B09-91FE-BEC5DB82938A}</ProjectGuid>
<ProjectGuid>{90D2AB08-A2D4-4F77-BE9C-0476B7066BCB}</ProjectGuid>
<OutputType>Library</OutputType>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<FileUpgradeFlags></FileUpgradeFlags>
......@@ -104,7 +104,6 @@
<Compile Include="Design\EnumWithFlagsDiagnosticAnalyzer.cs" />
<Compile Include="Design\StaticTypeRulesDiagnosticAnalyzer.cs" />
<Compile Include="DiagnosticKind.cs" />
<Compile Include="FxCopConstants.cs" />
<Compile Include="FxCopDiagnosticCategory.cs" />
<Compile Include="FxCopRulesResources.Designer.cs">
<AutoGen>True</AutoGen>
......
......@@ -14,7 +14,6 @@ public abstract class CA1309DiagnosticAnalyzer : ICompilationStartedAnalyzer
{
internal const string RuleId = "CA1309";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.StringComparisonShouldBeOrdinalOrOrdinalIgnoreCase,
FxCopRulesResources.StringComparisonShouldBeOrdinalOrOrdinalIgnoreCase,
FxCopDiagnosticCategory.Globalization,
......
......@@ -18,13 +18,11 @@ public abstract class PInvokeDiagnosticAnalyzer : ICompilationStartedAnalyzer
public const string CA1401 = "CA1401";
public const string CA2101 = "CA2101";
internal static DiagnosticDescriptor RuleCA1401 = new DiagnosticDescriptor(CA1401,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.PInvokesShouldNotBeVisible,
FxCopRulesResources.PInvokeMethodShouldNotBeVisible,
FxCopDiagnosticCategory.Interoperability,
DiagnosticSeverity.Warning);
internal static DiagnosticDescriptor RuleCA2101 = new DiagnosticDescriptor(CA2101,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.SpecifyMarshalingForPInvokeStringArguments,
FxCopRulesResources.SpecifyMarshalingForPInvokeStringArguments,
FxCopDiagnosticCategory.Globalization,
......
......@@ -23,7 +23,6 @@ public class CA1708DiagnosticAnalyzer : AbstractNamedTypeAnalyzer, ICompilationS
internal const string Parameter = "Parameters of";
internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.IdentifiersShouldDifferByMoreThanCase,
FxCopRulesResources.IdentifierNamesShouldDifferMoreThanCase,
FxCopDiagnosticCategory.Naming,
......
......@@ -14,13 +14,11 @@ public class CA1715DiagnosticAnalyzer : ISymbolAnalyzer
{
internal const string RuleId = "CA1715";
internal static readonly DiagnosticDescriptor InterfaceRule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.InterfaceNamesShouldStartWithI,
FxCopRulesResources.InterfaceNamesShouldStartWithI,
FxCopDiagnosticCategory.Naming,
DiagnosticSeverity.Warning);
internal static readonly DiagnosticDescriptor TypeParameterRule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.TypeParameterNamesShouldStartWithT,
FxCopRulesResources.TypeParameterNamesShouldStartWithT,
FxCopDiagnosticCategory.Naming,
......
......@@ -17,7 +17,6 @@ public abstract class CA1813DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1813";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.AvoidUnsealedAttributes,
FxCopRulesResources.SealAttributeTypesForImprovedPerf,
FxCopDiagnosticCategory.Performance,
......
......@@ -15,7 +15,6 @@ public abstract class CA1821DiagnosticAnalyzer : ICodeBlockStartedAnalyzer
{
internal const string RuleId = "CA1821";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.RemoveEmptyFinalizers,
FxCopRulesResources.RemoveEmptyFinalizers,
FxCopDiagnosticCategory.Performance,
......
......@@ -25,7 +25,6 @@ public class CA2002DiagnosticAnalyzer : IDiagnosticAnalyzer
{
internal const string RuleId = "CA2002";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.DoNotLockOnObjectsWithWeakIdentity,
FxCopRulesResources.DoNotLockOnWeakIdentity,
FxCopDiagnosticCategory.Reliability,
......
......@@ -15,7 +15,6 @@ public abstract class CA1036DiagnosticAnalyzer : AbstractNamedTypeAnalyzer
{
internal const string RuleId = "CA1036";
internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.OverloadOperatorEqualsOnIComparableInterface,
FxCopRulesResources.OverloadOperatorEqualsOnIComparableInterface,
FxCopDiagnosticCategory.Usage,
......
......@@ -15,7 +15,6 @@ public abstract class CA2200DiagnosticAnalyzer : IDiagnosticAnalyzer
{
internal const string RuleId = "CA2200";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.RethrowToPreserveStackDetails,
FxCopRulesResources.RethrowException,
FxCopDiagnosticCategory.Usage,
......
......@@ -25,7 +25,6 @@ public abstract class CA2213DiagnosticAnalyzer : ICompilationStartedAnalyzer
internal const string RuleId = "CA2213";
internal const string Dispose = "Dispose";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.DisposableFieldsShouldBeDisposed,
FxCopRulesResources.DisposableFieldsShouldBeDisposed,
FxCopDiagnosticCategory.Usage,
......
......@@ -23,7 +23,6 @@ public abstract class CA2214DiagnosticAnalyzer : ICodeBlockStartedAnalyzer
{
internal const string RuleId = "CA2214";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.DoNotCallOverridableMethodsInConstructors,
FxCopRulesResources.DoNotCallOverridableMethodsInConstructors,
FxCopDiagnosticCategory.Usage,
......
......@@ -16,7 +16,6 @@ public abstract class CA2231DiagnosticAnalyzer : AbstractNamedTypeAnalyzer, ISym
{
internal const string RuleId = "CA2231";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.OverloadOperatorEqualsOnOverridingValueTypeEquals,
FxCopRulesResources.OverloadOperatorEqualsOnOverridingValueTypeEquals,
FxCopDiagnosticCategory.Usage,
......
......@@ -18,7 +18,6 @@ public abstract class SerializationRulesDiagnosticAnalyzer : ICompilationStarted
// Implement serialization constructors
internal const string RuleCA2229Id = "CA2229";
internal static DiagnosticDescriptor RuleCA2229 = new DiagnosticDescriptor(RuleCA2229Id,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.ImplementSerializationConstructor,
"{0}",
FxCopDiagnosticCategory.Usage,
......@@ -27,7 +26,6 @@ public abstract class SerializationRulesDiagnosticAnalyzer : ICompilationStarted
// Mark ISerializable types with SerializableAttribute
internal const string RuleCA2237Id = "CA2237";
internal static DiagnosticDescriptor RuleCA2237 = new DiagnosticDescriptor(RuleCA2237Id,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MarkISerializableTypesWithAttribute,
FxCopRulesResources.AddSerializableAttributeToType,
FxCopDiagnosticCategory.Usage,
......@@ -36,7 +34,6 @@ public abstract class SerializationRulesDiagnosticAnalyzer : ICompilationStarted
// Mark all non-serializable fields
internal const string RuleCA2235Id = "CA2235";
internal static DiagnosticDescriptor RuleCA2235 = new DiagnosticDescriptor(RuleCA2235Id,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.MarkAllNonSerializableFields,
FxCopRulesResources.FieldIsOfNonSerializableType,
FxCopDiagnosticCategory.Usage,
......
......@@ -40,7 +40,7 @@
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Core\FxCopRulesDiagnosticAnalyzers.csproj">
<Project>{ABD37A20-C734-4B09-91FE-BEC5DB82938A}</Project>
<Project>{90D2AB08-A2D4-4F77-BE9C-0476B7066BCB}</Project>
<Name>FxCopRulesDiagnosticAnalyzers</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
......
......@@ -163,7 +163,7 @@ static void Main(string[] args)
{
Id = AssemblyAttributesDiagnosticAnalyzer.CA1014RuleName,
Severity = DiagnosticSeverity.Warning,
Message = AssemblyAttributesDiagnosticAnalyzer.CA1014Rule.MessageTemplate
Message = AssemblyAttributesDiagnosticAnalyzer.CA1014Rule.MessageFormat
};
}
}
......@@ -26,12 +26,12 @@ protected override IDiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
private static DiagnosticResult CSharpResult(int line, int column)
{
return GetCSharpResultAt(line, column, CA1060DiagnosticAnalyzer.Rule.Id, CA1060DiagnosticAnalyzer.Rule.MessageTemplate);
return GetCSharpResultAt(line, column, CA1060DiagnosticAnalyzer.Rule.Id, CA1060DiagnosticAnalyzer.Rule.MessageFormat);
}
private static DiagnosticResult BasicResult(int line, int column)
{
return GetBasicResultAt(line, column, CA1060DiagnosticAnalyzer.Rule.Id, CA1060DiagnosticAnalyzer.Rule.MessageTemplate);
return GetBasicResultAt(line, column, CA1060DiagnosticAnalyzer.Rule.Id, CA1060DiagnosticAnalyzer.Rule.MessageFormat);
}
#endregion
......
......@@ -285,7 +285,7 @@ protected static void AnalyzeDocumentCore(IDiagnosticAnalyzer analyzer, Document
private static Diagnostic[] GetSortedNonCompilerDiagnostics(IEnumerable<Diagnostic> diagnostics)
{
return diagnostics.Where(d => d.Kind != "Compiler").OrderBy(d => d.Location.SourceSpan.Start).ToArray();
return diagnostics.Where(d => d.Category != "Compiler").OrderBy(d => d.Location.SourceSpan.Start).ToArray();
}
}
}
......@@ -54,9 +54,6 @@ private static void VerifyDiagnostics(IEnumerable<Diagnostic> actualResults, Dia
}
}
Assert.True(actual.Kind == FxCopConstants.DiagnosticKind,
string.Format("Expected diagnostic kind to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
FxCopConstants.DiagnosticKind, actual.Kind, actual));
Assert.True(actual.Id == expected.Id,
string.Format("Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
expected.Id, actual.Id, actual));
......
......@@ -66,7 +66,7 @@
<Name>Workspaces</Name>
</ProjectReference>
<ProjectReference Include="..\Core\FxCopRulesDiagnosticAnalyzers.csproj">
<Project>{ABD37A20-C734-4B09-91FE-BEC5DB82938A}</Project>
<Project>{90D2AB08-A2D4-4F77-BE9C-0476B7066BCB}</Project>
<Name>FxCopRulesDiagnosticAnalyzers</Name>
</ProjectReference>
<ProjectReference Include="..\CSharp\CSharpFxCopRulesDiagnosticAnalyzers.csproj">
......
......@@ -50,13 +50,11 @@ public class Class6<TTypeParameter>
#region "Test_Class"
internal const string RuleId = "CA1715_Test";
internal static readonly DiagnosticDescriptor InterfaceRule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.InterfaceNamesShouldStartWithI,
FxCopRulesResources.InterfaceNamesShouldStartWithI,
FxCopDiagnosticCategory.Naming,
DiagnosticSeverity.Warning);
internal static readonly DiagnosticDescriptor TypeParameterRule = new DiagnosticDescriptor(RuleId,
FxCopConstants.DiagnosticKind,
FxCopRulesResources.TypeParameterNamesShouldStartWithT,
FxCopRulesResources.TypeParameterNamesShouldStartWithT,
FxCopDiagnosticCategory.Naming,
......
......@@ -31,7 +31,7 @@
<Name>BasicCodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\Core\FxCopRulesDiagnosticAnalyzers.csproj">
<Project>{ABD37A20-C734-4B09-91FE-BEC5DB82938A}</Project>
<Project>{90D2AB08-A2D4-4F77-BE9C-0476B7066BCB}</Project>
<Name>FxCopRulesDiagnosticAnalyzers</Name>
</ProjectReference>
<ProjectReference Include="..\..\Workspaces\Core\Workspaces.csproj">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册