Skip to content

Commit

Permalink
add new rule AG0040 (#187)
Browse files Browse the repository at this point in the history
Co-authored-by: Khathawut Chaipraphun <kchaipraphun@gf2vghxc6l.agoda.local>
  • Loading branch information
kchaipraphun and Khathawut Chaipraphun authored Sep 18, 2024
1 parent 088e35d commit 74e0ffa
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 201 deletions.
1 change: 1 addition & 0 deletions src/Agoda.Analyzers.Test/Agoda.Analyzers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Testing.Verifiers.NUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.5.0" />
<PackageReference Include="Microsoft.Composition" Version="1.0.27" />
<PackageReference Include="Microsoft.Playwright" Version="1.47.0" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
Expand Down
2 changes: 1 addition & 1 deletion src/Agoda.Analyzers.Test/AgodaCustom/AG0001UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public void TestMethod() {
await VerifyDiagnosticsAsync(code, new DiagnosticLocation(8, 57));
}

}
}
37 changes: 37 additions & 0 deletions src/Agoda.Analyzers.Test/AgodaCustom/AG0040UnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Threading.Tasks;
using System.Web.Mvc;
using Agoda.Analyzers.AgodaCustom;
using Agoda.Analyzers.Test.Helpers;
using Microsoft.CodeAnalysis.Diagnostics;
using NUnit.Framework;
using Microsoft.Playwright;

namespace Agoda.Analyzers.Test.AgodaCustom;

[TestFixture]
class AG0040UnitTests : DiagnosticVerifier
{
protected override DiagnosticAnalyzer DiagnosticAnalyzer => new AG0040DependencyResolverMustNotBeUsed();

protected override string DiagnosticId => AG0040DependencyResolverMustNotBeUsed.DIAGNOSTIC_ID;

[Test]
public async Task TestDependencyResolverUsageAsync()
{
var code = new CodeDescriptor
{
References = new[] {typeof(WaitUntilState).Assembly},
Code = @"
using Microsoft.Playwright;
class MyClass {
public MyClass () {
var a = WaitUntilState.NetworkIdle;
}
}
"
};
await VerifyDiagnosticsAsync(code, new DiagnosticLocation(6, 51));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using Agoda.Analyzers.Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Agoda.Analyzers.AgodaCustom
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AG0040DependencyResolverMustNotBeUsed : PropertyInvocationAnalyzerBase
{
public const string DIAGNOSTIC_ID = "AG0040";

private static readonly LocalizableString Title = new LocalizableResourceString(
nameof(CustomRulesResources.AG0040Title),
CustomRulesResources.ResourceManager,
typeof(CustomRulesResources));

private static readonly LocalizableString MessageFormat = new LocalizableResourceString(
nameof(CustomRulesResources.AG0040MessageFormat),
CustomRulesResources.ResourceManager,
typeof(CustomRulesResources));

private static readonly LocalizableString Description
= DescriptionContentLoader.GetAnalyzerDescription(nameof(AG0040DependencyResolverMustNotBeUsed));

protected override DiagnosticDescriptor Descriptor => new DiagnosticDescriptor(
DIAGNOSTIC_ID,
Title,
MessageFormat,
AnalyzerCategory.CustomQualityRules,
DiagnosticSeverity.Warning,
AnalyzerConstants.EnabledByDefault,
Description,
"https://playwright.dev/dotnet/docs/api/class-page#page-go-back",
WellKnownDiagnosticTags.EditAndContinue);

protected override IEnumerable<InvocationRule> Rules => new[]
{
new BlacklistedInvocationRule("Microsoft.Playwright.WaitUntilState", "NetworkIdle")
};
}
}
Loading

0 comments on commit 74e0ffa

Please sign in to comment.