More lint fixing

This commit is contained in:
Daniel Cronqvist 2024-08-22 21:12:16 +02:00
parent bb8c3a133c
commit b6721934e4
7 changed files with 36 additions and 108 deletions

View file

@ -42,7 +42,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_coalesce_expression = true dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = false dotnet_style_collection_initializer = false
dotnet_style_explicit_tuple_names = true dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true dotnet_style_namespace_match_folder = false
dotnet_style_null_propagation = true dotnet_style_null_propagation = true
dotnet_style_object_initializer = true dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line dotnet_style_operator_placement_when_wrapping = beginning_of_line
@ -116,7 +116,7 @@ csharp_style_prefer_top_level_statements = true
# Expression-level preferences # Expression-level preferences
csharp_prefer_simple_default_expression = true csharp_prefer_simple_default_expression = true
csharp_style_deconstructed_variable_declaration = true csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true csharp_style_implicit_object_creation_when_type_is_apparent = false
csharp_style_inlined_variable_declaration = true csharp_style_inlined_variable_declaration = true
csharp_style_prefer_index_operator = true csharp_style_prefer_index_operator = true
csharp_style_prefer_local_over_anonymous_function = true csharp_style_prefer_local_over_anonymous_function = true
@ -234,7 +234,9 @@ dotnet_diagnostic.IDE0001.severity = none
dotnet_diagnostic.IDE0004.severity = silent dotnet_diagnostic.IDE0004.severity = silent
dotnet_diagnostic.IDE0005.severity = error dotnet_diagnostic.IDE0005.severity = error
dotnet_diagnostic.IDE0008.severity = silent dotnet_diagnostic.IDE0008.severity = silent
dotnet_diagnostic.IDE0055.severity = silent
dotnet_diagnostic.IDE0160.severity = none dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.CA1707.severity = silent
[.github/**/*.yml] [.github/**/*.yml]
charset = utf-8 charset = utf-8

View file

@ -19,7 +19,7 @@ jobs:
run: dotnet build --no-restore src/DotTiled.sln run: dotnet build --no-restore src/DotTiled.sln
- name: Test - name: Test
run: dotnet test --no-build --verbosity normal src/DotTiled.sln run: dotnet test --no-build --verbosity normal src/DotTiled.sln
- name: Lint - name: Lint style
run: | run: dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln
dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln - name: Lint analyzers
dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln run: dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln

View file

@ -11,8 +11,8 @@ docs-build:
lint: lint:
dotnet build src/DotTiled.sln dotnet build src/DotTiled.sln
dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln dotnet format style --verify-no-changes src/DotTiled.sln
dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln dotnet format analyzers --verify-no-changes src/DotTiled.sln
BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj
BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts

View file

@ -24,30 +24,15 @@ public static partial class DotTiledAssert
AssertObject((dynamic)expected, (dynamic)actual); AssertObject((dynamic)expected, (dynamic)actual);
} }
private static void AssertObject(RectangleObject expected, RectangleObject actual) private static void AssertObject(RectangleObject _, RectangleObject __) => Assert.True(true); // A rectangle object is the same as the abstract Object
{
Assert.True(true); // A rectangle object is the same as the abstract Object
}
private static void AssertObject(EllipseObject expected, EllipseObject actual) private static void AssertObject(EllipseObject _, EllipseObject __) => Assert.True(true); // An ellipse object is the same as the abstract Object
{
Assert.True(true); // An ellipse object is the same as the abstract Object
}
private static void AssertObject(PointObject expected, PointObject actual) private static void AssertObject(PointObject _, PointObject __) => Assert.True(true); // A point object is the same as the abstract Object
{
Assert.True(true); // A point object is the same as the abstract Object
}
private static void AssertObject(PolygonObject expected, PolygonObject actual) private static void AssertObject(PolygonObject expected, PolygonObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points));
{
AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points));
}
private static void AssertObject(PolylineObject expected, PolylineObject actual) private static void AssertObject(PolylineObject expected, PolylineObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points));
{
AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points));
}
private static void AssertObject(TextObject expected, TextObject actual) private static void AssertObject(TextObject expected, TextObject actual)
{ {
@ -67,9 +52,5 @@ public static partial class DotTiledAssert
AssertEqual(expected.Text, actual.Text, nameof(TextObject.Text)); AssertEqual(expected.Text, actual.Text, nameof(TextObject.Text));
} }
private static void AssertObject(TileObject expected, TileObject actual) private static void AssertObject(TileObject expected, TileObject actual) => AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID));
{
// Attributes
AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID));
}
} }

View file

@ -28,40 +28,19 @@ public static partial class DotTiledAssert
AssertProperties((dynamic)actual, (dynamic)expected); AssertProperties((dynamic)actual, (dynamic)expected);
} }
private static void AssertProperty(StringProperty expected, StringProperty actual) private static void AssertProperty(StringProperty expected, StringProperty actual) => AssertEqual(expected.Value, actual.Value, "StringProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "StringProperty.Value");
}
private static void AssertProperty(IntProperty expected, IntProperty actual) private static void AssertProperty(IntProperty expected, IntProperty actual) => AssertEqual(expected.Value, actual.Value, "IntProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "IntProperty.Value");
}
private static void AssertProperty(FloatProperty expected, FloatProperty actual) private static void AssertProperty(FloatProperty expected, FloatProperty actual) => AssertEqual(expected.Value, actual.Value, "FloatProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "FloatProperty.Value");
}
private static void AssertProperty(BoolProperty expected, BoolProperty actual) private static void AssertProperty(BoolProperty expected, BoolProperty actual) => AssertEqual(expected.Value, actual.Value, "BoolProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "BoolProperty.Value");
}
private static void AssertProperty(ColorProperty expected, ColorProperty actual) private static void AssertProperty(ColorProperty expected, ColorProperty actual) => AssertEqual(expected.Value, actual.Value, "ColorProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "ColorProperty.Value");
}
private static void AssertProperty(FileProperty expected, FileProperty actual) private static void AssertProperty(FileProperty expected, FileProperty actual) => AssertEqual(expected.Value, actual.Value, "FileProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "FileProperty.Value");
}
private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) => AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value");
{
AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value");
}
private static void AssertProperty(ClassProperty expected, ClassProperty actual) private static void AssertProperty(ClassProperty expected, ClassProperty actual)
{ {

View file

@ -32,49 +32,14 @@ public static partial class TestData
public static IEnumerable<object[]> MapTests => public static IEnumerable<object[]> MapTests =>
[ [
["Serialization/TestData/Map/default_map/default-map", (string f) => TestData.DefaultMap(), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => TestData.MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => TestData.MapWithCustomTypeProps(), TestData.MapWithCustomTypePropsCustomTypeDefinitions()], ["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => TestData.MapWithEmbeddedTileset(), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => MapWithEmbeddedTileset(), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => TestData.MapWithExternalTileset(f), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => TestData.MapWithFlippingFlags(f), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => TestData.MapExternalTilesetMulti(f), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => TestData.MapExternalTilesetWangset(f), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty<CustomTypeDefinition>()],
["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => TestData.MapWithManyLayers(f), Array.Empty<CustomTypeDefinition>()], ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty<CustomTypeDefinition>()],
];
private static CustomTypeDefinition[] typedefs = [
new CustomClassDefinition
{
Name = "TestClass",
ID = 1,
UseAs = CustomClassUseAs.Property,
Members = [
new StringProperty
{
Name = "Name",
Value = ""
},
new FloatProperty
{
Name = "Amount",
Value = 0f
}
]
},
new CustomClassDefinition
{
Name = "Test",
ID = 2,
UseAs = CustomClassUseAs.All,
Members = [
new ClassProperty
{
Name = "Yep",
PropertyType = "TestClass",
Properties = []
}
]
}
]; ];
} }

View file

@ -9,9 +9,10 @@ internal static class ExtensionsJsonElement
{ {
internal static T GetRequiredProperty<T>(this JsonElement element, string propertyName) internal static T GetRequiredProperty<T>(this JsonElement element, string propertyName)
{ {
return !element.TryGetProperty(propertyName, out var property) if (!element.TryGetProperty(propertyName, out var property))
? throw new JsonException($"Missing required property '{propertyName}'.") throw new JsonException($"Missing required property '{propertyName}'.");
: property.GetValueAs<T>();
return property.GetValueAs<T>();
} }
internal static T GetOptionalProperty<T>(this JsonElement element, string propertyName, T defaultValue) internal static T GetOptionalProperty<T>(this JsonElement element, string propertyName, T defaultValue)