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

Warnings as errors and compiler error cleanup #976

Merged
merged 1 commit into from
Sep 13, 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
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
</PropertyGroup>

<PropertyGroup>
<WarningLevel>9999</WarningLevel>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<LangVersion>12.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration) == 'Release'" Label="Code style enforcement">
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FakeItEasy" Version="6.2.1" />
<PackageVersion Include="FluentAssertions" Version="4.19.2" />
<PackageVersion Include="FSharp.Core" Version="8.0.400" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
Expand Down
38 changes: 19 additions & 19 deletions YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Reflection.Metadata" />
</ItemGroup>
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Reflection.Metadata" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\YamlDotNet\YamlDotNet.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YamlDotNet\YamlDotNet.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Resources\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Update="Resources\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
23 changes: 22 additions & 1 deletion YamlDotNet.Core7AoTCompileTest.Model/ExternalModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
namespace YamlDotNet.Core7AoTCompileTest.Model;
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

namespace YamlDotNet.Core7AoTCompileTest.Model;

public class ExternalModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<PublishAot>true</PublishAot>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<Nullable>enable</Nullable>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug-AOT|AnyCPU' ">
Expand All @@ -17,7 +16,6 @@
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<ItemGroup>
Expand Down
160 changes: 88 additions & 72 deletions YamlDotNet.Fsharp.Test/DeserializerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ open YamlDotNet.Serialization.NamingConventions
open System.ComponentModel

[<CLIMutable>]
type Spec = {
EngineType: string
DriveType: string
}
type Spec =
{
EngineType: string
DriveType: string
}

[<CLIMutable>]
type Car = {
Name: string
Year: int
Spec: Spec option
Nickname: string option
}
type Car =
{
Name: string
Year: int
Spec: Spec option
Nickname: string option
}

[<CLIMutable>]
type Person = {
Name: string
MomentOfBirth: DateTime
Cars: Car array
}
type Person =
{
Name: string
MomentOfBirth: DateTime
Cars: Car array
}

[<Fact>]
let Deserialize_YamlWithScalarOptions() =
let yaml = """
let Deserialize_YamlWithScalarOptions () =
let yaml =
"""
name: Jack
momentOfBirth: 1983-04-21T20:21:03.0041599Z
cars:
Expand All @@ -40,21 +44,24 @@ cars:
- name: Honda
year: 2021
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let sut =
DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<Person>(yaml)
Assert.Equal("Jack", person.Name)
Assert.Equal(2, person.Cars.Length)
Assert.Equal("Mercedes", person.Cars[0].Name)
Assert.Equal(Some "Jessy", person.Cars[0].Nickname)// |> should equal (Some "Jessy")
Assert.Equal(Some "Jessy", person.Cars[0].Nickname) // |> should equal (Some "Jessy")
Assert.Equal("Honda", person.Cars[1].Name)
Assert.Equal(None, person.Cars[1].Nickname)

[<Fact>]
let Deserialize_YamlWithObjectOptions() =
let yaml = """
let Deserialize_YamlWithObjectOptions () =
let yaml =
"""
name: Jack
momentOfBirth: 1983-04-21T20:21:03.0041599Z
cars:
Expand All @@ -66,48 +73,56 @@ cars:
- name: Honda
year: 2021
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let sut =
DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<Person>(yaml)
Assert.Equal("Jack", person.Name)
Assert.Equal(2, person.Cars.Length)

Assert.Equal("Mercedes", person.Cars[0].Name)
Assert.NotNull(person.Cars[0].Spec)
Assert.True(person.Cars[0].Spec |> Option.isSome)
Assert.Equal("V6", person.Cars[0].Spec.Value.EngineType)
Assert.Equal("AWD", person.Cars[0].Spec.Value.DriveType)

Assert.Equal("Honda", person.Cars[1].Name)
Assert.Null(person.Cars[1].Spec)
Assert.Equal(None, person.Cars[1].Spec)
Assert.Equal(None, person.Cars[1].Nickname)


[<CLIMutable>]
type TestSeq = {
name: string
numbers: int seq
}
[<NoComparison>]
type TestSeq = { name: string; numbers: int seq }

[<Fact>]
let Deserialize_YamlSeq() =
let jackTheDriver = {
name = "Jack"
numbers = seq { 12; 2; 2 }
}

let yaml = """name: Jack
let Deserialize_YamlSeq () =
let jackTheDriver =
{
name = "Jack"
numbers =
seq {
12
2
2
}
}

let yaml =
"""name: Jack
numbers:
- 12
- 2
- 2
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let sut =
DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<TestSeq>(yaml)
Assert.Equal(jackTheDriver.name, person.name)
Expand All @@ -118,27 +133,28 @@ numbers:
Assert.Equal(2, numbers[2])

[<CLIMutable>]
type TestList = {
name: string
numbers: int list
}
type TestList = { name: string; numbers: int list }

[<Fact>]
let Deserialize_YamlList() =
let jackTheDriver = {
name = "Jack"
numbers = [ 12; 2; 2 ]
}

let yaml = """name: Jack
let Deserialize_YamlList () =
let jackTheDriver =
{
name = "Jack"
numbers = [ 12; 2; 2 ]
}

let yaml =
"""name: Jack
numbers:
- 12
- 2
- 2
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let sut =
DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<TestList>(yaml)
Assert.Equal(jackTheDriver.name, person.name)
Expand All @@ -148,29 +164,29 @@ numbers:
Assert.Equal(2, numbers[1])
Assert.Equal(2, numbers[2])


[<CLIMutable>]
type TestArray = {
name: string
numbers: int array
}
type TestArray = { name: string; numbers: int array }

[<Fact>]
let Deserialize_YamlArray() =
let jackTheDriver = {
name = "Jack"
numbers = [| 12; 2; 2 |]
}

let yaml = """name: Jack
let Deserialize_YamlArray () =
let jackTheDriver =
{
name = "Jack"
numbers = [| 12; 2; 2 |]
}

let yaml =
"""name: Jack
numbers:
- 12
- 2
- 2
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let sut =
DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<TestArray>(yaml)
Assert.Equal(jackTheDriver.name, person.name)
Expand Down
Loading