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

Update editorconfig package #2895

Merged
merged 2 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use EditorConfigCache.
  • Loading branch information
nojaf committed Jun 2, 2023
commit 1392888f0b27d0141c554424263fd78daaa7ff0b
6 changes: 3 additions & 3 deletions src/Fantomas.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
},
"editorconfig": {
"type": "Transitive",
"resolved": "0.13.0",
"contentHash": "1IAdbakbxaKyVv/gr3VTHkbFMFgfOSpP4VRSvOg50Ee9qAfXDr4F8FvOtwq7Pi6fcoxxXYfOYceT1U3oODdpFg=="
"resolved": "0.14.0",
"contentHash": "emt1KlBtTsTSHWeLnlD1grQYN991wlzIh8t0/HF8ambYTLE8v25sPU9q2eu3sNj/Za7Ij6a0MW00lDGTsphEhQ=="
},
"Fable.Core": {
"type": "Transitive",
Expand Down Expand Up @@ -922,7 +922,7 @@
"StreamJsonRpc": "[2.8.28, )",
"System.IO.Abstractions": "[17.2.3, )",
"Thoth.Json.Net": "[8.0.0, )",
"editorconfig": "[0.13.0, )"
"editorconfig": "[0.14.0, )"
}
},
"fantomas.client": {
Expand Down
14 changes: 8 additions & 6 deletions src/Fantomas/EditorConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Fantomas.EditorConfig

open System.Collections.Generic
open System.ComponentModel
open EditorConfig.Core
open Fantomas.Core

module Reflection =
Expand Down Expand Up @@ -40,7 +41,7 @@ let toEditorConfigName value =
value
|> Seq.map (fun c ->
if System.Char.IsUpper(c) then
sprintf "_%s" (c.ToString().ToLower())
$"_%s{c.ToString().ToLower()}"
else
c.ToString())
|> String.concat ""
Expand All @@ -49,7 +50,7 @@ let toEditorConfigName value =
if List.contains name supportedProperties then
name
else
sprintf "fsharp_%s" name
$"fsharp_%s{name}"

let private getFantomasFields (fallbackConfig: FormatConfig) =
Reflection.getRecordFields fallbackConfig
Expand Down Expand Up @@ -102,18 +103,19 @@ let configToEditorConfig (config: FormatConfig) : string =
|> Some
| :? System.Int32 as i -> $"%s{toEditorConfigName recordField.PropertyName}=%d{i}" |> Some
| :? MultilineFormatterType as mft ->
sprintf "%s=%s" (toEditorConfigName recordField.PropertyName) (MultilineFormatterType.ToConfigString mft)
$"%s{toEditorConfigName recordField.PropertyName}=%s{MultilineFormatterType.ToConfigString mft}"
|> Some
| :? EndOfLineStyle as eols ->
sprintf "%s=%s" (toEditorConfigName recordField.PropertyName) (EndOfLineStyle.ToConfigString eols)
$"%s{toEditorConfigName recordField.PropertyName}=%s{EndOfLineStyle.ToConfigString eols}"
|> Some
| _ -> None)
|> String.concat "\n"

let private editorConfigParser = EditorConfig.Core.EditorConfigParser()
let private editorConfigParser =
EditorConfigParser(EditorConfigFileCache.GetOrCreate)

let tryReadConfiguration (fsharpFile: string) : FormatConfig option =
let editorConfigSettings: EditorConfig.Core.FileConfiguration =
let editorConfigSettings: FileConfiguration =
editorConfigParser.Parse(fileName = fsharpFile)

if editorConfigSettings.Properties.Count = 0 then
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Fantomas.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="Argu" Version="6.1.1" />
<PackageReference Include="Thoth.Json.Net" Version="8.0.0" />
<PackageReference Include="SerilogTraceListener" Version="3.2.1-dev-00011" />
<PackageReference Include="editorconfig" Version="0.13.0" />
<PackageReference Include="editorconfig" Version="0.14.0" />
<PackageReference Include="Ignore" Version="0.1.46" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="Spectre.Console" Version="0.46.1-preview.0.6" />
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"editorconfig": {
"type": "Direct",
"requested": "[0.13.0, )",
"resolved": "0.13.0",
"contentHash": "1IAdbakbxaKyVv/gr3VTHkbFMFgfOSpP4VRSvOg50Ee9qAfXDr4F8FvOtwq7Pi6fcoxxXYfOYceT1U3oODdpFg=="
"requested": "[0.14.0, )",
"resolved": "0.14.0",
"contentHash": "emt1KlBtTsTSHWeLnlD1grQYN991wlzIh8t0/HF8ambYTLE8v25sPU9q2eu3sNj/Za7Ij6a0MW00lDGTsphEhQ=="
},
"FSharp.Core": {
"type": "Direct",
Expand Down