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 @@ -20,7 +20,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}()
public virtual Task<Response> {|AZC0002:GetAsync|}()
{
return null;
}
Expand All @@ -32,7 +32,6 @@ public class SomeClient
}
}";
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();
}

Expand All @@ -48,7 +47,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
{
return null;
}
Expand All @@ -60,7 +59,6 @@ public class SomeClient
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -77,7 +75,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}(RequestContext cancellation = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(RequestContext cancellation = default)
{
return null;
}
Expand All @@ -89,7 +87,6 @@ public class SomeClient
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -105,7 +102,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
{
return null;
}
Expand All @@ -117,7 +114,6 @@ public class SomeClient
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -133,7 +129,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
{
return null;
}
Expand All @@ -145,7 +141,6 @@ public class SomeClient
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

Expand All @@ -161,7 +156,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response {|AZC0002:GetAsync|}(CancellationToken cancellationToken = default, string text = default)
public virtual Task<Response> {|AZC0002:GetAsync|}(CancellationToken cancellationToken = default, string text = default)
{
return null;
}
Expand All @@ -173,33 +168,33 @@ public class SomeClient
}
}";
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 @@ -215,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 @@ -271,27 +269,28 @@ 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();
}
Expand All @@ -308,7 +307,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Response GetAsync(string s)
public virtual Task<Response> GetAsync(string s)
{
return null;
}
Expand All @@ -318,7 +317,7 @@ public virtual Response Get(string s)
return null;
}

public virtual Response GetAsync(string s, CancellationToken cancellationToken)
public virtual Task<Response> GetAsync(string s, CancellationToken cancellationToken)
{
return null;
}
Expand All @@ -330,7 +329,6 @@ public virtual Response Get(string s, CancellationToken cancellationToken)
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace RandomNamespace
{
public class SomeClient
{
public Response {|AZC0003:GetAsync|](CancellationToken cancellationToken = default)
public Task<Response> {|AZC0003:GetAsync|](CancellationToken cancellationToken = default)
{
return null;
}
Expand All @@ -33,7 +33,6 @@ public class SomeClient
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

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

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