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

Avoid conditionals inside assertions analyzer #2848

Merged
merged 18 commits into from
May 15, 2024

Conversation

fhnaseer
Copy link
Member

@fhnaseer fhnaseer commented May 14, 2024

Fixes #2751

  • Analyzers for Assert, CollectionAssert, and StringAssert
  • Assert method should avoid conditional access

Example:
// Warning
Assert.AreEqual(a?.b, "something");

// Fix
Assert.IsNotNull(a);
Assert.AreEqual(a.b, "something");

@fhnaseer fhnaseer requested a review from Evangelink as a code owner May 14, 2024 09:01
@fhnaseer fhnaseer marked this pull request as draft May 14, 2024 10:20
@fhnaseer fhnaseer requested a review from Evangelink May 14, 2024 10:25
@fhnaseer fhnaseer marked this pull request as ready for review May 14, 2024 14:26
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

It'd be good to validate that no diagnostic is raised when using conditional access within Assert.IsNull or Assert.IsNotNull.

Evangelink
Evangelink previously approved these changes May 15, 2024
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

LGTM thank you for the nice implementation and the fast updates @fhnaseer :shipit:

Could you please do a follow-up PR to dotnet/docs for this rule? Here is an example PR: dotnet/docs#40785

@Evangelink Evangelink enabled auto-merge (squash) May 15, 2024 09:30
@Evangelink Evangelink merged commit 5287018 into main May 15, 2024
7 checks passed
@Evangelink Evangelink deleted the fhnaseer/avoid-conditional-analyzer branch May 15, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid conditionals inside assertions
3 participants