diff --git a/src/Common/Collections.fs b/src/Common/Collections.fs index 4607060a4..406c0c552 100644 --- a/src/Common/Collections.fs +++ b/src/Common/Collections.fs @@ -49,7 +49,7 @@ module internal List = f x g () iterInterleaved f g (y :: tl) - | x :: [] -> f x + | [x] -> f x | [] -> () /// Tests whether a list starts with the elements of another @@ -90,7 +90,7 @@ module internal List = let other, rest = partitionUntil (f >> not) other yield last, other yield! loop rest - | [] when other = [] -> () + | [] when List.isEmpty other -> () | _ -> invalidArg "" "Should start with true" } diff --git a/src/Common/StringParsing.fs b/src/Common/StringParsing.fs index ef6c59124..af37930bb 100644 --- a/src/Common/StringParsing.fs +++ b/src/Common/StringParsing.fs @@ -15,8 +15,9 @@ open FSharp.Formatting.Markdown module String = /// Matches when a string is a whitespace or null + [] let (|WhiteSpace|_|) (s) = - if String.IsNullOrWhiteSpace(s) then Some() else None + if String.IsNullOrWhiteSpace(s) then ValueSome() else ValueNone /// Returns a string trimmed from both start and end let (|TrimBoth|) (text: string) = text.Trim() @@ -117,15 +118,17 @@ module String = module StringPosition = /// Matches when a string is a whitespace or null + [] let (|WhiteSpace|_|) (s, _n: MarkdownRange) = - if String.IsNullOrWhiteSpace(s) then Some() else None + if String.IsNullOrWhiteSpace(s) then ValueSome() else ValueNone /// Matches when a string does starts with non-whitespace + [] let (|Unindented|_|) (s: string, _n: MarkdownRange) = if not (String.IsNullOrWhiteSpace(s)) && s.TrimStart() = s then - Some() + ValueSome() else - None + ValueNone /// Returns a string trimmed from both start and end let (|TrimBoth|) (text: string, n: MarkdownRange) = @@ -174,11 +177,12 @@ module StringPosition = StartColumn = n.StartColumn + text.Length - trimmed.Length }) /// Matches when a string starts with any of the specified sub-strings + [] let (|StartsWithAny|_|) (starts: string seq) (text: string, _n: MarkdownRange) = if starts |> Seq.exists (fun s -> text.StartsWith(s, StringComparison.Ordinal)) then - Some() + ValueSome() else - None + ValueNone /// Matches when a string starts with the specified sub-string let (|StartsWith|_|) (start: string) (text: string, n: MarkdownRange) = @@ -297,15 +301,16 @@ module StringPosition = /// Matches when a string consists of some number of /// complete repetitions of a specified sub-string. + [] let (|EqualsRepeated|_|) (repeated, _n: MarkdownRange) = function - | StartsWithRepeated repeated (_n, (v, _)) when (String.IsNullOrWhiteSpace v) -> Some() - | _ -> None + | StartsWithRepeated repeated (_n, (v, _)) when (String.IsNullOrWhiteSpace v) -> ValueSome() + | _ -> ValueNone module List = /// Matches a list if it starts with a sub-list that is delimited /// using the specified delimiters. Returns a wrapped list and the rest. - let inline (|DelimitedWith|_|) startl endl input = + let inline internal (|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) @@ -314,14 +319,14 @@ module List = None /// Matches a list if it starts with a sub-list. Returns the list. - let inline (|StartsWith|_|) startl input = + let inline internal (|StartsWith|_|) startl input = if List.startsWith startl input then Some input else None /// Matches a list if it starts with a sub-list that is delimited /// using the specified delimiter. Returns a wrapped list and the rest. - let inline (|Delimited|_|) str = (|DelimitedWith|_|) str str + let inline internal (|Delimited|_|) str = (|DelimitedWith|_|) str str - let inline (|DelimitedNTimes|_|) str input = + let inline internal (|DelimitedNTimes|_|) str input = let strs, _items = List.partitionWhile (fun i -> i = str) input match strs with @@ -403,9 +408,8 @@ module Lines = let (|TrimParagraphLines|) lines = lines // first remove all whitespace on the beginning of the line - |> List.map (fun (StringPosition.TrimStart s) -> s) - // Now remove all additional spaces at the end, but keep two spaces if existent - |> List.map (fun (s, n) -> + // then remove all additional spaces at the end, but keep two spaces if existent + |> List.map (fun (StringPosition.TrimStart (s, n)) -> let endsWithTwoSpaces = s.EndsWith(" ", StringComparison.Ordinal) let trimmed = s.TrimEnd([| ' ' |]) + if endsWithTwoSpaces then " " else "" diff --git a/src/FSharp.Formatting.ApiDocs/Categorise.fs b/src/FSharp.Formatting.ApiDocs/Categorise.fs index 4b77443de..40202f73b 100644 --- a/src/FSharp.Formatting.ApiDocs/Categorise.fs +++ b/src/FSharp.Formatting.ApiDocs/Categorise.fs @@ -59,9 +59,9 @@ let entities (nsIndex: int, ns: ApiDocNamespace, suppress) = // // See https://github.com/fsharp/fsharp-core-docs/issues/57, we may rethink this |> List.filter (fun e -> - not (e.Symbol.Namespace = Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols")) + (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols")) |> List.filter (fun e -> - not (e.Symbol.Namespace = Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitNames")) + (e.Symbol.Namespace <> Some "Microsoft.FSharp.Data.UnitSystems.SI.UnitNames")) // Don't show 'AnonymousObject' in list-of-namespaces navigation |> List.filter (fun e -> not ( diff --git a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs index 31b9fbf44..edee8787f 100644 --- a/src/FSharp.Formatting.ApiDocs/GenerateModel.fs +++ b/src/FSharp.Formatting.ApiDocs/GenerateModel.fs @@ -62,15 +62,16 @@ module internal Utils = else None + [] let (|MeasureOne|_|) (typ: FSharpType) = if typ.HasTypeDefinition && typ.TypeDefinition.LogicalName = "1" && typ.GenericArguments.Count = 0 then - Some() + ValueSome() else - None + ValueNone let tryGetLocation (symbol: FSharpSymbol) = match symbol.ImplementationLocation with @@ -105,7 +106,7 @@ module internal Utils = member x.TryAttr(attr: string) = let a = x.Attribute(XName.Get attr) - if a = null then None + if isNull a then None else if String.IsNullOrEmpty a.Value then None else Some a.Value @@ -1757,7 +1758,7 @@ module internal SymbolReader = [ let mutable line = "" while (line <- reader.ReadLine() - line <> null) do + not(isNull line)) do yield line ] String.removeSpaces lines @@ -1905,14 +1906,14 @@ module internal SymbolReader = let name = elem.Attribute(XName.Get "name") let nameAsHtml = HttpUtility.HtmlEncode name.Value - if name <> null then + if not(isNull name) then html.AppendFormat("{0}", nameAsHtml) |> ignore | "see" | "seealso" -> let cref = elem.Attribute(XName.Get "cref") - if cref <> null then + if not(isNull cref) then if System.String.IsNullOrEmpty(cref.Value) || cref.Value.Length < 3 then printfn "ignoring invalid cref specified in: %A" e @@ -2018,7 +2019,7 @@ module internal SymbolReader = let remarks = let remarkNodes = doc.Elements(XName.Get "remarks") |> Seq.toList - if List.length remarkNodes > 0 then + if not(List.isEmpty remarkNodes) then let html = new StringBuilder() for (id, e) in List.indexed remarkNodes do @@ -2053,7 +2054,7 @@ module internal SymbolReader = [ for e in exceptionNodes do let cref = e.Attribute(XName.Get "cref") - if cref <> null then + if not(isNull cref) then if String.IsNullOrEmpty(cref.Value) || cref.Value.Length < 3 then printfn "Warning: Invalid cref specified in: %A" doc @@ -2581,7 +2582,7 @@ module internal SymbolReader = |> Seq.choose (fun p -> let nameAttr = p.Attribute(XName.Get "name") - if nameAttr = null then + if isNull nameAttr then None else Some(nameAttr.Value, p.Value)) @@ -2821,7 +2822,7 @@ module internal SymbolReader = [ for e in doc.Descendants(XName.Get "member") do let attr = e.Attribute(XName.Get "name") - if attr <> null && not (String.IsNullOrEmpty(attr.Value)) then + if (not(isNull attr)) && not (String.IsNullOrEmpty(attr.Value)) then yield attr.Value, e ] do // NOTE: We completely ignore duplicate keys and I don't see // an easy way to detect where "value" is coming from, because the entries diff --git a/src/FSharp.Formatting.CodeFormat/CodeFormatAgent.fs b/src/FSharp.Formatting.CodeFormat/CodeFormatAgent.fs index e19514c4e..1050607b3 100644 --- a/src/FSharp.Formatting.CodeFormat/CodeFormatAgent.fs +++ b/src/FSharp.Formatting.CodeFormat/CodeFormatAgent.fs @@ -352,7 +352,7 @@ module CodeFormatter = [| let line = ref "" while (line := reader.ReadLine() - line.Value <> null) do + not(isNull line.Value)) do yield line.Value |] // Get options for a standalone script file (this adds some // default references and doesn't require full project information) diff --git a/src/FSharp.Formatting.CodeFormat/SourceCode.fs b/src/FSharp.Formatting.CodeFormat/SourceCode.fs index 9db2c7b22..d8522adf7 100644 --- a/src/FSharp.Formatting.CodeFormat/SourceCode.fs +++ b/src/FSharp.Formatting.CodeFormat/SourceCode.fs @@ -20,7 +20,7 @@ type ToolTipSpan = | HardLineBreak /// Classifies tokens reported by the FCS -[] +[] type TokenKind = | Keyword | String @@ -49,7 +49,7 @@ type TokenKind = /// Represents a kind of error reported from the F# compiler (warning or error) -[] +[] type ErrorKind = | Error | Warning diff --git a/src/FSharp.Formatting.Common/PynbModel.fs b/src/FSharp.Formatting.Common/PynbModel.fs index 3afd8cefb..f36a6cdfb 100644 --- a/src/FSharp.Formatting.Common/PynbModel.fs +++ b/src/FSharp.Formatting.Common/PynbModel.fs @@ -88,8 +88,7 @@ type Cell = | Some(x) -> string x) (this.outputs |> Array.map string |> String.concat ",\n"))) (this.source - |> Array.map addLineEnd - |> Array.map escapeAndQuote + |> Array.map (addLineEnd >> escapeAndQuote) |> String.concat ",\n ") type Kernelspec = diff --git a/src/FSharp.Formatting.Common/Templating.fs b/src/FSharp.Formatting.Common/Templating.fs index bb8cf2d44..b00041217 100644 --- a/src/FSharp.Formatting.Common/Templating.fs +++ b/src/FSharp.Formatting.Common/Templating.fs @@ -280,14 +280,13 @@ module internal SimpleTemplating = // If there is no template or the template is an empty file, return just document + tooltips (tooltips empty if not HTML) let lookup = readOnlyDict substitutions - (if lookup.ContainsKey ParamKeys.``fsdocs-content`` then - lookup.[ParamKeys.``fsdocs-content``] - else - "") - + (if lookup.ContainsKey ParamKeys.``fsdocs-tooltips`` then - "\n\n" + lookup.[ParamKeys.``fsdocs-tooltips``] - else - "") + (match lookup.TryGetValue ParamKeys.``fsdocs-content`` with + | true, lookupContent -> lookupContent + | false, _ -> "") + + (match lookup.TryGetValue ParamKeys.``fsdocs-tooltips`` with + | true, lookupTips -> + "\n\n" + lookupTips + | false, _ -> "") | Some templateText -> ApplySubstitutionsInText substitutions templateText let UseFileAsSimpleTemplate (substitutions, templateOpt, outputFile) = diff --git a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs index a5e072217..1a705c638 100644 --- a/src/FSharp.Formatting.Common/YaafFSharpScripting.fs +++ b/src/FSharp.Formatting.Common/YaafFSharpScripting.fs @@ -246,9 +246,10 @@ module internal CompilerServiceExtensions = dllFiles |> List.map (fun file -> file, - (if referenceDict.ContainsKey file then - Some referenceDict.[file] - else + (match referenceDict.TryGetValue file with + | true, refFile -> + Some refFile + | false, _ -> None)) let getProjectReferencesSimple frameworkVersion (dllFiles: string list) = @@ -464,26 +465,29 @@ module internal ArgParser = else None + [] let (|FsiBoolArg|_|) argName s = match s with | StartsWith argName rest -> if String.IsNullOrWhiteSpace rest then - Some true + ValueSome true else match rest with - | "+" -> Some true - | "-" -> Some false - | _ -> None - | _ -> None + | "+" -> ValueSome true + | "-" -> ValueSome false + | _ -> ValueNone + | _ -> ValueNone open ArgParser +[] type internal DebugMode = | Full | PdbOnly | Portable | NoDebug +[] type internal OptimizationType = | NoJitOptimize | NoJitTracking @@ -761,7 +765,7 @@ type internal FsiOptions = | [] -> Seq.empty | opts -> opts - |> Seq.map (fun (enable, types) -> + |> Seq.collect (fun (enable, types) -> seq { yield sprintf "--optimize%s" (getMinusPlus enable) @@ -778,7 +782,6 @@ type internal FsiOptions = | NoTailCalls -> "notailcalls") |> String.concat "," }) - |> Seq.concat yield! getSimpleBoolArg "--quiet" x.Quiet yield! getSimpleBoolArg "--quotations-debug" x.QuotationsDebug diff --git a/src/FSharp.Formatting.Literate/Contexts.fs b/src/FSharp.Formatting.Literate/Contexts.fs index 3161411d2..b726044e2 100644 --- a/src/FSharp.Formatting.Literate/Contexts.fs +++ b/src/FSharp.Formatting.Literate/Contexts.fs @@ -23,7 +23,7 @@ type internal CompilerContext = } /// Defines the possible output types from literate script (HTML, Latex, Pynb) -[] +[] type OutputKind = /// Requests HTML output | Html diff --git a/src/FSharp.Formatting.Literate/Evaluator.fs b/src/FSharp.Formatting.Literate/Evaluator.fs index b2f4c5555..97dd653ae 100644 --- a/src/FSharp.Formatting.Literate/Evaluator.fs +++ b/src/FSharp.Formatting.Literate/Evaluator.fs @@ -15,7 +15,7 @@ open FSharp.Formatting.Internal /// /// Functionality to support literate evaluation for F# scripts /// -[] +[] type FsiEmbedKind = /// The FSI output | FsiOutput diff --git a/src/FSharp.Formatting.Literate/ParseScript.fs b/src/FSharp.Formatting.Literate/ParseScript.fs index 2b2f39d4e..0f910f414 100644 --- a/src/FSharp.Formatting.Literate/ParseScript.fs +++ b/src/FSharp.Formatting.Literate/ParseScript.fs @@ -163,7 +163,8 @@ type internal ParseScript(parseOptions, ctx: CompilerContext) = | Command "condition" name when not (String.IsNullOrWhiteSpace name) -> { Condition = Some name } | _ -> { Condition = None } - let (|EmptyString|_|) (v: string) = if v.Length = 0 then Some() else None + [] + let (|EmptyString|_|) (v: string) = if v.Length = 0 then ValueSome() else ValueNone /// Transform list of code blocks (snippet/comment/command) /// into a formatted Markdown document, with link definitions @@ -386,7 +387,7 @@ type internal ParseScript(parseOptions, ctx: CompilerContext) = let parsedBlocks = [ for Snippet(name, lines) in sourceSnippets do - if name <> null then + if not(isNull name) then yield BlockComment("## " + name) yield! parseScriptFile (lines) ] diff --git a/src/FSharp.Formatting.Literate/Transformations.fs b/src/FSharp.Formatting.Literate/Transformations.fs index 73783181d..257b1de0c 100644 --- a/src/FSharp.Formatting.Literate/Transformations.fs +++ b/src/FSharp.Formatting.Literate/Transformations.fs @@ -60,11 +60,12 @@ module internal Transformations = None else let code = - if cmds.ContainsKey("file") && cmds.ContainsKey("key") then + match cmds.TryGetValue "file", cmds.TryGetValue "key" with + | (true, fileVal), (true, keyVal) -> // Get snippet from an external file - let file = Path.Combine(Path.GetDirectoryName(path), cmds.["file"]) + let file = Path.Combine(Path.GetDirectoryName(path), fileVal) - let startTag, endTag = "[" + cmds.["key"] + "]", "[/" + cmds.["key"] + "]" + let startTag, endTag = "[" + keyVal + "]", "[/" + keyVal + "]" let lines = File.ReadAllLines(file) @@ -76,7 +77,7 @@ module internal Transformations = |> Array.toList |> String.removeSpaces |> String.concat "\n" - else + | _ -> code let lang = diff --git a/src/FSharp.Formatting.Markdown/Markdown.fs b/src/FSharp.Formatting.Markdown/Markdown.fs index 408fcb935..d0555fd0d 100644 --- a/src/FSharp.Formatting.Markdown/Markdown.fs +++ b/src/FSharp.Formatting.Markdown/Markdown.fs @@ -45,7 +45,7 @@ type Markdown internal () = let mutable lineNo = 1 while (line := reader.ReadLine() - line.Value <> null) do + not(isNull line.Value)) do yield (line.Value, { StartLine = lineNo diff --git a/src/FSharp.Formatting.Markdown/MarkdownModel.fs b/src/FSharp.Formatting.Markdown/MarkdownModel.fs index 635a886c5..ec23a69e8 100644 --- a/src/FSharp.Formatting.Markdown/MarkdownModel.fs +++ b/src/FSharp.Formatting.Markdown/MarkdownModel.fs @@ -14,11 +14,13 @@ open System.Collections.Generic /// /// A list kind can be Ordered or Unordered corresponding to <ol> and <ul> elements /// +[] type MarkdownListKind = | Ordered | Unordered /// Column in a table can be aligned to left, right, center or using the default alignment +[] type MarkdownColumnAlignment = | AlignLeft | AlignRight diff --git a/src/FSharp.Formatting.Markdown/MarkdownParser.fs b/src/FSharp.Formatting.Markdown/MarkdownParser.fs index 739e95674..e9ccb54d3 100644 --- a/src/FSharp.Formatting.Markdown/MarkdownParser.fs +++ b/src/FSharp.Formatting.Markdown/MarkdownParser.fs @@ -844,7 +844,7 @@ let rec pipeTableFindSplits (delim: char array) (line: char list) = match rest with | None -> [ cLstToStr line ] - | Some _x when line = [] -> [ "" ] + | Some _x when List.isEmpty line -> [ "" ] | Some x -> let chunkSize = List.length line - List.length x - 1 diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index 86385c3f4..5619e605d 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -695,7 +695,7 @@ type internal DocContent | (inputFileFullPath, isOtherLang, model) when not isOtherLang && model.OutputKind = OutputKind.Html - && not (Path.GetFileNameWithoutExtension(inputFileFullPath) = "index") + && (Path.GetFileNameWithoutExtension(inputFileFullPath) <> "index") -> { model with IsActive = diff --git a/src/fsdocs-tool/ProjectCracker.fs b/src/fsdocs-tool/ProjectCracker.fs index b2266a82a..2e5980515 100644 --- a/src/fsdocs-tool/ProjectCracker.fs +++ b/src/fsdocs-tool/ProjectCracker.fs @@ -161,11 +161,12 @@ module DotNetCli = module Crack = + [] let (|ConditionEquals|_|) (str: string) (arg: string) = if System.String.Compare(str, arg, System.StringComparison.OrdinalIgnoreCase) = 0 then - Some() + ValueSome() else - None + ValueNone let msbuildPropBool (s: string) = let trimmed = s.Trim() diff --git a/tests/FSharp.CodeFormat.Tests/CodeFormatTests.fs b/tests/FSharp.CodeFormat.Tests/CodeFormatTests.fs index ffc0df941..c613703fb 100644 --- a/tests/FSharp.CodeFormat.Tests/CodeFormatTests.fs +++ b/tests/FSharp.CodeFormat.Tests/CodeFormatTests.fs @@ -23,6 +23,7 @@ let containsSpan f snips = |> Seq.exists (fun (Snippet(_, lines)) -> lines |> Seq.exists (fun (Line(_, spans)) -> spans |> Seq.exists f)) // Check that tool tips contains a specified token +[] let (|ToolTipWithLiteral|_|) text tips = if Seq.exists @@ -31,9 +32,9 @@ let (|ToolTipWithLiteral|_|) text tips = | _ -> false) tips then - Some() + ValueSome() else - None + ValueNone // -------------------------------------------------------------------------------------- // Test that some basic things work