Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove `NoPartialFunctions` compiler workaround (#698) [@webwarrior-ws]
- Add `SLNX` and `SLNF` format support and migrate to SLNX solution #723 [@xperiandri]\
Remove `Ionide.ProjInfo.Sln` NuGet package dependency
- Remove `Newtonsoft.Json` NuGet dependency #725 [@xperiandri]

## [0.24.2] - 2024-02-29

Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="17.14.8" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.14.8" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/FSharpLint.Console/FSharpLint.Console.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<ItemGroup>
<PackageReference Include="Argu" />
<PackageReference Include="FSharp.Core" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
47 changes: 12 additions & 35 deletions src/FSharpLint.Core/Application/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module FSharpLint.Framework.Configuration
open System
open System.IO
open System.Reflection
open Newtonsoft.Json
open System.Text.Json
open System.Text.Json.Serialization
open FSharpLint.Framework
open FSharpLint.Framework.Rules
open FSharpLint.Framework.HintParser
Expand All @@ -15,40 +16,16 @@ let SettingsFileName = "fsharplint.json"

exception ConfigurationException of string

module FSharpJsonConverter =
open Microsoft.FSharp.Reflection

type OptionConverter() =
inherit JsonConverter()

override x.CanConvert(t) =
t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<_ option>

override x.WriteJson(writer, value, serializer) =
let value =
if isNull value then null
else
let _,fields = FSharpValue.GetUnionFields(value, value.GetType())
fields.[0]
serializer.Serialize(writer, value)

override x.ReadJson(reader, t, _, serializer) =
let innerType = t.GetGenericArguments().[0]
let innerType =
if innerType.IsValueType then (typedefof<Nullable<_>>).MakeGenericType([|innerType|])
else innerType
let value = serializer.Deserialize(reader, innerType)
let cases = FSharpType.GetUnionCases(t)
if isNull value then FSharpValue.MakeUnion(cases.[0], [||])
else FSharpValue.MakeUnion(cases.[1], [|value|])

let private converters =
[|
OptionConverter() :> JsonConverter
|]
module internal FSharpJsonConverter =

let serializerSettings =
JsonSerializerSettings(NullValueHandling = NullValueHandling.Ignore, Converters = converters)
let jsonOptions =
let options =
JsonSerializerOptions(
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
)
options.Converters.Add(JsonStringEnumConverter())
options

module IgnoreFiles =

Expand Down Expand Up @@ -582,7 +559,7 @@ with
/// Tries to parse the provided config text.
let parseConfig (configText:string) =
try
JsonConvert.DeserializeObject<Configuration>(configText, FSharpJsonConverter.serializerSettings)
JsonSerializer.Deserialize<Configuration>(configText, FSharpJsonConverter.jsonOptions)
with
| ex -> raise <| ConfigurationException $"Couldn't parse config, error=%s{ex.Message}"

Expand Down
1 change: 0 additions & 1 deletion src/FSharpLint.Core/FSharpLint.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
<PackageReference Include="Microsoft.Build.Tasks.Core" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

</Project>
Loading