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

Enable IDE2xxx experimental rules #6353

Merged
merged 10 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ dotnet_diagnostic.IDE0130.severity = silent
# IDE0150: Null check can be clarified
dotnet_diagnostic.IDE0150.severity = silent

# IDE2000: Allow multiple blank lines
dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = warning
mavasani marked this conversation as resolved.
Show resolved Hide resolved

# IDE2001: Embedded statements must be on their own line
csharp_style_allow_embedded_statements_on_same_line_experimental = false
dotnet_diagnostic.IDE2001.severity = warning

# IDE2002: Consecutive braces must not have blank line between them
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
dotnet_diagnostic.IDE2002.severity = silent

# IDE2003: Blank line required between block and subsequent statement
dotnet_style_allow_statement_immediately_after_block_experimental = false
dotnet_diagnostic.IDE2003.severity = silent

# IDE2004: Blank line not allowed after constructor initializer colon
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
dotnet_diagnostic.IDE2004.severity = silent

### Configuration for FxCop analyzers executed on this repo ###
[*.{cs,vb}]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ protected override bool IsInterestingTrivia(SyntaxTriviaList triviaList)
ns = qualifiedNamespaceSyntax.ToFullString();
}


return ns;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ private static void AnalyzeCompilationStart(CompilationStartAnalysisContext csCo
var symbol = (INamedTypeSymbol)saContext.Symbol;

// skip public symbols
if (symbol.IsPublic()) return;
if (symbol.IsPublic())
return;

// only report if base type matches
if (symbol.BaseType != null && exceptionTypes.Contains(symbol.BaseType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ private static void OnMethodSymbol(SymbolAnalysisContext context, ConstantExpect
CheckParameters(methodSymbol.Parameters, interfaceMethodSymbol.Parameters);
}


void CheckParameters(ImmutableArray<IParameterSymbol> parameters, ImmutableArray<IParameterSymbol> baseParameters)
{
if (constantExpectedContext.ValidatesAttributeImplementedFromParent(parameters, baseParameters, out var diagnostics))
Expand Down Expand Up @@ -570,7 +569,6 @@ public static AttributeConstant Get(AttributeData attributeData)
}
}


protected abstract class DiagnosticHelper
{
public abstract Location? GetMinLocation(SyntaxNode attributeSyntax);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private static bool TryGetVariableInitializerOperation(IOperation symbol, [NotNu
default:
variableInitializerOperation = null;
return false;
};
}
}

private static Diagnostic CreateDiagnostics(IInvocationOperation computeHashMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public override void Initialize(AnalysisContext context)
}

// Only validate libraries (which will still produce some false positives, but that is acceptable)
if (context.Compilation.Options.OutputKind != OutputKind.DynamicallyLinkedLibrary) return;
if (context.Compilation.Options.OutputKind != OutputKind.DynamicallyLinkedLibrary)
return;

context.RegisterSymbolAction(context =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ private static bool InspectAndReportBlockingMemberAccess(OperationAnalysisContex

foreach (SyncBlockingSymbol symbol in syncBlockingSymbols)
{
if (symbol.Kind != kind) continue;
if (symbol.Kind != kind)
continue;
if (symbol.Value.Equals(memberSymbol.OriginalDefinition))
{
Diagnostic diagnostic = context.Operation.Syntax.CreateDiagnostic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ static HashSet<ITypeSymbol> GetAssociatedTypes(ITypeSymbol type)
// graph: The graph
void AddLine(ISymbol from, ISymbol to, ConcurrentDictionary<ISymbol, int> degree, ConcurrentDictionary<ISymbol, ConcurrentDictionary<ISymbol, bool>> graph)
{
graph.AddOrUpdate(from, new ConcurrentDictionary<ISymbol, bool> { [to] = true }, (k, v) => { v[to] = true; return v; });
graph.AddOrUpdate(from, new ConcurrentDictionary<ISymbol, bool> { [to] = true }, (k, v) =>
{
v[to] = true;
return v;
});
degree.AddOrUpdate(from, 1, (k, v) => v + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,6 @@ End Module
await VerifyVisualBasicAsync(vbCode);
}


[Theory]
[InlineData("HashSet")]
[InlineData("LinkedList")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class C
await VerifyCSAnalyzerAsync(source);
}


[Fact]
public async Task VB_PInvokeWithClassReturnValue_Emits_Diagnostic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void ObsoletedOnLinux4AndWindows10() { }
await VerifyAnalyzerCSAsync(csSource, VerifyCS.Diagnostic(PlatformCompatibilityAnalyzer.ObsoletedCsReachable).WithLocation(0)
.WithArguments("Test.ObsoletedOnLinux4()", "'Linux' 4.1 and later", "'Linux'"));


var vbSource = @"
Imports System
Imports System.Runtime.Versioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public class Test
await VerifyAnalyzerCSAsync(csSource, "build_property.PlatformNeutralAssembly = true\nbuild_property.TargetFramework=net5.0");
}


[Fact]
public async Task OnlyThrowsNotSupportedWithOsDependentStringNotWarnsAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ public static int GetNumberOfLines(string source)
{
var numberOfLines = 0;
var index = -Environment.NewLine.Length;
while ((index = source.IndexOf(Environment.NewLine, index + Environment.NewLine.Length, StringComparison.Ordinal)) >= 0) numberOfLines++;
while ((index = source.IndexOf(Environment.NewLine, index + Environment.NewLine.Length, StringComparison.Ordinal)) >= 0)
numberOfLines++;
return numberOfLines;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public C(IReadOnlyList<int> l)
{{|CS0201:l.Count|}};
{csharpFirstOrDefaultAndLastOrDefault}
}}
}}"; ;
}}";

var csharpTest = new VerifyCS.Test
{
Expand Down Expand Up @@ -454,7 +454,8 @@ End Sub

Private Sub Use(Of U)(p As U)
End Sub
End Class"; ;
End Class";

var vbTest = new VerifyVB.Test
{
TestState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ void M(T arg)
}.RunAsync();
}


[Fact]
public async Task ArgumentNullExceptionThrowIfNull_EnsureSystemIsUsed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,3 @@ private static VerifyCS.Test PopulateTestCs(string sourceCode, params Diagnostic
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public sealed partial class DeclarePublicApiAnalyzer : DiagnosticAnalyzer
private const string BailOnMissingPublicApiFilesEditorConfigOptionName = $"{BaseEditorConfigPath}.require_api_files";
private const string NamespaceToIgnoreInTrackingEditorConfigOptionName = $"{BaseEditorConfigPath}.skip_namespaces";


internal static readonly SymbolDisplayFormat ShortSymbolNameFormat =
new(
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.OmittedAsContaining,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ public static bool HasFewerThan<TSource>(this IEnumerable<TSource> source, int c
}

using var enumerator = source.GetEnumerator();
while (count > 0 && enumerator.MoveNext()) { count--; }
while (count > 0 && enumerator.MoveNext())
{
count--;
}

return count > 0;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Utilities/Compiler/Options/AnalyzerOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ SymbolNamesWithValueOption<TValue> GetDefaultValue()

var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(compilation);
return analyzerConfigOptions.GetOptionValue(optionName, tree, rule: null,
tryParseValue: (string value, out string? result) => { result = value; return true; },
tryParseValue: (string value, out string? result) =>
{
result = value;
return true;
},
defaultValue: null, OptionKind.BuildProperty);
}

Expand All @@ -532,7 +536,11 @@ public static ImmutableArray<string> GetMSBuildItemMetadataValues(
var propertyOptionName = MSBuildItemOptionNamesHelpers.GetPropertyNameForItemOptionName(itemOptionName);
var analyzerConfigOptions = options.GetOrComputeCategorizedAnalyzerConfigOptions(compilation);
var propertyValue = analyzerConfigOptions.GetOptionValue(propertyOptionName, tree, rule: null,
tryParseValue: (string value, out string? result) => { result = value; return true; },
tryParseValue: (string value, out string? result) =>
{
result = value;
return true;
},
defaultValue: null, OptionKind.BuildProperty);
return MSBuildItemOptionNamesHelpers.ParseItemOptionValue(propertyValue);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Utilities/Compiler/SmallDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private static AvlNode MinValueNode(AvlNode node)

private static int Height(AvlNode? node)
{
if (node == null) return 0;
if (node == null)
return 0;

int a = Height(node.Left);
int b = Height(node.Right);
Expand Down Expand Up @@ -290,7 +291,8 @@ public AvlNode(int hashCode, K key, V value)
public static int AssertBalanced(AvlNode? V)
#pragma warning restore CA1000 // Do not declare static members on generic types
{
if (V == null) return 0;
if (V == null)
return 0;

int a = AssertBalanced(V.Left);
int b = AssertBalanced(V.Right);
Expand Down