diff --git a/src/Fable.Compiler/Globbing.fs b/src/Fable.Compiler/Globbing.fs index e90f2bb87c..c8c5db7bc2 100644 --- a/src/Fable.Compiler/Globbing.fs +++ b/src/Fable.Compiler/Globbing.fs @@ -1,5 +1,6 @@ module Fable.Compiler.Globbing +open System open System.Collections.Generic open System.IO @@ -140,7 +141,7 @@ module Glob = let globRoot = // If we dropped "/" from the beginning of the path in the 'Split' call, put it back! - if normPattern.StartsWith("/") then + if normPattern.StartsWith('/') then "/" + globRoot else globRoot @@ -162,9 +163,9 @@ module Glob = // names (as one folder name could be a substring of the other) let start = baseDir.TrimEnd([| Path.DirectorySeparatorChar |]) - + string Path.DirectorySeparatorChar + + string Path.DirectorySeparatorChar // See https://github.com/fsharp/FAKE/issues/1925 - if input.StartsWith start then + if input.StartsWith(start, StringComparison.Ordinal) then input.Substring start.Length else input @@ -182,7 +183,10 @@ module Glob = let baseItems = let start, rest = - if input.StartsWith "\\\\" && splits.Length >= 4 then + if + input.StartsWith("\\\\", StringComparison.Ordinal) + && splits.Length >= 4 + then let serverName = splits.[2] let share = splits.[3] @@ -197,21 +201,21 @@ module Glob = elif splits.Length >= 2 && Path.IsPathRooted input - && input.StartsWith "/" + && input.StartsWith '/' then [ Directory("/") ], splits |> Array.toSeq else if Path.IsPathRooted input then - if input.StartsWith "\\" then + if input.StartsWith '\\' then failwithf "Please remove the leading '\\' or '/' and replace them with \ - '.\\' or './' if you want to use a relative path. Leading \ - slashes are considered an absolute path (input was '%s')!" + '.\\' or './' if you want to use a relative path. Leading \ + slashes are considered an absolute path (input was '%s')!" originalInput else failwithf "Unknown globbing input '%s', try to use a \ - relative path and report an issue!" + relative path and report an issue!" originalInput [], splits |> Array.toSeq @@ -412,13 +416,13 @@ module GlobbingPatternExtensions = let included = this.Includes - |> Seq.exists (fun fileInclude -> + |> List.exists (fun fileInclude -> Glob.isMatch (fullDir fileInclude) fullPath ) let excluded = this.Excludes - |> Seq.exists (fun fileExclude -> + |> List.exists (fun fileExclude -> Glob.isMatch (fullDir fileExclude) fullPath ) @@ -465,7 +469,11 @@ module GlobbingPattern = |> Seq.filter (fun d -> directoryIncludes |> Seq.exists (fun p -> - d.StartsWith(p + string Path.DirectorySeparatorChar) && p <> d + d.StartsWith( + p + string Path.DirectorySeparatorChar, + StringComparison.Ordinal + ) + && p <> d ) |> not ) diff --git a/src/Fable.Compiler/ProjectCracker.fs b/src/Fable.Compiler/ProjectCracker.fs index 2d9a30365d..c5d0b7c67e 100644 --- a/src/Fable.Compiler/ProjectCracker.fs +++ b/src/Fable.Compiler/ProjectCracker.fs @@ -186,9 +186,9 @@ type CrackerResponse = } let isSystemPackage (pkgName: string) = - pkgName.StartsWith("System.") - || pkgName.StartsWith("Microsoft.") - || pkgName.StartsWith("runtime.") + pkgName.StartsWith("System.", StringComparison.Ordinal) + || pkgName.StartsWith("Microsoft.", StringComparison.Ordinal) + || pkgName.StartsWith("runtime.", StringComparison.Ordinal) || pkgName = "NETStandard.Library" || pkgName = "FSharp.Core" || pkgName = "Fable.Core" @@ -296,7 +296,9 @@ let tryGetFablePackage (opts: CrackerOptions) (dllPath: string) = let fsprojPath = match Map.tryFind pkgId opts.Replace with | Some replaced -> - if replaced.EndsWith(".fsproj") then + if + replaced.EndsWith(".fsproj", StringComparison.Ordinal) + then replaced else tryFileWithPattern replaced "*.fsproj" @@ -469,18 +471,24 @@ let private extractUsefulOptionsAndSources (line: string) (accSources: string list, accOptions: string list) = - if line.StartsWith("-") then + if line.StartsWith('-') then // "--warnaserror" // Disable for now to prevent unexpected errors, see #2288 - if line.StartsWith("--langversion:") && isMainProj then + if + line.StartsWith("--langversion:", StringComparison.Ordinal) + && isMainProj + then let v = line.Substring("--langversion:".Length).ToLowerInvariant() if v = "preview" then accSources, line :: accOptions else accSources, accOptions - elif line.StartsWith("--nowarn") || line.StartsWith("--warnon") then + elif + line.StartsWith("--nowarn", StringComparison.Ordinal) + || line.StartsWith("--warnon", StringComparison.Ordinal) + then accSources, line :: accOptions - elif line.StartsWith("--define:") then + elif line.StartsWith("--define:", StringComparison.Ordinal) then // When parsing the project as .csproj there will be multiple defines in the same line, // but the F# compiler seems to accept only one per line let defines = @@ -534,7 +542,7 @@ let getCrackedMainFsproj let sourceFiles, otherOpts = (projOpts, ([], [])) ||> Array.foldBack (fun line (src, otherOpts) -> - if line.StartsWith("-r:") then + if line.StartsWith("-r:", StringComparison.Ordinal) then let line = Path.normalizePath (line[3..]) let dllName = getDllName line dllRefs.Add(dllName, line) @@ -664,7 +672,12 @@ let getProjectOptionsFromProjectFile = r.CompilerArguments |> Array.map (fun line -> if reg.IsMatch(line) then - if line.StartsWith("/reference") then + if + line.StartsWith( + "/reference", + StringComparison.Ordinal + ) + then "-r" + line.Substring(10) else "--" + line.Substring(1) @@ -709,9 +722,12 @@ let getProjectOptionsFromProjectFile = let projOpts = compilerArgs - |> Array.skipWhile (fun line -> not (line.StartsWith("-"))) + |> Array.skipWhile (fun line -> not (line.StartsWith('-'))) |> Array.map (fun f -> - if f.EndsWith(".fs") || f.EndsWith(".fsi") then + if + f.EndsWith(".fs", StringComparison.Ordinal) + || f.EndsWith(".fsi", StringComparison.Ordinal) + then if Path.IsPathRooted f then f else @@ -811,7 +827,7 @@ let retryGetCrackedProjects opts = // Replace the .fsproj extension with .fableproj for files in fable_modules // We do this to avoid conflicts with other F# tooling that scan for .fsproj files let changeFsprojToFableproj (path: string) = - if path.EndsWith(".fsproj") then + if path.EndsWith(".fsproj", StringComparison.Ordinal) then IO.Path.ChangeExtension(path, Naming.fableProjExt) else path @@ -858,7 +874,7 @@ let getFableLibraryPath (opts: CrackerOptions) = | Python, Some Py.Naming.sitePackages -> "fable-library-py", "fable-library" | _, Some path -> - if path.StartsWith("./") then + if path.StartsWith("./", StringComparison.Ordinal) then "", Path.normalizeFullPath path elif IO.Path.IsPathRooted(path) then "", Path.normalizePath path @@ -969,7 +985,7 @@ let loadPrecompiledInfo (opts: CrackerOptions) otherOptions sourceFiles = // (e.g. fable_modules/Fable.Promise.2.1.0/Promise.fs) so we assume they're the same wherever they are // TODO: Check if this holds true also for Python which may not include the version number in the path let normalizePath (path: string) = - let i = path.IndexOf(Naming.fableModules) + let i = path.IndexOf(Naming.fableModules, StringComparison.Ordinal) if i >= 0 then path[i..] @@ -1238,7 +1254,7 @@ let getFullProjectOpts (opts: CrackerOptions) = if ignoredRefs.Contains(name) - || (name.StartsWith("System.") + || (name.StartsWith("System.", StringComparison.Ordinal) && not (coreRefs.Contains(name))) then None diff --git a/src/Fable.Compiler/Util.fs b/src/Fable.Compiler/Util.fs index b79e6d2b07..dd3a6a85c1 100644 --- a/src/Fable.Compiler/Util.fs +++ b/src/Fable.Compiler/Util.fs @@ -624,7 +624,8 @@ module Imports = path.Replace("../", "").Replace("./", "").Replace(":", "") let isRelativePath (path: string) = - path.StartsWith("./") || path.StartsWith("../") + path.StartsWith("./", StringComparison.Ordinal) + || path.StartsWith("../", StringComparison.Ordinal) let isAbsolutePath (path: string) = path.StartsWith('/') || path.IndexOf(':') = 1 @@ -735,7 +736,7 @@ module Imports = importPath if isAbsolutePath importPath then - if importPath.EndsWith(".fs") then + if importPath.EndsWith(".fs", StringComparison.Ordinal) then getTargetRelativePath pathResolver importPath