diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/StringTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/StringTests.cs index a6621457..4fddacac 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/StringTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/StringTests.cs @@ -85,8 +85,6 @@ public class StringTests [AssertionDataTestMethod] [AssertionDiagnostic("string.IsNullOrEmpty(actual).Should().BeTrue({0});")] - [AssertionDiagnostic("string.IsNullOrEmpty(actual).Should().BeTrue({0}).And.ToString();")] - [AssertionDiagnostic("string.IsNullOrEmpty(actual.ToString()).Should().BeTrue({0});")] [AssertionDiagnostic("string.IsNullOrEmpty(actual.ToString()).Should().BeTrue({0}).And.ToString();")] [Implemented] public void StringShouldBeNullOrEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic(assertion); @@ -95,12 +93,6 @@ public class StringTests [AssertionCodeFix( oldAssertion: "string.IsNullOrEmpty(actual).Should().BeTrue({0});", newAssertion: "actual.Should().BeNullOrEmpty({0});")] - [AssertionCodeFix( - oldAssertion: "string.IsNullOrEmpty(actual).Should().BeTrue({0}).And.ToString();", - newAssertion: "actual.Should().BeNullOrEmpty({0}).And.ToString();")] - [AssertionCodeFix( - oldAssertion: "string.IsNullOrEmpty(actual.ToString()).Should().BeTrue({0});", - newAssertion: "actual.ToString().Should().BeNullOrEmpty({0});")] [AssertionCodeFix( oldAssertion: "string.IsNullOrEmpty(actual.ToString()).Should().BeTrue({0}).And.ToString();", newAssertion: "actual.ToString().Should().BeNullOrEmpty({0}).And.ToString();")] diff --git a/src/FluentAssertions.Analyzers/Constants.cs b/src/FluentAssertions.Analyzers/Constants.cs index a234a462..fe4151da 100644 --- a/src/FluentAssertions.Analyzers/Constants.cs +++ b/src/FluentAssertions.Analyzers/Constants.cs @@ -6,6 +6,7 @@ public static class DiagnosticProperties { public const string Title = nameof(Title); public const string VisitorName = nameof(VisitorName); + public const string HelpLink = nameof(HelpLink); } public static class Tips diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs index 6fe197aa..dd9f5dee 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class OrderByShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class OrderByShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public OrderByShouldEqualSyntaxVisitor() : base(MemberValidator.MathodContainingLambda("OrderBy"), MemberValidator.Should, MemberValidator.ArgumentIsVariable("Equal")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs index 23e2fab0..6bbd7e9c 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class OrderByDescendingShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class OrderByDescendingShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public OrderByDescendingShouldEqualSyntaxVisitor() : base(MemberValidator.MathodContainingLambda("OrderByDescending"), MemberValidator.Should, MemberValidator.ArgumentIsVariable("Equal")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs index 0ea98d3b..d1972471 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs @@ -26,7 +26,7 @@ protected override IEnumerable Visitors } } - private class ContainsShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ContainsShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public ContainsShouldBeTrueSyntaxVisitor() : base(new MemberValidator("Contains"), MemberValidator.Should, new MemberValidator("BeTrue")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs index 11830f76..c7c72465 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs @@ -27,7 +27,7 @@ protected override IEnumerable Visitors } } - private class SelectShouldEqualOtherCollectionSelectSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class SelectShouldEqualOtherCollectionSelectSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public SelectShouldEqualOtherCollectionSelectSyntaxVisitor() : base(MemberValidator.MathodContainingLambda("Select"), MemberValidator.Should, new MemberValidator("Equal", MathodContainingArgumentInvokingLambda)) diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs index ec9938c4..5cdc7e9c 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs @@ -14,7 +14,7 @@ public class CollectionShouldHaveCountGreaterOrEqualToAnalyzer : CollectionAnaly public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldHaveCountGreaterOrEqualTo; public const string Category = Constants.Tips.Category; - public const string Message = "Use .Should()### instead."; + public const string Message = "Use .Should().HaveCountGreaterOrEqualTo() instead."; protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true); protected override IEnumerable Visitors @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class CountShouldBeGreaterOrEqualToSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldBeGreaterOrEqualToSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldBeGreaterOrEqualToSyntaxVisitor() : base(new MemberValidator("Count"), MemberValidator.Should, new MemberValidator("BeGreaterOrEqualTo")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs index 845cf41b..37b67994 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class CountShouldBeGreaterThanSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldBeGreaterThanSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldBeGreaterThanSyntaxVisitor() : base(new MemberValidator("Count"), MemberValidator.Should, new MemberValidator("BeGreaterThan")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs index 4b6b2532..d34182b1 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors yield return new CountShouldBeLessOrEqualToSyntaxVisitor(); } } - private class CountShouldBeLessOrEqualToSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldBeLessOrEqualToSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldBeLessOrEqualToSyntaxVisitor() : base(new MemberValidator("Count"), MemberValidator.Should, new MemberValidator("BeLessOrEqualTo")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs index b70b9f65..816222e5 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class CountShouldBeLessThanSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldBeLessThanSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldBeLessThanSyntaxVisitor() : base(new MemberValidator("Count"), MemberValidator.Should, new MemberValidator("BeLessThan")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs index 035e0dc3..dc74f69c 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs @@ -26,7 +26,7 @@ protected override IEnumerable Visitors } } - private class ShouldHaveCountOtherCollectionCountSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ShouldHaveCountOtherCollectionCountSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public ShouldHaveCountOtherCollectionCountSyntaxVisitor() : base(MemberValidator.Should, new MemberValidator("HaveCount", HasArgumentInvokingCountMethod)) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs index c894eb14..10589c7a 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class IntersectShouldNotBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class IntersectShouldNotBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public IntersectShouldNotBeEmptySyntaxVisitor() : base(MemberValidator.HasArguments("Intersect"), MemberValidator.Should, new MemberValidator("NotBeEmpty")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs index 4c839d53..2998acee 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs @@ -27,7 +27,7 @@ protected override IEnumerable Visitors } } - private class AnyShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class AnyShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public AnyShouldBeTrueSyntaxVisitor() : base(MemberValidator.MathodNotContainingLambda("Any"), MemberValidator.Should, new MemberValidator("BeTrue")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs index bca096e6..8599f316 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class ContainsShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ContainsShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public ContainsShouldBeFalseSyntaxVisitor() : base(new MemberValidator("Contains"), MemberValidator.Should, new MemberValidator("BeFalse")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs index 6296df0c..8babaecc 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class SelectShouldNotContainNullsSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class SelectShouldNotContainNullsSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public SelectShouldNotContainNullsSyntaxVisitor() : base(MemberValidator.MathodContainingLambda("Select"), MemberValidator.Should, new MemberValidator("NotContainNulls")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs index c928afd3..1441fa51 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs @@ -41,9 +41,9 @@ public class WhereShouldBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisit } } - public class ShouldOnlyContainNotSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ShouldOnlyContainSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public ShouldOnlyContainNotSyntaxVisitor() : base(MemberValidator.Should, MemberValidator.MathodContainingLambda("OnlyContain")) + public ShouldOnlyContainSyntaxVisitor() : base(MemberValidator.Should, MemberValidator.MathodContainingLambda("OnlyContain")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs index 9d3b9c18..74b851f9 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class CountShouldNotBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldNotBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldNotBeSyntaxVisitor() : base(MemberValidator.HasNoArguments("Count"), MemberValidator.Should, MemberValidator.ArgumentIsIdentifierOrLiteral("NotBe")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs index da5cafdc..4cacd9d5 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs @@ -26,7 +26,7 @@ protected override IEnumerable Visitors } } - private class CountShouldNotBeOtherCollectionCountSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class CountShouldNotBeOtherCollectionCountSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public CountShouldNotBeOtherCollectionCountSyntaxVisitor() : base(MemberValidator.HasNoArguments("Count"), MemberValidator.Should, new MemberValidator("NotBe", HasArgumentInvokingCountMethod)) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs index 24ae0331..57ed8484 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs @@ -24,7 +24,7 @@ protected override IEnumerable Visitors yield return new IntersectShouldBeEmptySyntaxVisitor(); } } - private class IntersectShouldBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class IntersectShouldBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public IntersectShouldBeEmptySyntaxVisitor() : base(MemberValidator.HasArguments("Intersect"), MemberValidator.Should, new MemberValidator("BeEmpty")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs index 4a5ac358..9b1bee0e 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs @@ -27,7 +27,7 @@ protected override IEnumerable Visitors } } - private class ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor() : base(MemberValidator.Should, new MemberValidator("HaveSameCount", ArgumentInvokesDistinctMethod)) { diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs index 93226d45..72e7daee 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs @@ -26,7 +26,7 @@ protected override IEnumerable Visitors } } - private class SelectShouldOnlyHaveUniqueItemsSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class SelectShouldOnlyHaveUniqueItemsSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public SelectShouldOnlyHaveUniqueItemsSyntaxVisitor() : base(MemberValidator.MathodContainingLambda("Select"), MemberValidator.Should, new MemberValidator("OnlyHaveUniqueItems")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainKey.cs b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainKey.cs index 12bffffe..ffaee849 100644 --- a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainKey.cs +++ b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainKey.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new ContainsKeyShouldBeTrue(); + yield return new ContainsKeyShouldBeTrueSyntaxVisitor(); } } - private class ContainsKeyShouldBeTrue : FluentAssertionsCSharpSyntaxVisitor + public class ContainsKeyShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public ContainsKeyShouldBeTrue() : base(new MemberValidator("ContainsKey"), MemberValidator.Should, new MemberValidator("BeTrue")) + public ContainsKeyShouldBeTrueSyntaxVisitor() : base(new MemberValidator("ContainsKey"), MemberValidator.Should, new MemberValidator("BeTrue")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainValue.cs b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainValue.cs index eac96ec3..5639636b 100644 --- a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainValue.cs +++ b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldContainValue.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new ContainsValueShouldBeTrue(); + yield return new ContainsValueShouldBeTrueSyntaxVisitor(); } } - private class ContainsValueShouldBeTrue : FluentAssertionsCSharpSyntaxVisitor + public class ContainsValueShouldBeTrueSyntaxVisitor: FluentAssertionsCSharpSyntaxVisitor { - public ContainsValueShouldBeTrue() : base(new MemberValidator("ContainsValue"), MemberValidator.Should, new MemberValidator("BeTrue")) + public ContainsValueShouldBeTrueSyntaxVisitor() : base(new MemberValidator("ContainsValue"), MemberValidator.Should, new MemberValidator("BeTrue")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainKey.cs b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainKey.cs index f09275fb..5074c147 100644 --- a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainKey.cs +++ b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainKey.cs @@ -25,7 +25,7 @@ protected override IEnumerable Visitors } } - private class ContainsKeyShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class ContainsKeyShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { public ContainsKeyShouldBeFalseSyntaxVisitor() : base(new MemberValidator("ContainsKey"), MemberValidator.Should, new MemberValidator("BeFalse")) { diff --git a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainValue.cs b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainValue.cs index 421ac5bf..4523a588 100644 --- a/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainValue.cs +++ b/src/FluentAssertions.Analyzers/Tips/Dictionaries/DictionaryShouldNotContainValue.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new ContainsValueShouldBeFalse(); + yield return new ContainsValueShouldBeFalseSyntaxVisitor(); } } - private class ContainsValueShouldBeFalse : FluentAssertionsCSharpSyntaxVisitor + public class ContainsValueShouldBeFalseSyntaxVisitor: FluentAssertionsCSharpSyntaxVisitor { - public ContainsValueShouldBeFalse() : base(new MemberValidator("ContainsValue"), MemberValidator.Should, new MemberValidator("BeFalse")) + public ContainsValueShouldBeFalseSyntaxVisitor() : base(new MemberValidator("ContainsValue"), MemberValidator.Should, new MemberValidator("BeFalse")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBeNegative.cs b/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBeNegative.cs index b5b54fc4..4aaa6baa 100644 --- a/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBeNegative.cs +++ b/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBeNegative.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new NumericShouldBeNegativeSyntaxVisitor(); + yield return new NumericShouldBeBeLessThan0SyntaxVisitor(); } } - public class NumericShouldBeNegativeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class NumericShouldBeBeLessThan0SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public NumericShouldBeNegativeSyntaxVisitor() : base(MemberValidator.Should, MemberValidator.ArgumentIsLiteral("BeLessThan", 0)) + public NumericShouldBeBeLessThan0SyntaxVisitor() : base(MemberValidator.Should, MemberValidator.ArgumentIsLiteral("BeLessThan", 0)) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBePositive.cs b/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBePositive.cs index 1cbace81..898e6449 100644 --- a/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBePositive.cs +++ b/src/FluentAssertions.Analyzers/Tips/Numerics/NumericShouldBePositive.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new NumericShouldBePositiveSyntaxVisitor(); + yield return new NumericShouldBeBeGreaterThan0SyntaxVisitor(); } } - public class NumericShouldBePositiveSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class NumericShouldBeBeGreaterThan0SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public NumericShouldBePositiveSyntaxVisitor() : base(MemberValidator.Should, MemberValidator.ArgumentIsLiteral("BeGreaterThan", 0)) + public NumericShouldBeBeGreaterThan0SyntaxVisitor() : base(MemberValidator.Should, MemberValidator.ArgumentIsLiteral("BeGreaterThan", 0)) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldBeNullOrEmpty.cs b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldBeNullOrEmpty.cs index ca960b38..b27bf010 100644 --- a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldBeNullOrEmpty.cs +++ b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldBeNullOrEmpty.cs @@ -22,13 +22,13 @@ protected override IEnumerable Visitors { get { - yield return new StringShouldBeNullOrEmptySyntaxVisitor(); + yield return new StringIsNullOrEmptyShouldBeTrueSyntaxVisitor(); } } - public class StringShouldBeNullOrEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class StringIsNullOrEmptyShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public StringShouldBeNullOrEmptySyntaxVisitor() : base(new MemberValidator("IsNullOrEmpty"), MemberValidator.Should, new MemberValidator("BeTrue")) + public StringIsNullOrEmptyShouldBeTrueSyntaxVisitor() : base(new MemberValidator("IsNullOrEmpty"), MemberValidator.Should, new MemberValidator("BeTrue")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldEndWith.cs b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldEndWith.cs index 23e32bc5..bfbb72a6 100644 --- a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldEndWith.cs +++ b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldEndWith.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new StringShouldEndWithSyntaxVisitor(); + yield return new EndWithShouldBeTrueSyntaxVisitor(); } } - public class StringShouldEndWithSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class EndWithShouldBeTrueSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public StringShouldEndWithSyntaxVisitor() : base(new MemberValidator("EndsWith"), MemberValidator.Should, new MemberValidator("BeTrue")) + public EndWithShouldBeTrueSyntaxVisitor() : base(new MemberValidator("EndsWith"), MemberValidator.Should, new MemberValidator("BeTrue")) { } } diff --git a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldHaveLength.cs b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldHaveLength.cs index f8931eb6..63b3269c 100644 --- a/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldHaveLength.cs +++ b/src/FluentAssertions.Analyzers/Tips/Strings/StringShouldHaveLength.cs @@ -21,13 +21,13 @@ protected override IEnumerable Visitors { get { - yield return new StringShouldHaveLengthSyntaxVisitor(); + yield return new LengthShouldBeSyntaxVisitor(); } } - public class StringShouldHaveLengthSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor + public class LengthShouldBeSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor { - public StringShouldHaveLengthSyntaxVisitor() : base(new MemberValidator("Length"), MemberValidator.Should, new MemberValidator("Be")) + public LengthShouldBeSyntaxVisitor() : base(new MemberValidator("Length"), MemberValidator.Should, new MemberValidator("Be")) { } } diff --git a/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsAnalyzer.cs b/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsAnalyzer.cs index 4ab1e79f..aa440a26 100644 --- a/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsAnalyzer.cs @@ -79,8 +79,10 @@ protected virtual Diagnostic CreateDiagnostic(TCSharpSyntaxVisitor visitor, Expr { var properties = visitor.ToDiagnosticProperties() .Add(Constants.DiagnosticProperties.Title, Title); + var newRule = new DiagnosticDescriptor(Rule.Id, Rule.Title, Rule.MessageFormat, Rule.Category, Rule.DefaultSeverity, true, + helpLinkUri: properties.GetValueOrDefault(Constants.DiagnosticProperties.HelpLink)); return Diagnostic.Create( - descriptor: Rule, + descriptor: newRule, location: expression.GetLocation(), properties: properties); } diff --git a/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsCSharpSyntaxVisitor.cs b/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsCSharpSyntaxVisitor.cs index 5827874e..e2d0ba5e 100644 --- a/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsCSharpSyntaxVisitor.cs +++ b/src/FluentAssertions.Analyzers/Utilities/FluentAssertionsCSharpSyntaxVisitor.cs @@ -18,6 +18,7 @@ public class FluentAssertionsCSharpSyntaxVisitor : CSharpSyntaxVisitor public virtual ImmutableDictionary ToDiagnosticProperties() => ImmutableDictionary.Empty .Add(Constants.DiagnosticProperties.VisitorName, GetType().Name) + .Add(Constants.DiagnosticProperties.HelpLink, HelpLinks.Get(GetType())) .ToImmutableDictionary(); public FluentAssertionsCSharpSyntaxVisitor(params MemberValidator[] members) diff --git a/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs b/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs new file mode 100644 index 00000000..d63e2d5f --- /dev/null +++ b/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; + +namespace FluentAssertions.Analyzers +{ + public static class HelpLinks + { + private static readonly Dictionary TypesHelpLinks; + private static string GetHelpLink(string id) => $"https://fluentassertions.com/tips/#{id}"; + + static HelpLinks() + { + TypesHelpLinks = new Dictionary + { + [typeof(CollectionShouldNotBeEmptyAnalyzer.AnyShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-1"), + [typeof(CollectionShouldBeEmptyAnalyzer.AnyShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-2"), + [typeof(CollectionShouldContainPropertyAnalyzer.AnyShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-3"), + [typeof(CollectionShouldNotContainPropertyAnalyzer.AnyShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-4"), + [typeof(CollectionShouldOnlyContainPropertyAnalyzer.AllShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-5"), + [typeof(CollectionShouldContainItemAnalyzer.ContainsShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-6"), + [typeof(CollectionShouldNotContainItemAnalyzer.ContainsShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-7"), + // missing Collections-8 + [typeof(CollectionShouldHaveCountAnalyzer.CountShouldBeSyntaxVisitor)] = GetHelpLink("Collections-9"), + [typeof(CollectionShouldHaveCountGreaterThanAnalyzer.CountShouldBeGreaterThanSyntaxVisitor)] = GetHelpLink("Collections-10"), + [typeof(CollectionShouldHaveCountGreaterOrEqualToAnalyzer.CountShouldBeGreaterOrEqualToSyntaxVisitor)] = GetHelpLink("Collections-11"), + [typeof(CollectionShouldHaveCountLessThanAnalyzer.CountShouldBeLessThanSyntaxVisitor)] = GetHelpLink("Collections-12"), + [typeof(CollectionShouldHaveCountLessOrEqualToAnalyzer.CountShouldBeLessOrEqualToSyntaxVisitor)] = GetHelpLink("Collections-13"), + [typeof(CollectionShouldNotHaveCountAnalyzer.CountShouldNotBeSyntaxVisitor)] = GetHelpLink("Collections-14"), + [typeof(CollectionShouldContainSingleAnalyzer.ShouldHaveCount1SyntaxVisitor)] = GetHelpLink("Collections-15"), + [typeof(CollectionShouldHaveCountAnalyzer.CountShouldBe1SyntaxVisitor)] = GetHelpLink("Collections-15"), + [typeof(CollectionShouldBeEmptyAnalyzer.ShouldHaveCount0SyntaxVisitor)] = GetHelpLink("Collections-16"), + [typeof(CollectionShouldHaveCountAnalyzer.CountShouldBe0SyntaxVisitor)] = GetHelpLink("Collections-16"), // hmmm + [typeof(CollectionShouldHaveSameCountAnalyzer.ShouldHaveCountOtherCollectionCountSyntaxVisitor)] = GetHelpLink("Collections-17"), + [typeof(CollectionShouldNotHaveSameCountAnalyzer.CountShouldNotBeOtherCollectionCountSyntaxVisitor)] = GetHelpLink("Collections-18"), + [typeof(CollectionShouldContainPropertyAnalyzer.WhereShouldNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-19"), + [typeof(CollectionShouldNotContainPropertyAnalyzer.WhereShouldBeEmptySyntaxVisitor)] = GetHelpLink("Collections-20"), + [typeof(CollectionShouldContainSingleAnalyzer.WhereShouldHaveCount1SyntaxVisitor)] = GetHelpLink("Collections-21"), + [typeof(CollectionShouldNotContainPropertyAnalyzer.ShouldOnlyContainSyntaxVisitor)] = GetHelpLink("Collections-22"), + [typeof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeNullAndNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-23"), + [typeof(CollectionShouldNotBeNullOrEmptyAnalyzer.ShouldNotBeEmptyAndNotBeNullSyntaxVisitor)] = GetHelpLink("Collections-23"), + [typeof(CollectionShouldHaveElementAtAnalyzer.ElementAtIndexShouldBeSyntaxVisitor)] = GetHelpLink("Collections-24"), + [typeof(CollectionShouldHaveElementAtAnalyzer.IndexerShouldBeSyntaxVisitor)] = GetHelpLink("Collections-25"), + [typeof(CollectionShouldHaveElementAtAnalyzer.SkipFirstShouldBeSyntaxVisitor)] = GetHelpLink("Collections-26"), + [typeof(CollectionShouldBeInAscendingOrderAnalyzer.OrderByShouldEqualSyntaxVisitor)] = GetHelpLink("Collections-27"), + [typeof(CollectionShouldBeInDescendingOrderAnalyzer.OrderByDescendingShouldEqualSyntaxVisitor)] = GetHelpLink("Collections-28"), + [typeof(CollectionShouldEqualOtherCollectionByComparerAnalyzer.SelectShouldEqualOtherCollectionSelectSyntaxVisitor)] = GetHelpLink("Collections-29"), + [typeof(CollectionShouldNotIntersectWithAnalyzer.IntersectShouldBeEmptySyntaxVisitor)] = GetHelpLink("Collections-30"), + [typeof(CollectionShouldIntersectWithAnalyzer.IntersectShouldNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-31"), + [typeof(CollectionShouldNotContainNullsAnalyzer.SelectShouldNotContainNullsSyntaxVisitor)] = GetHelpLink("Collections-32"), + [typeof(CollectionShouldOnlyHaveUniqueItemsAnalyzer.ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor)] = GetHelpLink("Collections-33"), + [typeof(CollectionShouldOnlyHaveUniqueItemsByComparerAnalyzer.SelectShouldOnlyHaveUniqueItemsSyntaxVisitor)] = GetHelpLink("Collections-34"), + + [typeof(NumericShouldBePositiveAnalyzer.NumericShouldBeBeGreaterThan0SyntaxVisitor)] = GetHelpLink("Comparable-and-Numerics-1"), + [typeof(NumericShouldBeNegativeAnalyzer.NumericShouldBeBeLessThan0SyntaxVisitor)] = GetHelpLink("Comparable-and-Numerics-2"), + [typeof(NumericShouldBeApproximatelyAnalyzer.MathAbsShouldBeLessOrEqualToSyntaxVisitor)] = string.Empty, // TODO: add to docs + [typeof(NumericShouldBeInRangeAnalyzer.BeGreaterOrEqualToAndBeLessOrEqualToSyntaxVisitor)] = string.Empty, // TODO: add to docs + [typeof(NumericShouldBeInRangeAnalyzer.BeLessOrEqualToAndBeGreaterOrEqualToSyntaxVisitor)] = string.Empty, // TODO: add to docs + + [typeof(DictionaryShouldContainKeyAnalyzer.ContainsKeyShouldBeTrueSyntaxVisitor)] = GetHelpLink("Dictionaries-1"), + [typeof(DictionaryShouldNotContainKeyAnalyzer.ContainsKeyShouldBeFalseSyntaxVisitor)] = GetHelpLink("Dictionaries-2"), + [typeof(DictionaryShouldContainValueAnalyzer.ContainsValueShouldBeTrueSyntaxVisitor)] = GetHelpLink("Dictionaries-3"), + [typeof(DictionaryShouldNotContainValueAnalyzer.ContainsValueShouldBeFalseSyntaxVisitor)] = GetHelpLink("Dictionaries-4"), + [typeof(DictionaryShouldContainKeyAndValueAnalyzer.ShouldContainKeyAndContainValueSyntaxVisitor)] = GetHelpLink("Dictionaries-5"), + [typeof(DictionaryShouldContainKeyAndValueAnalyzer.ShouldContainValueAndContainKeySyntaxVisitor)] = GetHelpLink("Dictionaries-5"), + [typeof(DictionaryShouldContainPairAnalyzer.ShouldContainKeyAndContainValueSyntaxVisitor)] = GetHelpLink("Dictionaries-6"), + [typeof(DictionaryShouldContainPairAnalyzer.ShouldContainValueAndContainKeySyntaxVisitor)] = GetHelpLink("Dictionaries-6"), + + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldContain)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldContain)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldContain)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldContain)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldBe)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldBe)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldBe)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldBe)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldStartWith)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldStartWith)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldStartWith)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldEndWith)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyWhichMessageShouldEndWith)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowWhichMessageShouldEndWith)] = GetHelpLink("Exceptions-2"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowExactlyAndMessageShouldEndWith)] = GetHelpLink("Exceptions-1"), + [typeof(ExceptionShouldThrowWithMessageAnalyzer.ShouldThrowAndMessageShouldStartWith)] = GetHelpLink("Exceptions-2"), + + [typeof(StringShouldStartWithAnalyzer.StartWithShouldBeTrueSyntaxVisitor)] = GetHelpLink("Strings-1"), + [typeof(StringShouldEndWithAnalyzer.EndWithShouldBeTrueSyntaxVisitor)] = GetHelpLink("Strings-2"), + [typeof(StringShouldNotBeNullOrEmptyAnalyzer.StringShouldNotBeNullAndNotBeEmptySyntaxVisitor)] = GetHelpLink("Strings-3"), + [typeof(StringShouldNotBeNullOrEmptyAnalyzer.StringShouldNotBeEmptyAndNotBeNullSyntaxVisitor)] = GetHelpLink("Strings-3"), + [typeof(StringShouldBeNullOrEmptyAnalyzer.StringIsNullOrEmptyShouldBeTrueSyntaxVisitor)] = GetHelpLink("Strings-4"), + [typeof(StringShouldNotBeNullOrEmptyAnalyzer.StringIsNullOrEmptyShouldBeFalseSyntaxVisitor)] = GetHelpLink("Strings-5"), + [typeof(StringShouldBeNullOrWhiteSpaceAnalyzer.StringShouldBeNullOrWhiteSpaceSyntaxVisitor)] = GetHelpLink("Strings-6"), + [typeof(StringShouldNotBeNullOrWhiteSpaceAnalyzer.StringShouldNotBeNullOrWhiteSpaceSyntaxVisitor)] = GetHelpLink("Strings-7"), + [typeof(StringShouldHaveLengthAnalyzer.LengthShouldBeSyntaxVisitor)] = GetHelpLink("Strings-8") + }; + } + + public static string Get(Type type) + => TypesHelpLinks.TryGetValue(type, out var value) ? value : string.Empty; + } +}