Skip to content

Commit 29a6419

Browse files
committed
Improve code based on analyzers.
1 parent 800edbc commit 29a6419

File tree

6 files changed

+28
-29
lines changed

6 files changed

+28
-29
lines changed

src/Common/Collections.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module internal List =
103103

104104
/// Represents a tree with nodes containing values an a list of children
105105
///
106-
type internal Tree<'T> = Node of 'T * list<Tree<'T>>
106+
type internal Tree<'T> = Node of self: 'T * children: Tree<'T> list
107107

108108
module internal Tree =
109109
/// Takes all elements at the specified level and turns them into nodes

src/Common/StringParsing.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ module StringPosition =
299299
/// complete repetitions of a specified sub-string.
300300
let (|EqualsRepeated|_|) (repeated, _n: MarkdownRange) =
301301
function
302-
| StartsWithRepeated repeated (_n, ("", _)) -> Some()
302+
| StartsWithRepeated repeated (_n, (v, _)) when not (String.IsNullOrWhiteSpace v) -> Some()
303303
| _ -> None
304304

305305
module List =

src/FSharp.Formatting.ApiDocs/GenerateModel.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,22 +690,23 @@ type ApiDocEntityInfo
690690
[<AutoOpen>]
691691
module internal CrossReferences =
692692
let getXmlDocSigForType (typ: FSharpEntity) =
693-
match typ.XmlDocSig with
694-
| "" ->
693+
if not (String.IsNullOrWhiteSpace typ.XmlDocSig) then
694+
typ.XmlDocSig
695+
else
695696
try
696697
defaultArg (Option.map (sprintf "T:%s") typ.TryFullName) ""
697698
with _ ->
698699
""
699-
| n -> n
700700

701701
let getMemberXmlDocsSigPrefix (memb: FSharpMemberOrFunctionOrValue) =
702702
if memb.IsEvent then "E"
703703
elif memb.IsProperty then "P"
704704
else "M"
705705

706706
let getXmlDocSigForMember (memb: FSharpMemberOrFunctionOrValue) =
707-
match memb.XmlDocSig with
708-
| "" ->
707+
if not (String.IsNullOrWhiteSpace memb.XmlDocSig) then
708+
memb.XmlDocSig
709+
else
709710
let memberName =
710711
try
711712
let name = memb.CompiledName.Replace(".ctor", "#ctor")
@@ -757,7 +758,6 @@ module internal CrossReferences =
757758
match (memb.DeclaringEntity.Value.TryFullName) with
758759
| None -> ""
759760
| Some(n) -> sprintf "%s:%s.%s" (getMemberXmlDocsSigPrefix memb) n memberName
760-
| n -> n
761761

762762
type internal CrefReference =
763763
{ IsInternal: bool

src/fsdocs-tool/BuildCommand.fs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ type internal DocContent
5252
let mutable counter = 0
5353

5454
fun (url: string) ->
55-
if url.StartsWith("http") || url.StartsWith("https") then
55+
if
56+
url.StartsWith("http", StringComparison.Ordinal)
57+
|| url.StartsWith("https", StringComparison.Ordinal)
58+
then
5659
counter <- counter + 1
5760
let ext = Path.GetExtension(url)
5861

@@ -134,8 +137,8 @@ type internal DocContent
134137
[ let inputFileName = Path.GetFileName(inputFileFullPath)
135138

136139
if
137-
not (inputFileName.StartsWith("."))
138-
&& not (inputFileName.StartsWith "_template")
140+
not (inputFileName.StartsWith('.'))
141+
&& not (inputFileName.StartsWith("_template", StringComparison.Ordinal))
139142
then
140143
let inputFileFullPath = Path.GetFullPath(inputFileFullPath)
141144

@@ -157,7 +160,7 @@ type internal DocContent
157160

158161
for subInputFolderFullPath in Directory.EnumerateDirectories(inputFolderAsGiven) do
159162
let subInputFolderName = Path.GetFileName(subInputFolderFullPath)
160-
let subFolderIsSkipped = subInputFolderName.StartsWith "."
163+
let subFolderIsSkipped = subInputFolderName.StartsWith '.'
161164
let subFolderIsOutput = subFolderIsOutput subInputFolderFullPath
162165

163166
if not subFolderIsOutput && not subFolderIsSkipped then
@@ -179,9 +182,9 @@ type internal DocContent
179182
=
180183
[ let name = Path.GetFileName(inputFileFullPath)
181184

182-
if name.StartsWith(".") then
185+
if name.StartsWith('.') then
183186
printfn "skipping file %s" inputFileFullPath
184-
elif not (name.StartsWith "_template") then
187+
elif not (name.StartsWith("_template", StringComparison.Ordinal)) then
185188
let isFsx = inputFileFullPath.EndsWith(".fsx", true, CultureInfo.InvariantCulture)
186189

187190
let isMd = inputFileFullPath.EndsWith(".md", true, CultureInfo.InvariantCulture)
@@ -510,7 +513,7 @@ type internal DocContent
510513

511514
for subInputFolderFullPath in Directory.EnumerateDirectories(inputFolderAsGiven) do
512515
let subInputFolderName = Path.GetFileName(subInputFolderFullPath)
513-
let subFolderIsSkipped = subInputFolderName.StartsWith "."
516+
let subFolderIsSkipped = subInputFolderName.StartsWith '.'
514517
let subFolderIsOutput = subFolderIsOutput subInputFolderFullPath
515518

516519
if subFolderIsOutput || subFolderIsSkipped then
@@ -1457,7 +1460,7 @@ type CoreBuildOptions(watch) =
14571460
let apiDocOtherFlags =
14581461
[ for (_dllFile, otherFlags, _, _, _, _, _, _, _, _) in crackedProjects do
14591462
for otherFlag in otherFlags do
1460-
if otherFlag.StartsWith("-r:") then
1463+
if otherFlag.StartsWith("-r:", StringComparison.Ordinal) then
14611464
if File.Exists(otherFlag.[3..]) then
14621465
yield otherFlag
14631466
else
@@ -1637,7 +1640,7 @@ type CoreBuildOptions(watch) =
16371640

16381641
// Used to resolve code references in content with respect to the API Docs model
16391642
let resolveInlineCodeReference (s: string) =
1640-
if s.StartsWith("cref:") then
1643+
if s.StartsWith("cref:", StringComparison.Ordinal) then
16411644
let s = s.[5..]
16421645

16431646
match model.Resolver.ResolveCref s with
@@ -1775,7 +1778,7 @@ type CoreBuildOptions(watch) =
17751778
File.Delete file |> ignore
17761779

17771780
for subdir in Directory.EnumerateDirectories dir do
1778-
if not (Path.GetFileName(subdir).StartsWith ".") then
1781+
if not (Path.GetFileName(subdir).StartsWith '.') then
17791782
clean subdir
17801783

17811784
let isOutputPathOK =

src/fsdocs-tool/Options.fs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ namespace fsdocs
22

33
module Common =
44

5-
let evalString s = if s = "" then None else Some s
6-
7-
let evalStrings a =
8-
match Seq.tryExactlyOne a with
9-
| Some "" -> None
10-
| _ -> Some(List.ofSeq a)
5+
let evalString s =
6+
if System.String.IsNullOrEmpty s then None else Some s
117

128
// https://stackoverflow.com/questions/4126351
139
let private pairs (xs: _ seq) =
@@ -22,12 +18,12 @@ module Common =
2218
yield first, second
2319
}
2420

25-
let evalPairwiseStrings a =
26-
match Seq.tryExactlyOne a with
21+
let evalPairwiseStrings (a: string array) =
22+
match Array.tryExactlyOne a with
2723
| Some "" -> None
2824
| _ -> a |> pairs |> List.ofSeq |> Some
2925

30-
let evalPairwiseStringsNoOption a =
26+
let evalPairwiseStringsNoOption (a: string array) =
3127
evalPairwiseStrings a |> Option.defaultValue []
3228

3329
let concat a =

src/fsdocs-tool/ProjectCracker.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module Utils =
138138
res
139139

140140
let ensureTrailingSlash (s: string) =
141-
if s.EndsWith("/") || s.EndsWith(".html") then
141+
if s.EndsWith '/' || s.EndsWith(".html", StringComparison.Ordinal) then
142142
s
143143
else
144144
s + "/"
@@ -456,7 +456,7 @@ module Crack =
456456
|> List.filter (fun s ->
457457
let isFSharpFormattingTestProject =
458458
s.Contains $"FSharp.ApiDocs.Tests{Path.DirectorySeparatorChar}files"
459-
|| s.EndsWith "FSharp.Formatting.TestHelpers.fsproj"
459+
|| s.EndsWith("FSharp.Formatting.TestHelpers.fsproj", StringComparison.Ordinal)
460460

461461
if isFSharpFormattingTestProject then
462462
printfn

0 commit comments

Comments
 (0)