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

Use markup key to indicate expected diagnostics location #3861

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/GraphQL.Analyzers.Tests/AwaitableResolverAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType, {{returnType}}>("Test")
.Resolve(ctx => {{awaitableType}}.FromResult("text"));
.{|#0:Resolve|}(ctx => {{awaitableType}}.FromResult("text"));
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ public MyGraphType()
{{CUSTOM_AWAITABLE_SOURCE}}
""";

var expected = VerifyCS.Diagnostic().WithSpan(13, 14, 13, 21).WithArguments(Constants.MethodNames.ResolveAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -211,14 +211,14 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType, {{returnType}}>("Test")
.Resolve(ctx => {{awaitableType}}.FromResult("text"));
.{|#0:Resolve|}(ctx => {{awaitableType}}.FromResult("text"));
}
}

{{CUSTOM_AWAITABLE_SOURCE}}
""";

var expected = VerifyCS.Diagnostic().WithSpan(13, 14, 13, 21).WithArguments(Constants.MethodNames.ResolveAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, source);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public class MyGraphType : ObjectGraphType<MySource>
public MyGraphType()
{
Field<StringGraphType, {{returnType}}>("Test")
.ResolveScoped(ctx => {{awaitableType}}.FromResult("text"));
.{|#0:ResolveScoped|}(ctx => {{awaitableType}}.FromResult("text"));
}
}

Expand All @@ -257,7 +257,7 @@ public class MySource { }
{{CUSTOM_AWAITABLE_SOURCE}}
""";

var expected = VerifyCS.Diagnostic().WithSpan(13, 14, 13, 27).WithArguments(Constants.MethodNames.ResolveScopedAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveScopedAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, source);
}

Expand All @@ -281,7 +281,7 @@ public class MyGraphType : ObjectGraphType<MySource>
public MyGraphType()
{
Field<StringGraphType, {{returnType}}>("Test")
.ResolveScoped(ctx => {{awaitableType}}.FromResult("text"));
.{|#0:ResolveScoped|}(ctx => {{awaitableType}}.FromResult("text"));
}
}

Expand All @@ -290,7 +290,7 @@ public class MySource { }
{{CUSTOM_AWAITABLE_SOURCE}}
""";

var expected = VerifyCS.Diagnostic().WithSpan(13, 14, 13, 27).WithArguments(Constants.MethodNames.ResolveScopedAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveScopedAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, source);
}

Expand All @@ -316,7 +316,7 @@ public class MyGraphType : ObjectGraphType
{
public MyGraphType()
{
Field<StringGraphType>("Test").Resolve(ctx => {{resolver}});
Field<StringGraphType>("Test").{|#0:Resolve|}(ctx => {{resolver}});
}

private string Resolve(IResolveFieldContext<object> ctx) => throw new NotImplementedException();
Expand Down Expand Up @@ -348,7 +348,7 @@ public MyGraphType()
""";

var expected = report
? new[] { VerifyCS.Diagnostic().WithSpan(12, 40, 12, 47).WithArguments(Constants.MethodNames.ResolveAsync) }
? new[] { VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync) }
: DiagnosticResult.EmptyDiagnosticResults;

string expectedFix = report ? fix : source;
Expand Down Expand Up @@ -378,7 +378,7 @@ public class MyGraphType : ObjectGraphType
{
public MyGraphType()
{
Field<StringGraphType>("Test").Resolve(ctx =>
Field<StringGraphType>("Test").{|#0:Resolve|}(ctx =>
{
if (true)
return {{resolver}};
Expand Down Expand Up @@ -422,7 +422,7 @@ public MyGraphType()
""";

var expected = report
? new[] { VerifyCS.Diagnostic().WithSpan(12, 40, 12, 47).WithArguments(Constants.MethodNames.ResolveAsync) }
? new[] { VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync) }
: DiagnosticResult.EmptyDiagnosticResults;

string expectedFix = report ? fix : source;
Expand All @@ -448,7 +448,7 @@ public class MyGraphType : ObjectGraphType
{
public MyGraphType()
{
Field<StringGraphType>("Test").Resolve({{resolver}});
Field<StringGraphType>("Test").{|#0:Resolve|}({{resolver}});
}

private string Resolve(IResolveFieldContext<object> ctx) => throw new NotImplementedException();
Expand Down Expand Up @@ -478,7 +478,7 @@ public MyGraphType()
""";

var expected = report
? new[] { VerifyCS.Diagnostic().WithSpan(12, 40, 12, 47).WithArguments(Constants.MethodNames.ResolveAsync) }
? new[] { VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync) }
: DiagnosticResult.EmptyDiagnosticResults;

string expectedFix = report ? fix : source;
Expand All @@ -502,7 +502,7 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Test")
.Resolve(
.{|#0:Resolve|}(
ctx => Task.FromResult("text")
);
}
Expand Down Expand Up @@ -531,7 +531,7 @@ public MyGraphType()

""";

var expected = VerifyCS.Diagnostic().WithSpan(12, 14, 12, 21).WithArguments(Constants.MethodNames.ResolveAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -551,7 +551,7 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Test")
.Resolve(ctx =>
.{|#0:Resolve|}(ctx =>
Task.FromResult("text")
);
}
Expand Down Expand Up @@ -580,7 +580,7 @@ await Task.FromResult("text")

""";

var expected = VerifyCS.Diagnostic().WithSpan(12, 14, 12, 21).WithArguments(Constants.MethodNames.ResolveAsync);
var expected = VerifyCS.Diagnostic().WithLocation(0).WithArguments(Constants.MethodNames.ResolveAsync);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}
}
52 changes: 26 additions & 26 deletions src/GraphQL.Analyzers.Tests/FieldArgumentAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MyGraphType : ObjectGraphType
{
public MyGraphType()
{
Field<StringGraphType>("Text").Argument<StringGraphType, string>("arg", "description");
Field<StringGraphType>("Text").{|#0:Argument<StringGraphType, string>("arg", "description")|};
}
}
""";
Expand All @@ -67,7 +67,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(9, 40, 9, 95);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -84,7 +84,7 @@ public class MyGraphType : ObjectGraphType
{
public MyGraphType()
{
Field<StringGraphType>("Text").Argument<StringGraphType, string>("arg", "description", configure: argument => argument.DefaultValue = "MyDefault");
Field<StringGraphType>("Text").{|#0:Argument<StringGraphType, string>("arg", "description", configure: argument => argument.DefaultValue = "MyDefault")|};
}
}
""";
Expand All @@ -104,7 +104,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(9, 40, 9, 155);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -122,7 +122,7 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>("arg", "description", "MyDefault");
.{|#0:Argument<StringGraphType, string>("arg", "description", "MyDefault")|};
}
}
""";
Expand All @@ -143,7 +143,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 10, 82);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -161,10 +161,10 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>(
.{|#0:Argument<StringGraphType, string>(
"arg",
"description",
"MyDefault");
"MyDefault")|};
}
}
""";
Expand All @@ -188,7 +188,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 13, 29);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -206,7 +206,7 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>("arg", "description", "MyDefault", argument => argument.DeprecationReason = "Deprecation Reason");
.{|#0:Argument<StringGraphType, string>("arg", "description", "MyDefault", argument => argument.DeprecationReason = "Deprecation Reason")|};
}
}
""";
Expand All @@ -227,7 +227,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 10, 145);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -245,8 +245,8 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>("arg", "description", "MyDefault", argument =>
argument.DeprecationReason = "Deprecation Reason");
.{|#0:Argument<StringGraphType, string>("arg", "description", "MyDefault", argument =>
argument.DeprecationReason = "Deprecation Reason")|};
}
}
""";
Expand All @@ -271,7 +271,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 11, 67);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -289,11 +289,11 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>(
.{|#0:Argument<StringGraphType, string>(
"arg",
"description",
"MyDefault",
argument => argument.DeprecationReason = "Deprecation Reason" );
argument => argument.DeprecationReason = "Deprecation Reason" )|};
}
}
""";
Expand All @@ -317,7 +317,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 14, 80);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -335,14 +335,14 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>(
.{|#0:Argument<StringGraphType, string>(
"arg",
"description",
"MyDefault",
argument =>
{
argument.DeprecationReason = "Deprecation Reason";
});
})|};
}
}
""";
Expand Down Expand Up @@ -370,7 +370,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 17, 19);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -388,13 +388,13 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>(
.{|#0:Argument<StringGraphType, string>(
"arg",
"description",
"MyDefault",
argument =>
{
});
})|};
}
}
""";
Expand All @@ -420,7 +420,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 16, 27);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}

Expand All @@ -438,11 +438,11 @@ public class MyGraphType : ObjectGraphType
public MyGraphType()
{
Field<StringGraphType>("Text")
.Argument<StringGraphType, string>(
.{|#0:Argument<StringGraphType, string>(
"arg",
"description",
"MyDefault",
argument => { });
argument => { })|};
}
}
""";
Expand All @@ -466,7 +466,7 @@ public MyGraphType()
}
""";

var expected = VerifyCS.Diagnostic().WithSpan(10, 14, 14, 33);
var expected = VerifyCS.Diagnostic().WithLocation(0);
await VerifyCS.VerifyCodeFixAsync(source, expected, fix);
}
}
Loading
Loading