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

Replace Newtonsoft.Json with System.Text.Json #23

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
root = true

###############################
# Core EditorConfig Options #
###############################
Expand All @@ -8,11 +10,14 @@
indent_style = space

[*.{csproj,xml,runsettings}]
indent_style = space
indent_size = 2
tab_size = 2

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
tab_size = 4
insert_final_newline = true
charset = utf-8

Expand Down Expand Up @@ -72,7 +77,7 @@ csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true
csharp_style_var_elsewhere = true
# Expression-bodied members
csharp_style_expression_bodied_methods = false:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:suggestion
csharp_style_expression_bodied_operators = false:suggestion
csharp_style_expression_bodied_properties = true:suggestion
Expand Down Expand Up @@ -122,3 +127,6 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

# IDE0022: Use block body for method
dotnet_diagnostic.IDE0022.severity = silent
2 changes: 1 addition & 1 deletion src/DendroDocs.Tool/Analyzers/SourceAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private bool ProcessedEmbeddedType(SyntaxNode node)
return true;
}

private void ExtractAttributes(SyntaxList<AttributeListSyntax> attributes, List<IAttributeDescription> attributeDescriptions)
private void ExtractAttributes(SyntaxList<AttributeListSyntax> attributes, List<AttributeDescription> attributeDescriptions)
{
foreach (var attribute in attributes.SelectMany(a => a.Attributes))
{
Expand Down
19 changes: 9 additions & 10 deletions src/DendroDocs.Tool/DendroDocs.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@
<EmbeddedResource Include="schema.json" />
</ItemGroup>

<ItemGroup>
<Using Include="CommandLine" />
<Using Include="DendroDocs.Extensions" />
<Using Include="DendroDocs.Json" />
<Using Include="Microsoft.CodeAnalysis" />
<Using Include="Microsoft.CodeAnalysis.CSharp" />
<Using Include="Microsoft.CodeAnalysis.CSharp.Syntax" />
</ItemGroup>
<ItemGroup>
<Using Include="CommandLine" />
<Using Include="DendroDocs.Extensions" />
<Using Include="DendroDocs.Json" />
<Using Include="Microsoft.CodeAnalysis" />
<Using Include="Microsoft.CodeAnalysis.CSharp" />
<Using Include="Microsoft.CodeAnalysis.CSharp.Syntax" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Buildalyzer.Workspaces" Version="7.0.2" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="DendroDocs.Shared" Version="0.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="DendroDocs.Shared" Version="0.2.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.11.0" />
Expand Down
8 changes: 4 additions & 4 deletions src/DendroDocs.Tool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Diagnostics;
using System.Text.Json;

namespace DendroDocs.Tool;

Expand Down Expand Up @@ -39,10 +39,10 @@ private static async Task<int> RunApplicationAsync(Options options)
stopwatch.Stop();

// Write analysis
var serializerSettings = JsonDefaults.SerializerSettings();
serializerSettings.Formatting = options.PrettyPrint ? Formatting.Indented : Formatting.None;
var serializerSettings = JsonDefaults.SerializerOptions();
serializerSettings.WriteIndented = options.PrettyPrint;

var result = JsonConvert.SerializeObject(types.OrderBy(t => t.FullName), serializerSettings);
var result = JsonSerializer.Serialize(types.OrderBy(t => t.FullName), serializerSettings);
File.WriteAllText(options.OutputPath!, result);

if (!options.Quiet)
Expand Down
34 changes: 17 additions & 17 deletions tests/DendroDocs.Tool.Tests/DeserializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DendroDocs.Json;
using Newtonsoft.Json;
using System.Text.Json;

namespace DendroDocs.Tool.Tests;

Expand All @@ -13,7 +13,7 @@ public void NoTypes_Should_GiveEmptyArray()
var json = @"[]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types.Should().BeEmpty();
Expand All @@ -26,7 +26,7 @@ public void AClassWithoutAModifierShouldBeInternalByDefault()
var json = @"[{""FullName"":""Test""}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types.Should().HaveCount(1);
Expand All @@ -43,7 +43,7 @@ public void Collections_Should_NotBeNull()
var json = @"[{""FullName"":""Test""}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Fields.Should().BeEmpty();
Expand Down Expand Up @@ -78,7 +78,7 @@ public void ModifiersShouldBeDeserializedCorrectly(int value, Modifier modifier)
var json = @$"[{{""Modifiers"":{value},""FullName"":""Test""}}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Modifiers.Should().Be(modifier);
Expand All @@ -91,7 +91,7 @@ public void MembersOfAClassWithoutAModifierShouldBePrivateByDefault()
var json = @"[{""FullName"":""Test"",""Methods"":[{""Name"":""Method""}]}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods.Should().HaveCount(1);
Expand All @@ -107,7 +107,7 @@ public void AttributeCollection_Should_GiveAttributeWithNameAndType()
var json = @"[{""FullName"":""Test"",""Attributes"":[{""Type"":""System.ObsoleteAttribute"",""Name"":""System.Obsolete""}]}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Attributes.Should().HaveCount(1);
Expand All @@ -123,7 +123,7 @@ public void AttributeArgumentCollection_Should_GiveAttributeArgumentWithName_Typ
var json = @"[{""FullName"":""Test"",""Attributes"":[{""Type"":""System.ObsoleteAttribute"",""Name"":""System.Obsolete"",""Arguments"":[{""Name"":""\""Reason\"""",""Type"":""string"",""Value"":""Reason""}]}]}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Attributes[0].Arguments.Should().HaveCount(1);
Expand All @@ -150,7 +150,7 @@ public void AStatementInAMethodBodyShouldHaveTheMethodAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Parent.Should().Be(types[0].Methods[0]);
Expand All @@ -173,7 +173,7 @@ public void AStatementInAConstructorBodyShouldHaveTheConstructorAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Constructors[0].Statements[0].Parent.Should().Be(types[0].Constructors[0]);
Expand All @@ -195,7 +195,7 @@ public void AnIfElseSectionShouldHaveTheIfAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<If>();
Expand All @@ -220,7 +220,7 @@ public void AnIfElseConditionShouldBeParsedCorrectly()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<If>();
Expand Down Expand Up @@ -251,7 +251,7 @@ public void AStatementInAnIfElseSectionShouldHaveTheIfElseSectionAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<If>();
Expand All @@ -276,7 +276,7 @@ public void ASwitchSectionShouldHaveTheSwitchAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<Switch>();
Expand All @@ -301,7 +301,7 @@ public void ASwitchExpressionShouldBeParsedCorrectly()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<Switch>();
Expand All @@ -328,7 +328,7 @@ public void SwitchLabelsShouldBeParsedCorrectly()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<Switch>();
Expand Down Expand Up @@ -360,7 +360,7 @@ public void AStatementInASwitchSectionShouldHaveTheSwitchSectionAsParent()
}]";

// Act
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings());
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;

// Assert
types[0].Methods[0].Statements[0].Should().BeOfType<Switch>();
Expand Down
Loading
Loading