-
Notifications
You must be signed in to change notification settings - Fork 742
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
Consistently use 'is null' and 'is not null' iso '== null' and '!= null' #4379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @manfred-brands. I only have some nit-picks (mostly relating to the formatting of ternary expressions after the update) - otherwise it looks good.
return 0; | ||
|
||
if (x == null || y == null) | ||
if (x is null || y is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to your change, but this is an odd (read: wrong) IComparer
@@ -11,8 +11,7 @@ public class RuntimeFrameworkTests | |||
static readonly RuntimeType currentRuntime = RuntimeType.NetCore; | |||
#else | |||
static readonly RuntimeType currentRuntime = | |||
Type.GetType("Mono.Runtime", false) != null | |||
? RuntimeType.Mono | |||
Type.GetType("Mono.Runtime", false) is not null ? RuntimeType.Mono |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type.GetType("Mono.Runtime", false) is not null ? RuntimeType.Mono | |
Type.GetType("Mono.Runtime", false) is not null | |
? RuntimeType.Mono |
@@ -205,15 +205,14 @@ private int Execute() | |||
|
|||
_textUI.DisplayRuntimeEnvironment(); | |||
|
|||
var testFile = _testAssembly != null | |||
? AssemblyHelper.GetAssemblyPath(_testAssembly) | |||
var testFile = _testAssembly is not null ? AssemblyHelper.GetAssemblyPath(_testAssembly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var testFile = _testAssembly is not null ? AssemblyHelper.GetAssemblyPath(_testAssembly) | |
var testFile = _testAssembly is not null | |
? AssemblyHelper.GetAssemblyPath(_testAssembly) |
? _testAssembly.GetName().Name | ||
: _options.InputFile != null | ||
? Path.GetFileNameWithoutExtension(_options.InputFile) | ||
var baseName = _testAssembly is not null ? _testAssembly.GetName().Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the existing formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I certainly agree, it seems the CodeFix from the Analyzer looses trailing trivia. I will create an issue (and PR) for it: AArnott/CSharpIsNull#45
@@ -199,8 +199,7 @@ protected static void AppendGenericTypeNames(StringBuilder sb, MethodInfo method | |||
|
|||
protected static string GetDisplayString(object? arg, int stringMax) | |||
{ | |||
string display = arg == null | |||
? "null" | |||
string display = arg is null ? "null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string display = arg is null ? "null" | |
string display = arg is null | |
? "null" |
@@ -67,8 +67,7 @@ public TestAssembly(TestAssembly assembly, ITestFilter filter) | |||
/// </summary> | |||
public override TAttr[] GetCustomAttributes<TAttr>(bool inherit) | |||
{ | |||
return Assembly != null | |||
? Assembly.GetAttributes<TAttr>() | |||
return Assembly is not null ? Assembly.GetAttributes<TAttr>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Assembly is not null ? Assembly.GetAttributes<TAttr>() | |
return Assembly is not null | |
? Assembly.GetAttributes<TAttr>() |
@@ -150,7 +150,7 @@ private void PumpThreadProc() | |||
while (true) | |||
{ | |||
Event? e = _events.Dequeue( PumpState == EventPumpState.Pumping ); | |||
if ( e == null ) | |||
if ( e is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( e is null) | |
if (e is null) |
@@ -373,8 +373,7 @@ private static List<TNode> ApplySelection(List<TNode> nodeList, string xpath) | |||
} | |||
} | |||
|
|||
return tail != null | |||
? ApplySelection(resultNodes, tail) | |||
return tail is not null ? ApplySelection(resultNodes, tail) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return tail is not null ? ApplySelection(resultNodes, tail) | |
return tail is not null | |
? ApplySelection(resultNodes, tail) |
@@ -159,11 +159,10 @@ private IEnumerable<ITestCaseData> GetTestCasesFor(IMethodInfo method) | |||
// single null argument will cause an error to be | |||
// reported at the test level, in most cases. | |||
// 2. User provided an ITestCaseData and we just use it. | |||
ITestCaseData? parms = item == null | |||
? new TestCaseParameters(new object?[] { null }) | |||
ITestCaseData? parms = item is null ? new TestCaseParameters(new object?[] { null }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ITestCaseData? parms = item is null ? new TestCaseParameters(new object?[] { null }) | |
ITestCaseData? parms = item is null | |
? new TestCaseParameters(new object?[] { null }) |
@mikkelbu I have fixed the CSharpIsNullAnalyzer CodeFix (locally) and re-applied the codefix. Now the existing formatting has been kept. |
Fixes #4378