Consistently use 'is null' and 'is not null' iso '== null' and '!= null'#4379
Conversation
mikkelbu
left a comment
There was a problem hiding this comment.
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.
Unrelated to your change, but this is an odd (read: wrong) IComparer
| 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.
| Type.GetType("Mono.Runtime", false) is not null ? RuntimeType.Mono | |
| Type.GetType("Mono.Runtime", false) is not null | |
| ? RuntimeType.Mono |
|
|
||
| var testFile = _testAssembly != null | ||
| ? AssemblyHelper.GetAssemblyPath(_testAssembly) | ||
| var testFile = _testAssembly is not null ? AssemblyHelper.GetAssemblyPath(_testAssembly) |
There was a problem hiding this comment.
| 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.
I think we should keep the existing formatting
There was a problem hiding this comment.
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
| { | ||
| string display = arg == null | ||
| ? "null" | ||
| string display = arg is null ? "null" |
There was a problem hiding this comment.
| string display = arg is null ? "null" | |
| string display = arg is null | |
| ? "null" |
| { | ||
| return Assembly != null | ||
| ? Assembly.GetAttributes<TAttr>() | ||
| return Assembly is not null ? Assembly.GetAttributes<TAttr>() |
There was a problem hiding this comment.
| return Assembly is not null ? Assembly.GetAttributes<TAttr>() | |
| return Assembly is not null | |
| ? Assembly.GetAttributes<TAttr>() |
| { | ||
| Event? e = _events.Dequeue( PumpState == EventPumpState.Pumping ); | ||
| if ( e == null ) | ||
| if ( e is null) |
There was a problem hiding this comment.
| if ( e is null) | |
| if (e is null) |
|
|
||
| return tail != null | ||
| ? ApplySelection(resultNodes, tail) | ||
| return tail is not null ? ApplySelection(resultNodes, tail) |
There was a problem hiding this comment.
| return tail is not null ? ApplySelection(resultNodes, tail) | |
| return tail is not null | |
| ? ApplySelection(resultNodes, tail) |
| // 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.
| 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