Skip to content

Commit

Permalink
Package updates and primary constructors fix (#156)
Browse files Browse the repository at this point in the history
* Update Resharper
* Package updates
* Run tests against .NET 8, update to latest C# version
* Resharper: use file-scoped namespaces
* Resharper: use target-typed new
* Resharper: use collection expression
* Resharper: use raw string
* Resharper: use pattern syntax
* Resharper: use primary constructor
* Resharper: make struct readonly
* Resharper: remove redundant discard
* Resharper: remove redundant casts
* Resharper: reformat solution
* Fixed AV1500: Do not report on captured variables from primary constructor initializer
  • Loading branch information
bkoelman committed Apr 20, 2024
1 parent e84590e commit 8aab990
Show file tree
Hide file tree
Showing 171 changed files with 11,555 additions and 11,817 deletions.
50 changes: 42 additions & 8 deletions src/CSharpGuidelinesAnalyzer.sln.DotSettings

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net60</TargetFramework>
<TargetFramework>net80</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DefineConstants>TRACE;RELEASE;JETBRAINS_ANNOTATIONS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.4" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.console" Version="2.6.6" PrivateAssets="all" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.console" Version="2.7.1" PrivateAssets="all" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private async Task<CompilationWithAnalyzers> GetCompilationWithAnalyzersAsync(Do
ValidateCompileErrors(compilerDiagnostics);
}

ImmutableArray<DiagnosticAnalyzer> analyzers = ImmutableArray.Create(analyzer);
ImmutableArray<DiagnosticAnalyzer> analyzers = [analyzer];
return compilation.WithAnalyzers(analyzers, options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static ImmutableHashSet<MetadataReference> ResolveDefaultReferences()
string assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location)!;

string[] assemblies =
{
[
typeof(object).Assembly.Location, // System.Private.CoreLib.dll
typeof(BitArray).Assembly.Location, // System.Collections.dll
typeof(IImmutableList<>).Assembly.Location, // System.Collections.Immutable.dll
Expand All @@ -72,7 +72,7 @@ private static ImmutableHashSet<MetadataReference> ResolveDefaultReferences()
typeof(DynamicAttribute).Assembly.Location, // System.Linq.Expressions.dll
typeof(IPAddress).Assembly.Location, // System.Net.Primitives.dll
Path.Combine(assemblyPath, "System.Runtime.dll")
};
];

return assemblies.Select(assembly => (MetadataReference)MetadataReference.CreateFromFile(assembly)).ToImmutableHashSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ public static Document ToDocument(string code, AnalyzerTestContext context)
ParseOptions parseOptions = GetParseOptions(context.DocumentationMode);
CompilationOptions compilationOptions = GetCompilationOptions(context);

Document document = new AdhocWorkspace()
// @formatter:wrap_chained_method_calls chop_always
// @formatter:wrap_before_first_method_call true

return new AdhocWorkspace()
.AddProject(context.AssemblyName, LanguageNames.CSharp)
.WithParseOptions(parseOptions)
.WithCompilationOptions(compilationOptions)
.AddMetadataReferences(context.References)
.AddDocument(context.FileName, code);

return document;
// @formatter:wrap_before_first_method_call restore
// @formatter:wrap_chained_method_calls restore
}

private static ParseOptions GetParseOptions(DocumentationMode documentationMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,19 @@ private sealed class MarkupParser
private const int SpanTextLength = 2;

private static readonly char[] SpanKinds =
{
[
'|',
'+',
'-',
'*'
};
];

private static readonly string[] ReplaceSeparatorArray =
{
ReplaceSeparator
};
private static readonly string[] ReplaceSeparatorArray = [ReplaceSeparator];

private readonly string markupCode;

public IList<TextBlock> TextBlocks { get; } = new List<TextBlock>();
public IList<TextSpan> TextSpans { get; } = new List<TextSpan>();
public IList<TextBlock> TextBlocks { get; } = [];
public IList<TextSpan> TextSpans { get; } = [];

public MarkupParser(string markupCode)
{
Expand Down Expand Up @@ -352,65 +349,40 @@ protected TextBlock(string textBefore, string textAfter)
}
}

private sealed class StaticTextBlock : TextBlock
private sealed class StaticTextBlock(string text) : TextBlock(text, text)
{
public StaticTextBlock(string text)
: base(text, text)
{
}

public override string ToString()
{
return TextBefore;
}
}

private sealed class MarkedTextBlock : TextBlock
private sealed class MarkedTextBlock(string textToMark) : TextBlock(textToMark, textToMark)
{
public MarkedTextBlock(string textToMark)
: base(textToMark, textToMark)
{
}

public override string ToString()
{
return "|" + TextAfter;
}
}

private sealed class InsertedTextBlock : TextBlock
private sealed class InsertedTextBlock(string textToInsert) : TextBlock(string.Empty, textToInsert)
{
public InsertedTextBlock(string textToInsert)
: base(string.Empty, textToInsert)
{
}

public override string ToString()
{
return "+" + TextAfter;
}
}

private sealed class DeletedTextBlock : TextBlock
private sealed class DeletedTextBlock(string textToDelete) : TextBlock(textToDelete, string.Empty)
{
public DeletedTextBlock(string textToDelete)
: base(textToDelete, string.Empty)
{
}

public override string ToString()
{
return "-" + TextBefore;
}
}

private sealed class ReplacedTextBlock : TextBlock
private sealed class ReplacedTextBlock(string textBefore, string textAfter) : TextBlock(textBefore, textAfter)
{
public ReplacedTextBlock(string textBefore, string textAfter)
: base(textBefore, textAfter)
{
}

public override string ToString()
{
return TextBefore + "=>" + TextAfter;
Expand Down
Loading

0 comments on commit 8aab990

Please sign in to comment.