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

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Feb 15, 2022

Fixes #59559

Relevant Discord discussion that lead to this PR:

image

@Youssef1313 Youssef1313 requested a review from a team as a code owner February 15, 2022 09:18
@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Feb 15, 2022
Comment on lines 33 to 36
[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)
Copy link
Member

Choose a reason for hiding this comment

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

💡 Consider rewriting this to minimize unnecessary/duplicate parameterization of the method:

Suggested change
[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)
[InlineData(null)]
[InlineData(true)]
[InlineData(false)]
public async Task TestSimpleReferenceType(bool? useParameterNullChecking)

Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to extract the scenario where the option is explicitly disabled to its own [Fact], and then treat this test as though useParameterNullChecking is a constant true. However, I don't feel strongly about any particular factoring of the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sharwell @RikkiGibson I'm a bit confused as to which suggestion should I take. Both sounds reasonable and I'm okay either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go with #59561 (comment) :)

Copy link
Member

Choose a reason for hiding this comment

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

The downside of the approach mentioned by @RikkiGibson is we lose the ability to see that the two tests are operating on different input. At that point, it's not clear whether the different output is caused by a change in the option, or a change in the input. While this is rarely a problem in the pull request where the test is introduced, it's easy and common for an update to one test to fail to realize that the other is a matching test that needs to be updated at the same time. For this reason, it is strongly recommended for the test to be combined.

Copy link
Member

Choose a reason for hiding this comment

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

@Youssef1313 I won't block this PR on the suggested change. More a note for the future to keep with the approach you were already using 😄

Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Thanks Youssef! Is there any need to also make a change in the analyzer? Or maybe I did that part right? 😅

Comment on lines 33 to 36
[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)
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to extract the scenario where the option is explicitly disabled to its own [Fact], and then treat this test as though useParameterNullChecking is a constant true. However, I don't feel strongly about any particular factoring of the test.

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Feb 15, 2022

@Youssef1313 Please advise us if you plan to make any change to the test, and otherwise I think we can just merge.

[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?

@sharwell
Copy link
Member

📝 CLA bot seems to be down. Have reported this and will ping that check after it's fixed/online again to trigger the merge.

@RikkiGibson RikkiGibson merged commit 52bdc01 into dotnet:main Feb 16, 2022
@ghost ghost added this to the Next milestone Feb 16, 2022
@Youssef1313 Youssef1313 deleted the respect-paramnull-option-59559 branch February 16, 2022 20:47
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P2 Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSharpAddParameterCheckCodeRefactoringProvider doesn't respect PreferParameterNullChecking
4 participants