Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Azure.ClientSdk.Analyzers to fix incorrect behaviors #6496

Closed
wants to merge 15 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,52 @@ public class AZC0002Tests
public async Task AZC0002ProducedForMethodsWithoutCancellationTokenOrRequestContext()
{
const string code = @"
using Azure;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}()
public virtual Task<Response> {|AZC0002:GetAsync|}()
{
return null;
}

public virtual void {|AZC0002:Get|}()
public virtual Response {|AZC0002:Get|}()
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: does this enable AZC0015 for these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just means we don't need to suppress AZC0015. That's it.

AZC0015 is not effective now.

.RunAsync();
}

[Fact]
public async Task AZC0002ProducedForMethodsWithWrongNameCancellationToken()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
{
return null;
}

public virtual void {|AZC0002:Get|}(CancellationToken cancellation = default)
public virtual Response {|AZC0002:Get|}(CancellationToken cancellation = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -65,51 +67,53 @@ public async Task AZC0002ProducedForMethodsWithWrongNameRequestContext()
{
const string code = @"
using Azure;
using Azure.Core;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(RequestContext cancellation = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(RequestContext cancellation = default)
{
return null;
}

public virtual void {|AZC0002:Get|}(RequestContext cancellation = default)
public virtual Response {|AZC0002:Get|}(RequestContext cancellation = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

[Fact]
public async Task AZC0002ProducedForMethodsWithNonOptionalCancellationToken()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
{
return null;
}

public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken)
public virtual Response {|AZC0002:Get|}(CancellationToken cancellationToken)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -125,18 +129,18 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
{
return null;
}

public virtual void {|AZC0002:Get|}(RequestContext context = default, string text = default)
public virtual Response {|AZC0002:Get|}(RequestContext context = default, string text = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -152,44 +156,45 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken = default, string text = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellationToken = default, string text = default)
{
return null;
}

public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken = default, string text = default)
public virtual Response {|AZC0002:Get|}(CancellationToken cancellationToken = default, string text = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

[Fact]
public async Task AZC0002NotProducedForMethodsWithCancellationToken()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task GetAsync(CancellationToken cancellationToken = default)
public virtual Task<Response> GetAsync(CancellationToken cancellationToken = default)
{
return null;
}

public virtual void Get(CancellationToken cancellationToken = default)
public virtual Response Get(CancellationToken cancellationToken = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -205,45 +210,48 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task Get1Async(string s, CancellationToken cancellationToken = default)
public virtual Task<Response> Get1Async(string s, CancellationToken cancellationToken = default)
{
return null;
}

public virtual void Get1(string s, CancellationToken cancellationToken = default)
public virtual Response Get1(string s, CancellationToken cancellationToken = default)
{
return null;
}

public virtual Task Get1Async(string s, RequestContext context)
public virtual Task<Response> Get1Async(string s, RequestContext context)
{
return null;
}

public virtual void Get1(string s, RequestContext context)
public virtual Response Get1(string s, RequestContext context)
{
return null;
}

public virtual Task Get2Async(CancellationToken cancellationToken = default)
public virtual Task<Response> Get2Async(CancellationToken cancellationToken = default)
{
return null;
}

public virtual void Get2(CancellationToken cancellationToken = default)
public virtual Response Get2(CancellationToken cancellationToken = default)
{
return null;
}

public virtual Task Get2Async(RequestContext context)
public virtual Task<Response> Get2Async(RequestContext context)
{
return null;
}

public virtual void Get2(RequestContext context)
public virtual Response Get2(RequestContext context)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.WithDisabledDiagnostics("AZC0018")
.WithDisabledDiagnostics("AD0001")
.RunAsync();
Expand All @@ -261,29 +269,67 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task GetAsync(RequestContext context = default)
public virtual Task<Response> GetAsync(RequestContext context = default)
{
return null;
}

public virtual void Get(RequestContext context = default)
public virtual Response Get(RequestContext context = default)
{
return null;
}

public virtual Task Get2Async(RequestContext context)
public virtual Task<Response> Get2Async(RequestContext context)
{
return null;
}

public virtual void Get2(RequestContext context)
public virtual Response Get2(RequestContext context)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.WithDisabledDiagnostics("AZC0018")
.RunAsync();
}

[Fact]
public async Task AZC0002NotProducedIfThereIsAnOverloadWithCancellationToken()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public virtual Task<Response> GetAsync(string s)
{
return null;
}

public virtual Response Get(string s)
{
return null;
}

public virtual Task<Response> GetAsync(string s, CancellationToken cancellationToken)
{
return null;
}

public virtual Response Get(string s, CancellationToken cancellationToken)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.RunAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ public class AZC0003Tests
public async Task AZC0003ProducedForNonVirtualMethods()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;

namespace RandomNamespace
{
public class SomeClient
{
public Task {|AZC0003:GetAsync|](CancellationToken cancellationToken = default)
public Task<Response> {|AZC0003:GetAsync|](CancellationToken cancellationToken = default)
{
return null;
}

public void {|AZC0003:Get|](CancellationToken cancellationToken = default)
public Response {|AZC0003:Get|](CancellationToken cancellationToken = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -57,7 +58,6 @@ private void Get(CancellationToken cancellationToken = default)
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand Down Expand Up @@ -91,8 +91,7 @@ public virtual void Get(CancellationToken cancellationToken = default)
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}
}
}
}
Loading