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

Respect PreferParameterNullChecking user option #59561

Merged
merged 5 commits into from
Feb 16, 2022
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,36 @@ public async Task TestEmptyFile()
await VerifyCS.VerifyRefactoringAsync(code, code);
}

[Theory, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
[InlineData("", true)]
[InlineData("csharp_style_prefer_parameter_null_checking = true", true)]
[InlineData("csharp_style_prefer_parameter_null_checking = false", false)]
public async Task TestSimpleReferenceType(string editorConfig, bool useParameterNullChecking)
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
public async Task TestSimpleReferenceType()
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the case where the option is explicitly enabled was removed. Was that intended?

{
var fixedCode = useParameterNullChecking ? @"
await new VerifyCS.Test
{
LanguageVersion = LanguageVersionExtensions.CSharpNext,
TestCode = @"
using System;

class C
{
public C(string s!!)
public C([||]string s)
{
}
}" : @"
}",
FixedCode = @"
using System;

class C
{
public C(string s)
public C(string s!!)
{
if (s is null)
{
throw new ArgumentNullException(nameof(s));
}
}
}";
}",
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
public async Task TestDoNotPreferParameterNullChecking()
{
await new VerifyCS.Test
{
LanguageVersion = LanguageVersionExtensions.CSharpNext,
Expand All @@ -68,10 +71,22 @@ public C([||]string s)
{
}
}",
FixedCode = fixedCode,
EditorConfig = $@"
FixedCode = @"
using System;

class C
{
public C(string s)
{
if (s is null)
{
throw new ArgumentNullException(nameof(s));
}
}
}",
EditorConfig = @"
[*]
{editorConfig}
csharp_style_prefer_parameter_null_checking = false
",
}.RunAsync();
}
Expand Down