diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 3027b3ad..b902040d 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "fsharp-analyzers": { - "version": "0.24.0", + "version": "0.26.0", "commands": [ "fsharp-analyzers" ] diff --git a/Directory.Packages.props b/Directory.Packages.props index facf2013..e699315b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -27,7 +27,7 @@ - - + + \ No newline at end of file diff --git a/src/Common/StringParsing.fs b/src/Common/StringParsing.fs index 9ce65ee7..1136bd4c 100644 --- a/src/Common/StringParsing.fs +++ b/src/Common/StringParsing.fs @@ -108,8 +108,11 @@ module String = let removeSpaces (lines: string list) = let spaces = lines - |> Seq.filter (String.IsNullOrWhiteSpace >> not) - |> Seq.map (fun line -> line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length) + |> Seq.choose (fun line -> + if String.IsNullOrWhiteSpace line |> not then + line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length |> Some + else + None) |> fun xs -> if Seq.isEmpty xs then 0 else Seq.min xs lines diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 04cd96a9..9b406e67 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -1282,8 +1282,9 @@ module internal TypeFormatter = n curriedArgs - |> List.map (List.map (fun x -> formatArgNameAndType (counter ()) x |> fst)) - |> List.map (fun argTuple -> + |> List.map (fun args -> + let argTuple = args |> List.map (formatArgNameAndType (counter ()) >> fst) + match argTuple with | [] -> !! "()" | [ argName ] when argName = "()" -> !! "()" @@ -2217,10 +2218,9 @@ module internal SymbolReader = } /// Returns whether the link is not included in the document defined links - let linkNotDefined (doc: LiterateDocument) (link: string) = + let linkDefined (doc: LiterateDocument) (link: string) = [ link; link.Replace("\r\n", ""); link.Replace("\r\n", " "); link.Replace("\n", ""); link.Replace("\n", " ") ] - |> Seq.map (fun key -> not (doc.DefinedLinks.ContainsKey(key))) - |> Seq.reduce (fun a c -> a && c) + |> List.exists (fun key -> doc.DefinedLinks.ContainsKey(key)) /// Returns a tuple of the undefined link and its Cref if it exists let getTypeLink (ctx: ReadingContext) undefinedLink = @@ -2264,8 +2264,11 @@ module internal SymbolReader = do replacedParagraphs |> Seq.collect collectParagraphIndirectLinks - |> Seq.filter (linkNotDefined doc) - |> Seq.map (getTypeLink ctx) + |> Seq.choose (fun line -> + if linkDefined doc line then + None + else + getTypeLink ctx line |> Some) |> Seq.iter (addLinkToType doc) doc.With(paragraphs = replacedParagraphs) @@ -2275,15 +2278,12 @@ module internal SymbolReader = let text = lines - |> List.filter ( - findCommand - >> (function + |> List.choose (fun line -> + match findCommand line with | Some(k, v) -> cmds.[k] <- v - false - | _ -> true) - ) - |> List.map fst + None + | _ -> fst line |> Some) |> String.concat "\n" let doc = @@ -2421,8 +2421,7 @@ module internal SymbolReader = let readChildren ctx (entities: FSharpEntity seq) reader cond = entities - |> Seq.filter (fun v -> checkAccess ctx v.Accessibility) - |> Seq.filter cond + |> Seq.filter (fun v -> checkAccess ctx v.Accessibility && cond v) |> Seq.sortBy (fun (c: FSharpEntity) -> c.DisplayName) |> Seq.choose (reader ctx) |> List.ofSeq @@ -2448,23 +2447,28 @@ module internal SymbolReader = let readAllMembers ctx entityUrl kind (members: FSharpMemberOrFunctionOrValue seq) = members - |> Seq.filter (fun v -> checkAccess ctx v.Accessibility) - |> Seq.filter (fun v -> - not v.IsCompilerGenerated - && not v.IsPropertyGetterMethod - && not v.IsPropertySetterMethod - && not v.IsEventAddMethod - && not v.IsEventRemoveMethod) - |> Seq.choose (tryReadMember ctx entityUrl kind) + |> Seq.choose (fun v -> + if + checkAccess ctx v.Accessibility + && not v.IsCompilerGenerated + && not v.IsPropertyGetterMethod + && not v.IsPropertySetterMethod + && not v.IsEventAddMethod + && not v.IsEventRemoveMethod + then + tryReadMember ctx entityUrl kind v + else + None) |> List.ofSeq |> collectNamespaceDocs let readMembers ctx entityUrl kind (entity: FSharpEntity) cond = entity.MembersFunctionsAndValues - |> Seq.filter (fun v -> checkAccess ctx v.Accessibility) - |> Seq.filter (fun v -> not v.IsCompilerGenerated) - |> Seq.filter cond - |> Seq.choose (tryReadMember ctx entityUrl kind) + |> Seq.choose (fun v -> + if checkAccess ctx v.Accessibility && not v.IsCompilerGenerated && cond v then + tryReadMember ctx entityUrl kind v + else + None) |> List.ofSeq |> collectNamespaceDocs @@ -2485,47 +2489,51 @@ module internal SymbolReader = let readUnionCases ctx entityUrl (typ: FSharpEntity) = typ.UnionCases |> List.ofSeq - |> List.filter (fun v -> checkAccess ctx v.Accessibility) |> List.choose (fun case -> - readCommentsInto case ctx case.XmlDocSig (fun cat catidx exclude _ comment -> - let details = readUnionCase ctx typ case - - ApiDocMember( - case.Name, - readAttributes case.Attributes, - entityUrl, - ApiDocMemberKind.UnionCase, - cat, - catidx, - exclude, - details, - comment, - case, - ctx.WarnOnMissingDocs - ))) + if checkAccess ctx case.Accessibility |> not then + None + else + readCommentsInto case ctx case.XmlDocSig (fun cat catidx exclude _ comment -> + let details = readUnionCase ctx typ case + + ApiDocMember( + case.Name, + readAttributes case.Attributes, + entityUrl, + ApiDocMemberKind.UnionCase, + cat, + catidx, + exclude, + details, + comment, + case, + ctx.WarnOnMissingDocs + ))) |> collectNamespaceDocs let readRecordFields ctx entityUrl (typ: FSharpEntity) = typ.FSharpFields |> List.ofSeq - |> List.filter (fun field -> not field.IsCompilerGenerated) |> List.choose (fun field -> - readCommentsInto field ctx field.XmlDocSig (fun cat catidx exclude _ comment -> - let details = readFSharpField ctx field - - ApiDocMember( - field.Name, - readAttributes (Seq.append field.FieldAttributes field.PropertyAttributes), - entityUrl, - ApiDocMemberKind.RecordField, - cat, - catidx, - exclude, - details, - comment, - field, - ctx.WarnOnMissingDocs - ))) + if field.IsCompilerGenerated then + None + else + readCommentsInto field ctx field.XmlDocSig (fun cat catidx exclude _ comment -> + let details = readFSharpField ctx field + + ApiDocMember( + field.Name, + readAttributes (Seq.append field.FieldAttributes field.PropertyAttributes), + entityUrl, + ApiDocMemberKind.RecordField, + cat, + catidx, + exclude, + details, + comment, + field, + ctx.WarnOnMissingDocs + ))) |> collectNamespaceDocs let readStaticParams ctx entityUrl (typ: FSharpEntity) = @@ -2585,11 +2593,12 @@ module internal SymbolReader = if isNull nameAttr then None else - Some(nameAttr.Value, p.Value)) - |> Seq.iter (fun (name, xmlDoc) -> - let xmlDocSig = getFSharpStaticParamXmlSig typ name + let xmlDocSig = getFSharpStaticParamXmlSig typ nameAttr.Value - registerXmlDoc ctx xmlDocSig (Security.SecurityElement.Escape xmlDoc) |> ignore) + registerXmlDoc ctx xmlDocSig (Security.SecurityElement.Escape p.Value) + |> ignore + |> Some) + |> ignore let rec readType (ctx: ReadingContext) (typ: FSharpEntity) = if typ.IsProvided && typ.XmlDoc <> FSharpXmlDoc.None then @@ -2617,17 +2626,15 @@ module internal SymbolReader = let ivals, svals = getMembers typ - |> List.ofSeq - |> List.filter (fun v -> + |> Seq.filter (fun v -> checkAccess ctx v.Accessibility && not v.IsCompilerGenerated - && not v.IsOverrideOrExplicitInterfaceImplementation) - |> List.filter (fun v -> - not v.IsCompilerGenerated + && not v.IsOverrideOrExplicitInterfaceImplementation && not v.IsEventAddMethod && not v.IsEventRemoveMethod && not v.IsPropertyGetterMethod && not v.IsPropertySetterMethod) + |> List.ofSeq |> List.partition (fun v -> v.IsInstanceMember) let cvals, svals = svals |> List.partition (fun v -> v.CompiledName = ".ctor") diff --git a/src/FSharp.Formatting.Common/Templating.fs b/src/FSharp.Formatting.Common/Templating.fs index 043543b3..d17684ed 100644 --- a/src/FSharp.Formatting.Common/Templating.fs +++ b/src/FSharp.Formatting.Common/Templating.fs @@ -48,10 +48,15 @@ type FrontMatterFile = // Allow empty lines in frontmatter let isBlankLine = String.IsNullOrWhiteSpace line isBlankLine || line.Contains(":")) - |> Seq.filter (String.IsNullOrWhiteSpace >> not) - |> Seq.map (fun line -> - let parts = line.Split(":") - parts.[0].ToLowerInvariant(), parts.[1]) + |> Seq.choose (fun line -> + if String.IsNullOrWhiteSpace line |> not then + let parts = line.Split(":") |> Array.toList + + match parts with + | first :: second :: _ -> Some(first.ToLowerInvariant(), second) + | _ -> None + else + None) |> Map.ofSeq match diff --git a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs index a8a344d2..6e32a331 100644 --- a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs +++ b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs @@ -83,7 +83,6 @@ module internal CompilerServiceExtensions = options.OtherOptions |> Array.filter (fun path -> path.StartsWith("-r:", StringComparison.Ordinal)) - |> Array.filter (fun path -> path.StartsWith("-r:", StringComparison.Ordinal)) //|> Seq.choose (fun path -> if path.StartsWith "-r:" then path.Substring 3 |> Some else None) //|> Seq.map (fun path -> path.Replace("\\\\", "\\")) |> Array.toList) @@ -180,11 +179,11 @@ module internal CompilerServiceExtensions = || libDirs |> List.exists (fun lib -> Directory.EnumerateFiles(lib) - |> Seq.filter (fun file -> Path.GetExtension file =? ".dll") |> Seq.filter (fun file -> // If we find a FSharp.Core in a lib path, we check if is suited for us... - Path.GetFileNameWithoutExtension file <>? "FSharp.Core" - || (tryCheckFsCore file |> Option.isSome)) + Path.GetExtension file =? ".dll" + && (Path.GetFileNameWithoutExtension file <>? "FSharp.Core" + || (tryCheckFsCore file |> Option.isSome))) |> Seq.toList |> isAssembly asm) @@ -279,10 +278,9 @@ module internal CompilerServiceExtensions = let findReferences libDir = Directory.EnumerateFiles(libDir, "*.dll") - |> Seq.map Path.GetFullPath // Filter files already referenced directly |> Seq.filter (fun file -> - let fileName = Path.GetFileName file + let fileName = Path.GetFullPath file |> Path.GetFileName dllFiles |> List.exists (fun (dllFile: string) -> Path.GetFileName dllFile =? fileName) diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 5619e605..e00d4837 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -95,9 +95,12 @@ type internal DocContent (subFolderFullPath = rootOutputFolderFullPath) let allCultures = - System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures) - |> Array.map (fun x -> x.TwoLetterISOLanguageName) - |> Array.filter (fun x -> x.Length = 2) + CultureInfo.GetCultures(CultureTypes.AllCultures) + |> Array.choose (fun x -> + if x.TwoLetterISOLanguageName.Length <> 2 then + None + else + Some x.TwoLetterISOLanguageName) |> Array.distinct let makeMarkdownLinkResolver