-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d338d0d
commit 34d8bc8
Showing
3 changed files
with
59 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 33 additions & 5 deletions
38
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/MemberInitializerRedundant.CSharp12.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
/// Reproducer for https://github.com/SonarSource/sonar-dotnet/issues/7624 | ||
class WithPrimaryConstructor(object options) | ||
{ | ||
private readonly object _options = options; // Compliant | ||
public object Options { get; } = options; // Compliant | ||
public object[] AllOptions { get; } = [options]; // Compliant | ||
} | ||
|
||
class WithReferencedPrimaryConstructor(object options) | ||
{ | ||
public WithReferencedPrimaryConstructor() : this(null) | ||
{ | ||
|
||
} | ||
private readonly object _options = options; // Compliant | ||
} | ||
|
||
/// Reproducer for https://github.com/SonarSource/sonar-dotnet/issues/7624 | ||
class SampleClass(object options) | ||
class WithPrimaryConstructorAndAssignment(object options) | ||
{ | ||
private readonly object _options = options; // Noncompliant FP | ||
public WithPrimaryConstructorAndAssignment() : this(null) | ||
{ | ||
_options = null; | ||
} | ||
private readonly object _options = options; // Compliant | ||
} | ||
|
||
class CollectionExpression1 | ||
{ | ||
private readonly int[] numbers = [1, 2, 3]; // Noncompliant | ||
// ^^^^^^^^^^^ | ||
|
||
CollectionExpression1() | ||
{ | ||
numbers = [4, 5, 6]; | ||
} | ||
} |