private Diagnostic Analyze(MemberAccessExpressionSyntax methodCall, SemanticModel semanticModel) { var methodName = methodCall.GetName(); switch (methodName) { case Constants.ILog.DebugFormat: case Constants.ILog.InfoFormat: case Constants.ILog.WarnFormat: case Constants.ILog.ErrorFormat: case Constants.ILog.FatalFormat: { // check for correct type (only ILog methods shall be reported) var type = methodCall.GetTypeSymbol(semanticModel); if (type.Name != Constants.ILog.TypeName) { return(null); } var enclosingMethod = methodCall.GetEnclosingMethod(semanticModel); return(Issue(enclosingMethod.Name, methodCall.Name, methodName, methodName.Without(Format))); } default: return(null); } }
private static bool IsConditionMatcher(MemberAccessExpressionSyntax node) { if (node.Expression is IdentifierNameSyntax invokedType && invokedType.GetName() == "It") { switch (node.GetName()) { case "Is": case "IsAny": case "IsIn": case "IsInRange": case "IsNotIn": case "IsNotNull": case "IsRegex": return(true); } } return(false); }
private Diagnostic Analyze(MemberAccessExpressionSyntax methodCall, SemanticModel semanticModel) { var methodName = methodCall.GetName(); switch (methodName) { case Constants.ILog.Debug: case Constants.ILog.DebugFormat: { // check if inside IsDebugEnabled call for if or block if (methodCall.IsInsideIfStatementWithCallTo(Constants.ILog.IsDebugEnabled)) { return(null); } // check for correct type (only ILog methods shall be reported) var type = methodCall.GetTypeSymbol(semanticModel); if (type.Name != Constants.ILog.TypeName) { // skip it as it's no matching type return(null); } if (type.GetMembers(Constants.ILog.IsDebugEnabled).None()) { // skip it as it has no matching method return(null); } var enclosingMethod = methodCall.GetEnclosingMethod(semanticModel); return(Issue(enclosingMethod.Name, methodCall.Parent, methodName, Constants.ILog.IsDebugEnabled)); } default: { return(null); } } }
private static bool NodeHasIssue(MemberAccessExpressionSyntax node, SemanticModel semanticModel) { if (node.GetName() != "WaitOne") { return(false); } if (node.Parent is InvocationExpressionSyntax i) { foreach (var argument in i.ArgumentList.Arguments) { var argumentType = argument.GetTypeSymbol(semanticModel); if (argumentType.SpecialType == SpecialType.System_Int32 || argumentType.FullyQualifiedName() == TypeNames.TimeSpan) { // we use a timeout parameter (int or TimeSpan) return(false); } } } return(true); }
private static ExpressionSyntax UpdatedSyntax(string typeName, MemberAccessExpressionSyntax syntax, SeparatedSyntaxList <ArgumentSyntax> args) { var methodName = syntax.GetName(); switch (methodName) { case "AllItemsAreNotNull": return(FixAllItemsAreNotNull(args)); case "AllItemsAreUnique": return(FixAllItemsAreUnique(args)); case "AreEqual": return(FixAreEqual(args)); case "AreEqualIgnoringCase": return(FixAreEqualIgnoringCase(args)); case "AreEquivalent": return(FixAreEquivalent(args)); case "AreNotEqual": return(FixAreNotEqual(args)); case "AreNotEquivalent": return(FixAreNotEquivalent(args)); case "AreNotSame": return(FixAreNotSame(args)); case "AreSame": return(FixAreSame(args)); case "Contains": return(FixContains(typeName, args)); case "DoesNotContain": return(FixDoesNotContain(typeName, args)); case "DoesNotEndWith": return(FixDoesNotEndWith(args)); case "DoesNotStartWith": return(FixDoesNotStartWith(args)); case "EndsWith": return(FixEndsWith(args)); case "False": return(FixIsFalse(args)); case "Greater": return(FixGreater(args)); case "GreaterOrEqual": return(FixGreaterOrEqual(args)); case "IsEmpty": return(FixIsEmpty(args)); case "IsFalse": return(FixIsFalse(args)); case "IsInstanceOf": return(FixIsInstanceOf(args, syntax.Name)); case "IsNaN": return(FixIsNaN(args)); case "IsNotEmpty": return(FixIsNotEmpty(args)); case "IsNotNull": return(FixIsNotNull(args)); case "IsNotSubsetOf": return(FixIsNotSubsetOf(args)); case "IsNotSupersetOf": return(FixIsNotSupersetOf(args)); case "IsNull": return(FixIsNull(args)); case "IsNullOrEmpty": return(FixIsNullOrEmpty(args)); case "IsOrdered": return(FixIsOrdered(args)); case "IsSubsetOf": return(FixIsSubsetOf(args)); case "IsSupersetOf": return(FixIsSupersetOf(args)); case "IsTrue": return(FixIsTrue(args)); case "Less": return(FixLess(args)); case "LessOrEqual": return(FixLessOrEqual(args)); case "Positive": return(FixPositive(args)); case "Negative": return(FixNegative(args)); case "NotNull": return(FixNotNull(args)); case "NotZero": return(FixNotZero(args)); case "StartsWith": return(FixStartsWith(args)); case "True": return(FixIsTrue(args)); case "Zero": return(FixZero(args)); default: return(null); } }
private static bool IsLogManagerGetLoggerCall(MemberAccessExpressionSyntax node) => node.GetName() == "GetLogger" && node.Expression is IdentifierNameSyntax i &&
private static bool IsAssertionMethod(MemberAccessExpressionSyntax node) => AssertionMethods.Contains(node.GetName()) && node.Expression is IdentifierNameSyntax invokedType &&