SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
797 stars 229 forks source link

New Rule Idea: You should not use the null forgiving operator when nullable context is disabled #9691

Open mary-georgiou-sonarsource opened 3 weeks ago

mary-georgiou-sonarsource commented 3 weeks ago

When the Nullable context is disabled, the nullable forgiving operator is a no-op. There's no need to use it.

#nullable disable

string s  = Method();
_ = s!.ToString(); // Noncompliant, as it's noop and just adds noise