Skip to content

Commit

Permalink
Merge pull request #813 from nojaf/fantomas-6
Browse files Browse the repository at this point in the history
Update to Fantomas v6.
  • Loading branch information
nojaf authored Mar 30, 2023
2 parents cf55560 + e1f6985 commit 8462b2f
Show file tree
Hide file tree
Showing 44 changed files with 908 additions and 929 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"fantomas": {
"version": "5.0.0-beta-008",
"version": "6.0.0-alpha-008",
"commands": [
"fantomas"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: dotnet tool restore
- name: Restore packages
run: dotnet paket restore
- name: Check code formatting conforms (run 'dotnet fantomas src tests docs build --recurse' to repair)
run: dotnet fantomas src tests docs build -r --check
- name: Check code formatting conforms (run 'dotnet fantomas src tests docs build' to repair)
run: dotnet fantomas src tests docs build --check
- name: Build and test
run: dotnet run --project ./build/build.fsproj
4 changes: 2 additions & 2 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
run: dotnet tool restore
- name: Restore packages
run: dotnet paket restore
- name: Check code formatting conforms (run 'dotnet fantomas src tests docs build --recurse' to repair)
run: dotnet fantomas src tests docs build -r --check
- name: Check code formatting conforms (run 'dotnet fantomas src tests docs build' to repair)
run: dotnet fantomas src tests docs build --check
- name: Build and test
run: dotnet run --project ./build/build.fsproj
- name: Deploy docs
Expand Down
4 changes: 3 additions & 1 deletion build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ let solutionFile = "FSharp.Formatting.sln"

let build _ =
solutionFile
|> DotNet.build (fun opts -> { opts with Configuration = configuration })
|> DotNet.build (fun opts ->
{ opts with
Configuration = configuration })

let tests _ =
solutionFile
Expand Down
41 changes: 32 additions & 9 deletions src/Common/StringParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,26 @@ module StringPosition =
/// Returns a string trimmed from the end
let (|TrimEnd|) (text: string, n: MarkdownRange) =
let trimmed = text.TrimEnd()
(trimmed, { n with EndColumn = n.EndColumn - text.Length + trimmed.Length })

(trimmed,
{ n with
EndColumn = n.EndColumn - text.Length + trimmed.Length })

/// Returns a string trimmed from the start
let (|TrimStart|) (text: string, n: MarkdownRange) =
let trimmed = text.TrimStart()
(trimmed, { n with StartColumn = n.StartColumn + text.Length - trimmed.Length })

(trimmed,
{ n with
StartColumn = n.StartColumn + text.Length - trimmed.Length })

/// Returns a string trimmed from the end using characters given as a parameter
let (|TrimEndUsing|) chars (text: string, n: MarkdownRange) =
let trimmed = text.TrimEnd(Array.ofSeq chars)
(trimmed, { n with EndColumn = n.EndColumn - text.Length + trimmed.Length })

(trimmed,
{ n with
EndColumn = n.EndColumn - text.Length + trimmed.Length })

/// Returns a string trimmed from the start together with
/// the number of skipped whitespace characters
Expand All @@ -160,7 +169,9 @@ module StringPosition =

len,
text.Substring(0, len).Replace("\t", " ").Length,
(trimmed, { n with StartColumn = n.StartColumn + text.Length - trimmed.Length })
(trimmed,
{ n with
StartColumn = n.StartColumn + text.Length - trimmed.Length })

/// Matches when a string starts with any of the specified sub-strings
let (|StartsWithAny|_|) (starts: seq<string>) (text: string, _n: MarkdownRange) =
Expand All @@ -172,7 +183,11 @@ module StringPosition =
/// Matches when a string starts with the specified sub-string
let (|StartsWith|_|) (start: string) (text: string, n: MarkdownRange) =
if text.StartsWith(start) then
Some(text.Substring(start.Length), { n with StartColumn = n.StartColumn + text.Length - start.Length })
Some(
text.Substring(start.Length),
{ n with
StartColumn = n.StartColumn + text.Length - start.Length }
)
else
None

Expand All @@ -182,7 +197,8 @@ module StringPosition =
if text.StartsWith(start) then
Some(
text.Substring(start.Length).Trim(),
{ n with StartColumn = n.StartColumn + text.Length - start.Length }
{ n with
StartColumn = n.StartColumn + text.Length - start.Length }
)
else
None
Expand Down Expand Up @@ -268,7 +284,12 @@ module StringPosition =

let rest = text.Substring(id + ends.Length, text.Length - id - ends.Length)

Some(wrapped, (rest, { n with StartColumn = id + ends.Length }))
Some(
wrapped,
(rest,
{ n with
StartColumn = id + ends.Length })
)
else
None
else
Expand All @@ -287,7 +308,7 @@ module List =
let inline (|DelimitedWith|_|) startl endl input =
if List.startsWith startl input then
match List.partitionUntilEquals endl (List.skip startl.Length input) with
| Some (pre, post) -> Some(pre, List.skip endl.Length post, startl.Length, endl.Length)
| Some(pre, post) -> Some(pre, List.skip endl.Length post, startl.Length, endl.Length)
| None -> None
else
None
Expand Down Expand Up @@ -388,7 +409,9 @@ module Lines =

let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else ""

(trimmed, { n with EndColumn = n.EndColumn - s.Length + trimmed.Length }))
(trimmed,
{ n with
EndColumn = n.EndColumn - s.Length + trimmed.Length }))

/// Parameterized pattern that assigns the specified value to the
/// first component of a tuple. Usage:
Expand Down
14 changes: 7 additions & 7 deletions src/FSharp.Formatting.ApiDocs/GenerateHtml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
br []
match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, rty) ->
| Some(_, rty) ->
span
[]
[ !!(if m.Kind <> ApiDocMemberKind.RecordField then
Expand Down Expand Up @@ -195,7 +195,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
| None -> ()

match m.ExtendedType with
| Some (_, extendedTypeHtml) ->
| Some(_, extendedTypeHtml) ->
p [] [ !! "Extended Type: "; embed extendedTypeHtml ]
| _ -> ()

Expand All @@ -219,7 +219,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =

match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, returnTypeHtml) ->
| Some(_, returnTypeHtml) ->
dl
[ Class "fsdocs-returns" ]
[ dt
Expand Down Expand Up @@ -371,12 +371,12 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =


match entity.AbbreviatedType with
| Some (_, abbreviatedTypHtml) -> dt [] [ !! "Abbreviation For: "; embed abbreviatedTypHtml ]
| Some(_, abbreviatedTypHtml) -> dt [] [ !! "Abbreviation For: "; embed abbreviatedTypHtml ]

| None -> ()

match entity.BaseType with
| Some (_, baseTypeHtml) -> dt [] [ !! "Base Type: "; embed baseTypeHtml ]
| Some(_, baseTypeHtml) -> dt [] [ !! "Base Type: "; embed baseTypeHtml ]
| None -> ()

match entity.AllInterfaces with
Expand All @@ -395,7 +395,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
dt [] [ !!("Kind: Struct") ]

match entity.DelegateSignature with
| Some (_, delegateSigHtml) -> dt [] [ !!("Delegate Signature: "); embed delegateSigHtml ]
| Some(_, delegateSigHtml) -> dt [] [ !!("Delegate Signature: "); embed delegateSigHtml ]
| None -> ()

if entity.Symbol.IsProvided then
Expand Down Expand Up @@ -598,7 +598,7 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
match nsOpt with
| Some ns2 when ns.Name = ns2.Name ->
ul
[ Custom("list-style-type", "none") (* Class "navbar-nav " *) ]
[ Custom("list-style-type", "none") (* Class "navbar-nav " *) ]
[ for category in allByCategory do
for e in category.CategoryEntites do
li
Expand Down
10 changes: 5 additions & 5 deletions src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =

match m.ExtendedType with
| None -> ()
| Some (_, extendedTypeHtml) -> p [ !! "Extended Type: "; embedSafe extendedTypeHtml; br ]
| Some(_, extendedTypeHtml) -> p [ !! "Extended Type: "; embedSafe extendedTypeHtml; br ]

match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, returnTypeHtml) ->
| Some(_, returnTypeHtml) ->
p
[ !!(if m.Kind <> ApiDocMemberKind.RecordField then
"Returns: "
Expand Down Expand Up @@ -174,11 +174,11 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =
(parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]

match entity.AbbreviatedType with
| Some (_, abbreviatedTyp) -> p [ !! "Abbreviation For: "; embed abbreviatedTyp ]
| Some(_, abbreviatedTyp) -> p [ !! "Abbreviation For: "; embed abbreviatedTyp ]
| None -> ()

match entity.BaseType with
| Some (_, baseType) -> p [ !! "Base Type: "; embed baseType ]
| Some(_, baseType) -> p [ !! "Base Type: "; embed baseType ]
| None -> ()

match entity.AllInterfaces with
Expand All @@ -196,7 +196,7 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =
p [ !!("Kind: Struct") ]

match entity.DelegateSignature with
| Some (_, delegateSigHtml) -> p [ !!("Delegate Signature: "); embed delegateSigHtml ]
| Some(_, delegateSigHtml) -> p [ !!("Delegate Signature: "); embed delegateSigHtml ]
| None -> ()

if entity.Symbol.IsProvided then
Expand Down
Loading

0 comments on commit 8462b2f

Please sign in to comment.