diff --git a/src/Agoda.Analyzers.Test/AllAnalyzersUnitTests.cs b/src/Agoda.Analyzers.Test/AllAnalyzersUnitTests.cs index 932a232..3735c98 100644 --- a/src/Agoda.Analyzers.Test/AllAnalyzersUnitTests.cs +++ b/src/Agoda.Analyzers.Test/AllAnalyzersUnitTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Reflection; using Agoda.Analyzers.Helpers; @@ -44,14 +45,14 @@ private static IEnumerable GetAnalyzerTestCases() } [TestCaseSource(nameof(GetAnalyzerTestCases))] - public void Analyzer_Should_Have_Required_Properties_For_Diagnostic_Create(Type analyzerType) + public void Analyzer_Should_Pass_Properties_To_Diagnostic_Create(Type analyzerType) { var methods = analyzerType.GetMethods(BindingFlags.Instance | - BindingFlags.NonPublic | - BindingFlags.Public | - BindingFlags.DeclaredOnly | - BindingFlags.Static | - BindingFlags.FlattenHierarchy); + BindingFlags.NonPublic | + BindingFlags.Public | + BindingFlags.DeclaredOnly | + BindingFlags.Static | + BindingFlags.FlattenHierarchy); var violations = new List(); @@ -59,35 +60,12 @@ public void Analyzer_Should_Have_Required_Properties_For_Diagnostic_Create(Type { try { - // Get the IL bytes of the method - var methodBody = method.GetMethodBody(); - if (methodBody == null) continue; - - var instructions = methodBody.GetILAsByteArray(); - if (instructions == null) continue; - - // Check if the method contains a call to Diagnostic.Create - if (ContainsDiagnosticCreate(method)) + foreach (var diagnosticCreateCall in FindDiagnosticCreateCalls(method)) { - // Create instance of analyzer to check properties - var analyzer = Activator.CreateInstance(analyzerType); - - // Get the Properties dictionary/field - var propertiesInfo = analyzerType.GetProperty("Properties", - BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - - propertiesInfo.ShouldNotBeNull($"Analyzer uses Diagnostic.Create in method {method.Name} " + - "but doesn't have a Properties property"); - - var properties = propertiesInfo.GetValue(analyzer) as IDictionary; - - properties.ShouldNotBeNull($"Properties is null or not a dictionary"); - - properties.ContainsKey(AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES) - .ShouldBeTrue($"Method {method.Name} doesn't contain required '{AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES}' property When calling Diagnostic.Create"); - - properties["MyKey"].ShouldNotBeNullOrWhiteSpace( - $"MyKey property in method {method.Name} should have a value"); + if (!diagnosticCreateCall.HasPropertiesParameter) + { + violations.Add($"Method {method.Name} in {analyzerType.Name} calls Diagnostic.Create without properties parameter"); + } } } catch (Exception ex) @@ -99,21 +77,24 @@ public void Analyzer_Should_Have_Required_Properties_For_Diagnostic_Create(Type violations.ShouldBeEmpty(); } - private bool ContainsDiagnosticCreate(MethodInfo method) + private class DiagnosticCreateCall + { + public bool HasPropertiesParameter { get; set; } + public int ParameterCount { get; set; } + } + + private IEnumerable FindDiagnosticCreateCalls(MethodInfo method) { + var calls = new List(); try { - // Get all method calls within the method var body = method.GetMethodBody(); - if (body == null) return false; + if (body == null) return calls; - // Decompile IL to find calls to Diagnostic.Create var instructions = body.GetILAsByteArray(); - if (instructions == null) return false; + if (instructions == null) return calls; - // Get all method calls from the IL var moduleHandle = method.Module.ModuleHandle; - var methodCalls = new List(); for (int i = 0; i < instructions.Length; i++) { @@ -129,7 +110,18 @@ private bool ContainsDiagnosticCreate(MethodInfo method) if (calledMethod?.DeclaringType?.FullName == "Microsoft.CodeAnalysis.Diagnostic" && calledMethod.Name == "Create") { - return true; + var parameters = calledMethod.GetParameters(); + var hasPropertiesParam = parameters.Any(p => + p.ParameterType.IsGenericType && + p.ParameterType.GetGenericTypeDefinition() == typeof(ImmutableDictionary<,>) && + p.ParameterType.GetGenericArguments()[0] == typeof(string) && + p.ParameterType.GetGenericArguments()[1] == typeof(string)); + + calls.Add(new DiagnosticCreateCall + { + HasPropertiesParameter = hasPropertiesParam, + ParameterCount = parameters.Length + }); } } catch @@ -142,10 +134,9 @@ private bool ContainsDiagnosticCreate(MethodInfo method) } catch { - // If we can't analyze the method, assume it might contain Diagnostic.Create - return true; + // If we can't analyze the method, we'll skip it } - return false; + return calls; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0001DependencyResolverMustNotBeUsed.cs b/src/Agoda.Analyzers/AgodaCustom/AG0001DependencyResolverMustNotBeUsed.cs index cd24096..d3e30c5 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0001DependencyResolverMustNotBeUsed.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0001DependencyResolverMustNotBeUsed.cs @@ -14,7 +14,7 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0001DependencyResolverMustNotBeUsed : PropertyInvocationAnalyzerBase { internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; + { { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } }; public const string DIAGNOSTIC_ID = "AG0001"; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0002PrivateMethodsShouldNotBeTested.cs b/src/Agoda.Analyzers/AgodaCustom/AG0002PrivateMethodsShouldNotBeTested.cs index 33cf8e2..5d16df3 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0002PrivateMethodsShouldNotBeTested.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0002PrivateMethodsShouldNotBeTested.cs @@ -1,4 +1,5 @@ -using Agoda.Analyzers.Helpers; +using System.Collections.Generic; +using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -71,7 +72,12 @@ So right not not possible to filter out unreferenced errors in the specific proj //var references = SymbolFinder.FindReferencesAsync(methodSymbol, null).Result; //if (references.Count() > 1) - context.ReportDiagnostic(Diagnostic.Create(Rule, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Rule, context.Node.GetLocation(),properties: _props.ToImmutableDictionary())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } -} \ No newline at end of file +} diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0003HttpContextCannotBePassedAsMethodArgument.cs b/src/Agoda.Analyzers/AgodaCustom/AG0003HttpContextCannotBePassedAsMethodArgument.cs index 319999e..75e0ca7 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0003HttpContextCannotBePassedAsMethodArgument.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0003HttpContextCannotBePassedAsMethodArgument.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using System; +using System.Collections.Generic; using System.Collections.Immutable; namespace Agoda.Analyzers.AgodaCustom @@ -60,11 +61,14 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) if (context.SemanticModel.GetTypeInfo(simpleType).Type.ToDisplayString() == "Microsoft.AspNetCore.Http.HttpContext") { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } } - - + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; + } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0004DoNotUseHardCodedStringsToIdentifyTypes.cs b/src/Agoda.Analyzers/AgodaCustom/AG0004DoNotUseHardCodedStringsToIdentifyTypes.cs index 0bba77a..011af20 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0004DoNotUseHardCodedStringsToIdentifyTypes.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0004DoNotUseHardCodedStringsToIdentifyTypes.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; using Agoda.Analyzers.Helpers; +using System.Collections.Generic; namespace Agoda.Analyzers.AgodaCustom { @@ -59,7 +60,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) // Type.GetType("") - this method is completely banned as all its overloads take types as strings if (!GetTypeRule.Verify(methodSymbol)) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); return; } @@ -78,8 +79,12 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) if (firstParameter.Type.Name.ToLower() == "string") { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0005TestMethodNamesMustFollowConvention.cs b/src/Agoda.Analyzers/AgodaCustom/AG0005TestMethodNamesMustFollowConvention.cs index ac78a28..3e5f643 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0005TestMethodNamesMustFollowConvention.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0005TestMethodNamesMustFollowConvention.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; using Agoda.Analyzers.Helpers; +using System.Collections.Generic; namespace Agoda.Analyzers.AgodaCustom { @@ -69,7 +70,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) // report error at position of method name var methodNameToken = methodDeclaration.ChildTokens().First(t => t.IsKind(SyntaxKind.IdentifierToken)); - context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodNameToken.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodNameToken.GetLocation(), properties: _props.ToImmutableDictionary())); } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0006RegisteredComponentShouldHaveExactlyOnePublicConstructor.cs b/src/Agoda.Analyzers/AgodaCustom/AG0006RegisteredComponentShouldHaveExactlyOnePublicConstructor.cs index 2c87790..d487d52 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0006RegisteredComponentShouldHaveExactlyOnePublicConstructor.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0006RegisteredComponentShouldHaveExactlyOnePublicConstructor.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text.RegularExpressions; using Agoda.Analyzers.Helpers; @@ -74,7 +75,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) if (publicConstructorsCount == 1) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, classDeclaration.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, classDeclaration.GetLocation(), properties: _props.ToImmutableDictionary())); } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0009IHttpContextAccessorCannotBePassedAsMethodArgument.cs b/src/Agoda.Analyzers/AgodaCustom/AG0009IHttpContextAccessorCannotBePassedAsMethodArgument.cs index d8a7efc..4e613da 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0009IHttpContextAccessorCannotBePassedAsMethodArgument.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0009IHttpContextAccessorCannotBePassedAsMethodArgument.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -45,7 +46,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) if ("Microsoft.AspNetCore.Http.IHttpContextAccessor" == paramTypeName || "Microsoft.AspNetCore.Http.HttpContextAccessor" == paramTypeName) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } } @@ -57,5 +58,9 @@ public override void Initialize(AnalysisContext context) context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.Parameter); } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0010PreventTestFixtureInheritance.cs b/src/Agoda.Analyzers/AgodaCustom/AG0010PreventTestFixtureInheritance.cs index e5eb25a..fa55de5 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0010PreventTestFixtureInheritance.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0010PreventTestFixtureInheritance.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; using Agoda.Analyzers.Helpers; +using System.Collections.Generic; namespace Agoda.Analyzers.AgodaCustom { @@ -58,7 +59,11 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) .Any(x => TestMethodHelpers.IsTestCase(x, context)); if (!hasTestMethod) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, classDeclaration.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, classDeclaration.GetLocation(), properties: _props.ToImmutableDictionary())); } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0011NoDirectQueryStringAccess.cs b/src/Agoda.Analyzers/AgodaCustom/AG0011NoDirectQueryStringAccess.cs index bcb808d..793d60c 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0011NoDirectQueryStringAccess.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0011NoDirectQueryStringAccess.cs @@ -14,26 +14,26 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0011NoDirectQueryStringAccess : PropertyInvocationAnalyzerBase { public const string DIAGNOSTIC_ID = "AG0011"; - + private static readonly LocalizableString Title = new LocalizableResourceString( - nameof(CustomRulesResources.AG0011Title), - CustomRulesResources.ResourceManager, + nameof(CustomRulesResources.AG0011Title), + CustomRulesResources.ResourceManager, typeof(CustomRulesResources)); - + private static readonly LocalizableString MessageFormat = new LocalizableResourceString( - nameof(CustomRulesResources.AG0011Title), - CustomRulesResources.ResourceManager, + nameof(CustomRulesResources.AG0011Title), + CustomRulesResources.ResourceManager, typeof(CustomRulesResources)); - + protected override DiagnosticDescriptor Descriptor => new DiagnosticDescriptor( - DIAGNOSTIC_ID, - Title, - MessageFormat, + DIAGNOSTIC_ID, + Title, + MessageFormat, AnalyzerCategory.CustomQualityRules, - DiagnosticSeverity.Error, - AnalyzerConstants.EnabledByDefault, + DiagnosticSeverity.Error, + AnalyzerConstants.EnabledByDefault, DescriptionContentLoader.GetAnalyzerDescription(nameof(AG0011NoDirectQueryStringAccess)), - "https://agoda-com.github.io/standards-c-sharp/services/framework-abstractions.html", + "https://agoda-com.github.io/standards-c-sharp/services/framework-abstractions.html", WellKnownDiagnosticTags.EditAndContinue); protected override IEnumerable Rules => new[] @@ -42,6 +42,8 @@ public class AG0011NoDirectQueryStringAccess : PropertyInvocationAnalyzerBase }; internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; - } + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; +} } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0012TestMethodMustContainAtLeastOneAssertion.cs b/src/Agoda.Analyzers/AgodaCustom/AG0012TestMethodMustContainAtLeastOneAssertion.cs index 2514e32..9ae1f00 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0012TestMethodMustContainAtLeastOneAssertion.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0012TestMethodMustContainAtLeastOneAssertion.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Net; @@ -67,7 +68,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) return; } - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } private static bool HasInvokedAssertStaticMethod(MethodDeclarationSyntax methodDeclaration, SyntaxNodeAnalysisContext context) @@ -128,5 +129,9 @@ public AssertLibraryInfo(string namespaceTitle, string module, string name, stri HasExtenstionMethods = type != null; } } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0013LimitNumberOfTestMethodParametersTo5.cs b/src/Agoda.Analyzers/AgodaCustom/AG0013LimitNumberOfTestMethodParametersTo5.cs index cef738a..d327b40 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0013LimitNumberOfTestMethodParametersTo5.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0013LimitNumberOfTestMethodParametersTo5.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; namespace Agoda.Analyzers.AgodaCustom { @@ -53,9 +54,14 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) if(!IsTestPrametersMoreThanLimit(methodDeclaration)) { return; } - context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, methodDeclaration.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, methodDeclaration.GetLocation(),_props.ToImmutableDictionary())); } private bool IsTestPrametersMoreThanLimit(MethodDeclarationSyntax method) => (method.ParameterList?.Parameters.Count ?? 0) > MAXIMUM_TEST_PARAMETERS; + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0018PermitOnlyCertainPubliclyExposedEnumerables.cs b/src/Agoda.Analyzers/AgodaCustom/AG0018PermitOnlyCertainPubliclyExposedEnumerables.cs index a532b59..3256c63 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0018PermitOnlyCertainPubliclyExposedEnumerables.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0018PermitOnlyCertainPubliclyExposedEnumerables.cs @@ -64,7 +64,7 @@ public override void Initialize(AnalysisContext context) private static void Analyze(SyntaxNodeAnalysisContext context) { if (context.ContainingSymbol.DeclaredAccessibility != Accessibility.Public || IsPubliclyExposedIEnumerableTypes(context.ContainingSymbol)) { return; } - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } private static bool IsPubliclyExposedIEnumerableTypes(ISymbol symbol) @@ -113,5 +113,10 @@ private static bool IsPubliclyExposedIEnumerableTypes(ISymbol symbol) return true; } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0019PreventUseOfInternalsVisibleToAttribute.cs b/src/Agoda.Analyzers/AgodaCustom/AG0019PreventUseOfInternalsVisibleToAttribute.cs index 872900d..50fd877 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0019PreventUseOfInternalsVisibleToAttribute.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0019PreventUseOfInternalsVisibleToAttribute.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; +using System.Collections.Generic; using System.Collections.Immutable; namespace Agoda.Analyzers.AgodaCustom @@ -51,9 +52,14 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { if (attribute.Name is IdentifierNameSyntax name && name.Identifier.Text == "InternalsVisibleTo") { - context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, attribute.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, attribute.GetLocation(),properties: _props.ToImmutableDictionary())); } } } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerables.cs b/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerables.cs index 7ec69c2..2319f58 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerables.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerables.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -93,10 +94,14 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) && methodReturnType.ConstructedFrom.Interfaces.Any(x => x.ToDisplayString() == "System.Collections.IEnumerable") && methodReturnType.ConstructedFrom.ToDisplayString() != "string")) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, location)); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, properties: _props.ToImmutableDictionary())); } } } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerablesFixProvider.cs b/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerablesFixProvider.cs index d589c55..3c91ff8 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerablesFixProvider.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0020AvoidReturningNullEnumerablesFixProvider.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Composition; using System.Linq; using System.Threading; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0021PreferAsyncMethods.cs b/src/Agoda.Analyzers/AgodaCustom/AG0021PreferAsyncMethods.cs index 1aed8f7..ab9f761 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0021PreferAsyncMethods.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0021PreferAsyncMethods.cs @@ -67,7 +67,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) if (alternativeAsyncMethods.Any()) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } } @@ -180,5 +180,9 @@ private struct MethodDescriptor /// public ITypeSymbol CallingType { get; set; } } + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0022DoNotExposeBothSyncAndAsyncVersionsOfMethods.cs b/src/Agoda.Analyzers/AgodaCustom/AG0022DoNotExposeBothSyncAndAsyncVersionsOfMethods.cs index 1ce211a..a9a4cb2 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0022DoNotExposeBothSyncAndAsyncVersionsOfMethods.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0022DoNotExposeBothSyncAndAsyncVersionsOfMethods.cs @@ -87,10 +87,14 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodSyntax); if (!AsyncHelpers.IsAsyncIntent(methodSymbol)) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodSyntax.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodSyntax.GetLocation(), properties: _props.ToImmutableDictionary())); } } - - } + } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0022RemoveSyncMethodFixProvider.cs b/src/Agoda.Analyzers/AgodaCustom/AG0022RemoveSyncMethodFixProvider.cs index ee0a0a0..780d16b 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0022RemoveSyncMethodFixProvider.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0022RemoveSyncMethodFixProvider.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Composition; using System.Threading; using System.Threading.Tasks; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0024PreventUseOfTaskFactoryStartNew.cs b/src/Agoda.Analyzers/AgodaCustom/AG0024PreventUseOfTaskFactoryStartNew.cs index 5d0967c..b1c7c6b 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0024PreventUseOfTaskFactoryStartNew.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0024PreventUseOfTaskFactoryStartNew.cs @@ -68,8 +68,13 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) ); if (isLongRunning) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0027EnsureOnlyDataSeleniumIsUsedToFindElements.cs b/src/Agoda.Analyzers/AgodaCustom/AG0027EnsureOnlyDataSeleniumIsUsedToFindElements.cs index 63012a7..fa6855a 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0027EnsureOnlyDataSeleniumIsUsedToFindElements.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0027EnsureOnlyDataSeleniumIsUsedToFindElements.cs @@ -63,7 +63,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) var firstArgument = invocationExpressionSyntax.ArgumentList.Arguments.FirstOrDefault(); if (firstArgument?.Expression is LiteralExpressionSyntax && !MatchDataSelenium.IsMatch(firstArgument.ToString())) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation(), properties: _props.ToImmutableDictionary())); } if (!(firstArgument?.Expression is IdentifierNameSyntax)) @@ -75,8 +75,13 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) var constantValue = context.SemanticModel.GetConstantValue(firstArgument.Expression); if (constantValue.HasValue && !MatchDataSelenium.IsMatch($@"""{constantValue.Value}""")) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation(), properties: _props.ToImmutableDictionary())); } } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0030PreventUseOfDynamics.cs b/src/Agoda.Analyzers/AgodaCustom/AG0030PreventUseOfDynamics.cs index 1cb05a1..693e71d 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0030PreventUseOfDynamics.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0030PreventUseOfDynamics.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -52,21 +53,21 @@ private void AnalyzeVariableDeclaration(SyntaxNodeAnalysisContext context) { var variableDeclaration = (VariableDeclarationSyntax)context.Node; if (ValidateReturnType(variableDeclaration.Type)) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, variableDeclaration.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, variableDeclaration.GetLocation(), properties: _props.ToImmutableDictionary())); } private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context) { var methodDeclaration = (MethodDeclarationSyntax)context.Node; if (ValidateReturnType(methodDeclaration.ReturnType)) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodDeclaration.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodDeclaration.GetLocation(), properties: _props.ToImmutableDictionary())); } private void AnalyzeGenericName(SyntaxNodeAnalysisContext context) { var genericName = (GenericNameSyntax)context.Node; if (ValidateGenericType(genericName)) return; - context.ReportDiagnostic(Diagnostic.Create(Descriptor, genericName.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, genericName.GetLocation(), properties: _props.ToImmutableDictionary())); } private bool ValidateReturnType(TypeSyntax returnTypeSyntax) @@ -79,5 +80,10 @@ private bool ValidateGenericType(GenericNameSyntax genericName) { return genericName.TypeArgumentList.Arguments.All(argument => argument.GetText().ToString() != "dynamic"); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "30" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0032PreventUseOfBlockingTaskMethods.cs b/src/Agoda.Analyzers/AgodaCustom/AG0032PreventUseOfBlockingTaskMethods.cs index 504ba14..440b936 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0032PreventUseOfBlockingTaskMethods.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0032PreventUseOfBlockingTaskMethods.cs @@ -14,7 +14,7 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0032PreventUseOfBlockingTaskMethods : PropertyInvocationAnalyzerBase { internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; + { { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } }; public const string DIAGNOSTIC_ID = "AG0032"; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0033PreventUseOfTaskResult.cs b/src/Agoda.Analyzers/AgodaCustom/AG0033PreventUseOfTaskResult.cs index c76fe2d..97a7330 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0033PreventUseOfTaskResult.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0033PreventUseOfTaskResult.cs @@ -14,7 +14,7 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0033PreventUseOfTaskResult : PropertyInvocationAnalyzerBase { internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; + { { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } }; public const string DIAGNOSTIC_ID = "AG0033"; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0035PreventUseOfMachineName.cs b/src/Agoda.Analyzers/AgodaCustom/AG0035PreventUseOfMachineName.cs index 5994a54..6c38230 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0035PreventUseOfMachineName.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0035PreventUseOfMachineName.cs @@ -9,7 +9,7 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0035PreventUseOfMachineName : PropertyInvocationAnalyzerBase { internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; + { { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } }; public const string DIAGNOSTIC_ID = "AG0035"; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0037EnsureSeleniumTestHasOwnedByAttribute.cs b/src/Agoda.Analyzers/AgodaCustom/AG0037EnsureSeleniumTestHasOwnedByAttribute.cs index b8e4930..2856fa5 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0037EnsureSeleniumTestHasOwnedByAttribute.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0037EnsureSeleniumTestHasOwnedByAttribute.cs @@ -88,7 +88,12 @@ private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context) return; } - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0038PreventUseOfRegionPreprocessorDirective.cs b/src/Agoda.Analyzers/AgodaCustom/AG0038PreventUseOfRegionPreprocessorDirective.cs index 8254ed7..3e15b85 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0038PreventUseOfRegionPreprocessorDirective.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0038PreventUseOfRegionPreprocessorDirective.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using System; +using System.Collections.Generic; using System.Collections.Immutable; namespace Agoda.Analyzers.AgodaCustom @@ -50,7 +51,12 @@ public override void Initialize(AnalysisContext context) private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation(), properties: _props.ToImmutableDictionary())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0039MethodLineLengthAnalyzer.cs b/src/Agoda.Analyzers/AgodaCustom/AG0039MethodLineLengthAnalyzer.cs index 1ecb9ec..e9f5df6 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0039MethodLineLengthAnalyzer.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0039MethodLineLengthAnalyzer.cs @@ -71,7 +71,7 @@ private void AnalyzeMethod(SyntaxNodeAnalysisContext context) if (lineCount <= MaxLines) return; - var diagnostic = Diagnostic.Create(Descriptor, methodNode.Identifier.GetLocation(), methodNode.Identifier.Text, lineCount, MaxLines); + var diagnostic = Diagnostic.Create(Descriptor, methodNode.Identifier.GetLocation(), properties: _props.ToImmutableDictionary(), methodNode.Identifier.Text, lineCount, MaxLines); context.ReportDiagnostic(diagnostic); } @@ -79,5 +79,10 @@ private static int GetNonEmptyLineCount(IEnumerable lines) { return lines.Count(line => !string.IsNullOrWhiteSpace(line.ToString())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0040WaitUntilStateNetworkIdleMustNotBeUsed.cs b/src/Agoda.Analyzers/AgodaCustom/AG0040WaitUntilStateNetworkIdleMustNotBeUsed.cs index 2155250..46edcdc 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0040WaitUntilStateNetworkIdleMustNotBeUsed.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0040WaitUntilStateNetworkIdleMustNotBeUsed.cs @@ -9,7 +9,7 @@ namespace Agoda.Analyzers.AgodaCustom public class AG0040WaitUntilStateNetworkIdleMustNotBeUsed : PropertyInvocationAnalyzerBase { internal override Dictionary Properties => new Dictionary() - { { Const.KEY_TECH_DEBT_IN_MINUTES, "10" } }; + { { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } }; public const string DIAGNOSTIC_ID = "AG0040"; diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0041LogTemplateAnalyzer.cs b/src/Agoda.Analyzers/AgodaCustom/AG0041LogTemplateAnalyzer.cs index 540a672..4f665f5 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0041LogTemplateAnalyzer.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0041LogTemplateAnalyzer.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -47,7 +48,7 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) if (argument.Expression.IsKind(SyntaxKind.InterpolatedStringExpression) || ContainsStringConcatenation(argument.Expression)) { - var diagnostic = Diagnostic.Create(Rule, argument.GetLocation()); + var diagnostic = Diagnostic.Create(Rule, argument.GetLocation(), properties: _props.ToImmutableDictionary()); context.ReportDiagnostic(diagnostic); } } @@ -86,5 +87,10 @@ private static bool ContainsStringConcatenation(ExpressionSyntax expression) (bes.Left.IsKind(SyntaxKind.StringLiteralExpression) || bes.Right.IsKind(SyntaxKind.StringLiteralExpression))); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0042ElementHandlerShouldNotBeUsed.cs b/src/Agoda.Analyzers/AgodaCustom/AG0042ElementHandlerShouldNotBeUsed.cs index 38912e4..d6ac217 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0042ElementHandlerShouldNotBeUsed.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0042ElementHandlerShouldNotBeUsed.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Collections.Immutable; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -70,7 +71,7 @@ private static void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) var returnType = methodSymbol.ReturnType; if (!IsElementHandleReturnType(returnType)) return; - var diagnostic = Diagnostic.Create(Descriptor, invocationExpression.GetLocation()); + var diagnostic = Diagnostic.Create(Descriptor, invocationExpression.GetLocation(), properties: _props.ToImmutableDictionary()); context.ReportDiagnostic(diagnostic); } @@ -130,5 +131,10 @@ private static bool IsPlaywrightPageOrElementType(INamedTypeSymbol typeSymbol) typeName == "Microsoft.Playwright.IElementHandle" || typeName == "Microsoft.Playwright.ElementHandle"; } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0043NoBuildServiceProvider.cs b/src/Agoda.Analyzers/AgodaCustom/AG0043NoBuildServiceProvider.cs index 8653f89..152a414 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0043NoBuildServiceProvider.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0043NoBuildServiceProvider.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Agoda.Analyzers.Helpers; @@ -86,9 +87,14 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context) if (isServiceCollectionExtension || isExpressionServiceCollection) { - var diagnostic = Diagnostic.Create(Descriptor, memberAccessExpr.Name.GetLocation()); + var diagnostic = Diagnostic.Create(Descriptor, memberAccessExpr.Name.GetLocation(), properties: _props.ToImmutableDictionary()); context.ReportDiagnostic(diagnostic); } } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/AgodaCustom/AG0044ForceOptionShouldNotBeUsed.cs b/src/Agoda.Analyzers/AgodaCustom/AG0044ForceOptionShouldNotBeUsed.cs index b73ff06..a1dc3f8 100644 --- a/src/Agoda.Analyzers/AgodaCustom/AG0044ForceOptionShouldNotBeUsed.cs +++ b/src/Agoda.Analyzers/AgodaCustom/AG0044ForceOptionShouldNotBeUsed.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -70,7 +71,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) if (!(assignment.Right is LiteralExpressionSyntax literal) || literal.Token.ValueText != "true") continue; - var diagnostic = Diagnostic.Create(Rule, expression.GetLocation()); + var diagnostic = Diagnostic.Create(Rule, expression.GetLocation(), properties: _props.ToImmutableDictionary()); context.ReportDiagnostic(diagnostic); } } @@ -87,5 +88,10 @@ private static bool IsLocatorOptionsType(string typeName) typeName.Contains("LocatorUncheck") || typeName.Contains("LocatorSelectOption")); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "60" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/StyleCop/SA1106CodeMustNotContainEmptyStatements.cs b/src/Agoda.Analyzers/StyleCop/SA1106CodeMustNotContainEmptyStatements.cs index ab8aef9..45318f2 100644 --- a/src/Agoda.Analyzers/StyleCop/SA1106CodeMustNotContainEmptyStatements.cs +++ b/src/Agoda.Analyzers/StyleCop/SA1106CodeMustNotContainEmptyStatements.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -57,7 +58,7 @@ private static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context) if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken)) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation(), properties: _props.ToImmutableDictionary())); } } @@ -67,7 +68,7 @@ private static void HandleNamespaceDeclaration(SyntaxNodeAnalysisContext context if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken)) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation(), properties: _props.ToImmutableDictionary())); } } @@ -101,7 +102,12 @@ private static void HandleEmptyStatement(SyntaxNodeAnalysisContext context) } // Code must not contain empty statements - context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.GetLocation(), properties: _props.ToImmutableDictionary())); } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/StyleCop/SA1107CodeMustNotContainMultipleStatementsOnOneLine.cs b/src/Agoda.Analyzers/StyleCop/SA1107CodeMustNotContainMultipleStatementsOnOneLine.cs index 63b87c1..a7fc783 100644 --- a/src/Agoda.Analyzers/StyleCop/SA1107CodeMustNotContainMultipleStatementsOnOneLine.cs +++ b/src/Agoda.Analyzers/StyleCop/SA1107CodeMustNotContainMultipleStatementsOnOneLine.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using Agoda.Analyzers.Helpers; using Microsoft.CodeAnalysis; @@ -67,7 +68,7 @@ private static void HandleBlock(SyntaxNodeAnalysisContext context) == currentStatementLocation.StartLinePosition.Line && !IsLastTokenMissing(previousStatement)) { - context.ReportDiagnostic(Diagnostic.Create(Descriptor, block.Statements[i].GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, block.Statements[i].GetLocation(), properties: _props.ToImmutableDictionary())); } previousStatementLocation = currentStatementLocation; @@ -80,5 +81,10 @@ private static bool IsLastTokenMissing(StatementSyntax previousStatement) { return previousStatement.GetLastToken(includeZeroWidth: true, includeSkipped: true).IsMissing; } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file diff --git a/src/Agoda.Analyzers/StyleCop/SA1123DoNotPlaceRegionsWithinElements.cs b/src/Agoda.Analyzers/StyleCop/SA1123DoNotPlaceRegionsWithinElements.cs index e6d1a54..bb4e391 100644 --- a/src/Agoda.Analyzers/StyleCop/SA1123DoNotPlaceRegionsWithinElements.cs +++ b/src/Agoda.Analyzers/StyleCop/SA1123DoNotPlaceRegionsWithinElements.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis; @@ -94,8 +95,13 @@ private static void HandleRegionDirectiveTrivia(SyntaxNodeAnalysisContext contex if (IsCompletelyContainedInBody(regionSyntax)) { // Region must not be located within a code element. - context.ReportDiagnostic(Diagnostic.Create(Descriptor, regionSyntax.GetLocation())); + context.ReportDiagnostic(Diagnostic.Create(Descriptor, regionSyntax.GetLocation(), properties: _props.ToImmutableDictionary())); } } + + private static Dictionary _props = new Dictionary() + { + { AnalyzerConstants.KEY_TECH_DEBT_IN_MINUTES, "10" } + }; } } \ No newline at end of file