diff --git a/.editorconfig b/.editorconfig index 8c68b86..3c889ed 100644 --- a/.editorconfig +++ b/.editorconfig @@ -42,7 +42,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members dotnet_style_coalesce_expression = true dotnet_style_collection_initializer = false 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_object_initializer = true dotnet_style_operator_placement_when_wrapping = beginning_of_line @@ -116,7 +116,7 @@ csharp_style_prefer_top_level_statements = true # Expression-level preferences csharp_prefer_simple_default_expression = 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_prefer_index_operator = 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.IDE0005.severity = error dotnet_diagnostic.IDE0008.severity = silent +dotnet_diagnostic.IDE0055.severity = silent dotnet_diagnostic.IDE0160.severity = none +dotnet_diagnostic.CA1707.severity = silent [.github/**/*.yml] charset = utf-8 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f24db4a..d744fce 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -19,7 +19,7 @@ jobs: run: dotnet build --no-restore src/DotTiled.sln - name: Test run: dotnet test --no-build --verbosity normal src/DotTiled.sln - - name: Lint - run: | - dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln - dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln + - name: Lint style + run: dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln + - name: Lint analyzers + run: dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln diff --git a/Makefile b/Makefile index 3790c68..c5fa89a 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ docs-build: lint: dotnet build src/DotTiled.sln - dotnet format style --verify-no-changes --verbosity diagnostic src/DotTiled.sln - dotnet format analyzers --verify-no-changes --verbosity diagnostic src/DotTiled.sln + dotnet format style --verify-no-changes src/DotTiled.sln + dotnet format analyzers --verify-no-changes src/DotTiled.sln BENCHMARK_SOURCES = DotTiled.Benchmark/Program.cs DotTiled.Benchmark/DotTiled.Benchmark.csproj BENCHMARK_OUTPUTDIR = DotTiled.Benchmark/BenchmarkDotNet.Artifacts diff --git a/src/DotTiled.Tests/Assert/AssertObject.cs b/src/DotTiled.Tests/Assert/AssertObject.cs index d982ebd..bc8e54c 100644 --- a/src/DotTiled.Tests/Assert/AssertObject.cs +++ b/src/DotTiled.Tests/Assert/AssertObject.cs @@ -24,30 +24,15 @@ public static partial class DotTiledAssert AssertObject((dynamic)expected, (dynamic)actual); } - private static void AssertObject(RectangleObject expected, RectangleObject actual) - { - Assert.True(true); // A rectangle object is the same as the abstract Object - } + private static void AssertObject(RectangleObject _, RectangleObject __) => Assert.True(true); // A rectangle object is the same as the abstract Object - private static void AssertObject(EllipseObject expected, EllipseObject actual) - { - Assert.True(true); // An ellipse object is the same as the abstract Object - } + private static void AssertObject(EllipseObject _, EllipseObject __) => Assert.True(true); // An ellipse object is the same as the abstract Object - private static void AssertObject(PointObject expected, PointObject actual) - { - Assert.True(true); // A point object is the same as the abstract Object - } + private static void AssertObject(PointObject _, PointObject __) => Assert.True(true); // A point object is the same as the abstract Object - private static void AssertObject(PolygonObject expected, PolygonObject actual) - { - AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points)); - } + private static void AssertObject(PolygonObject expected, PolygonObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolygonObject.Points)); - private static void AssertObject(PolylineObject expected, PolylineObject actual) - { - AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points)); - } + private static void AssertObject(PolylineObject expected, PolylineObject actual) => AssertEqual(expected.Points, actual.Points, nameof(PolylineObject.Points)); 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)); } - private static void AssertObject(TileObject expected, TileObject actual) - { - // Attributes - AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID)); - } + private static void AssertObject(TileObject expected, TileObject actual) => AssertEqual(expected.GID, actual.GID, nameof(TileObject.GID)); } diff --git a/src/DotTiled.Tests/Assert/AssertProperties.cs b/src/DotTiled.Tests/Assert/AssertProperties.cs index 16d9cdb..646d6eb 100644 --- a/src/DotTiled.Tests/Assert/AssertProperties.cs +++ b/src/DotTiled.Tests/Assert/AssertProperties.cs @@ -28,40 +28,19 @@ public static partial class DotTiledAssert AssertProperties((dynamic)actual, (dynamic)expected); } - private static void AssertProperty(StringProperty expected, StringProperty actual) - { - AssertEqual(expected.Value, actual.Value, "StringProperty.Value"); - } + private static void AssertProperty(StringProperty expected, StringProperty actual) => AssertEqual(expected.Value, actual.Value, "StringProperty.Value"); - private static void AssertProperty(IntProperty expected, IntProperty actual) - { - AssertEqual(expected.Value, actual.Value, "IntProperty.Value"); - } + private static void AssertProperty(IntProperty expected, IntProperty actual) => AssertEqual(expected.Value, actual.Value, "IntProperty.Value"); - private static void AssertProperty(FloatProperty expected, FloatProperty actual) - { - AssertEqual(expected.Value, actual.Value, "FloatProperty.Value"); - } + private static void AssertProperty(FloatProperty expected, FloatProperty actual) => AssertEqual(expected.Value, actual.Value, "FloatProperty.Value"); - private static void AssertProperty(BoolProperty expected, BoolProperty actual) - { - AssertEqual(expected.Value, actual.Value, "BoolProperty.Value"); - } + private static void AssertProperty(BoolProperty expected, BoolProperty actual) => AssertEqual(expected.Value, actual.Value, "BoolProperty.Value"); - private static void AssertProperty(ColorProperty expected, ColorProperty actual) - { - AssertEqual(expected.Value, actual.Value, "ColorProperty.Value"); - } + private static void AssertProperty(ColorProperty expected, ColorProperty actual) => AssertEqual(expected.Value, actual.Value, "ColorProperty.Value"); - private static void AssertProperty(FileProperty expected, FileProperty actual) - { - AssertEqual(expected.Value, actual.Value, "FileProperty.Value"); - } + private static void AssertProperty(FileProperty expected, FileProperty actual) => AssertEqual(expected.Value, actual.Value, "FileProperty.Value"); - private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) - { - AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value"); - } + private static void AssertProperty(ObjectProperty expected, ObjectProperty actual) => AssertEqual(expected.Value, actual.Value, "ObjectProperty.Value"); private static void AssertProperty(ClassProperty expected, ClassProperty actual) { diff --git a/src/DotTiled.Tests/Serialization/TestData.cs b/src/DotTiled.Tests/Serialization/TestData.cs index c36cab5..f6e49b5 100644 --- a/src/DotTiled.Tests/Serialization/TestData.cs +++ b/src/DotTiled.Tests/Serialization/TestData.cs @@ -32,49 +32,14 @@ public static partial class TestData public static IEnumerable MapTests => [ - ["Serialization/TestData/Map/default_map/default-map", (string f) => TestData.DefaultMap(), Array.Empty()], - ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => TestData.MapWithCommonProps(), Array.Empty()], - ["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => TestData.MapWithCustomTypeProps(), TestData.MapWithCustomTypePropsCustomTypeDefinitions()], - ["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => TestData.MapWithEmbeddedTileset(), Array.Empty()], - ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => TestData.MapWithExternalTileset(f), Array.Empty()], - ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => TestData.MapWithFlippingFlags(f), Array.Empty()], - ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => TestData.MapExternalTilesetMulti(f), Array.Empty()], - ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => TestData.MapExternalTilesetWangset(f), Array.Empty()], - ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => TestData.MapWithManyLayers(f), Array.Empty()], - ]; - - 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 = [] - } - ] - } + ["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty()], + ["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty()], + ["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) => MapWithEmbeddedTileset(), Array.Empty()], + ["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty()], + ["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty()], + ["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty()], ]; } diff --git a/src/DotTiled/Serialization/Tmj/ExtensionsJsonElement.cs b/src/DotTiled/Serialization/Tmj/ExtensionsJsonElement.cs index 7717df4..0e76d84 100644 --- a/src/DotTiled/Serialization/Tmj/ExtensionsJsonElement.cs +++ b/src/DotTiled/Serialization/Tmj/ExtensionsJsonElement.cs @@ -9,9 +9,10 @@ internal static class ExtensionsJsonElement { internal static T GetRequiredProperty(this JsonElement element, string propertyName) { - return !element.TryGetProperty(propertyName, out var property) - ? throw new JsonException($"Missing required property '{propertyName}'.") - : property.GetValueAs(); + if (!element.TryGetProperty(propertyName, out var property)) + throw new JsonException($"Missing required property '{propertyName}'."); + + return property.GetValueAs(); } internal static T GetOptionalProperty(this JsonElement element, string propertyName, T defaultValue)