Skip to content

Commit 86faa18

Browse files
authored
[All] Fix ~28 code scanning warnings (batch 2) (#4371)
1 parent 9d87067 commit 86faa18

15 files changed

Lines changed: 86 additions & 62 deletions

src/Fable.Compiler/Globbing.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module Glob =
5454
| Drive name :: t ->
5555
let subDirs = List.collect (checkSubDirs true name) acc
5656
buildPaths subDirs t
57-
| Recursive :: [] ->
57+
| [ Recursive ] ->
5858
let dirs =
5959
Seq.collect
6060
(fun dir ->

src/Fable.Transforms/Dart/Replacements.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,13 +2406,13 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
24062406
Helper.LibCall(com, "Decimal", "pow", t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
24072407
|> Some
24082408
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangechar-function-%5bfsharp%5d
2409-
// Type: RangeChar : char -> char -> seq<char>
2409+
// Type: RangeChar : char -> char -> char seq
24102410
// Usage: RangeChar start stop
24112411
| "RangeChar", None, _ ->
24122412
Helper.LibCall(com, "Range", "rangeChar", t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
24132413
|> Some
24142414
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
2415-
// Type: RangeDouble: float -> float -> float -> seq<float>
2415+
// Type: RangeDouble: float -> float -> float -> float seq
24162416
// Usage: RangeDouble start step stop
24172417
| ("RangeSByte" | "RangeByte" | "RangeInt16" | "RangeUInt16" | "RangeInt32" | "RangeUInt32" | "RangeSingle" | "RangeDouble"),
24182418
None,

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ module Helpers =
710710
if ent.IsFSharpModule then
711711
match trimRootModule, entName with
712712
| TrimRootModule com, _ when com.Options.Language = Rust -> memb.CompiledName, Naming.NoMemberPart // module prefix for Rust
713-
| _, "" -> memb.CompiledName, Naming.NoMemberPart
713+
| _, s when System.String.IsNullOrEmpty(s) -> memb.CompiledName, Naming.NoMemberPart
714714
| _, moduleName -> moduleName, Naming.StaticMemberPart(memb.CompiledName, "")
715715
else
716716
let overloadSuffix = getOverloadSuffixFrom ent memb
@@ -1374,7 +1374,7 @@ module TypeHelpers =
13741374

13751375
// Filter measure generic arguments here? (for that we need to pass the compiler, which needs a bigger refactoring)
13761376
// Currently for Dart we're doing it in the Fable2Dart step
1377-
let makeTypeGenArgsWithConstraints withConstraints ctxTypeArgs (genArgs: seq<FSharpType>) =
1377+
let makeTypeGenArgsWithConstraints withConstraints ctxTypeArgs (genArgs: FSharpType seq) =
13781378
genArgs
13791379
|> Seq.mapToList (fun genArg ->
13801380
if genArg.IsGenericParameter then
@@ -1383,7 +1383,7 @@ module TypeHelpers =
13831383
makeTypeWithConstraints withConstraints ctxTypeArgs genArg
13841384
)
13851385

1386-
let makeTypeGenArgs ctxTypeArgs (genArgs: seq<FSharpType>) =
1386+
let makeTypeGenArgs ctxTypeArgs (genArgs: FSharpType seq) =
13871387
makeTypeGenArgsWithConstraints true ctxTypeArgs genArgs
13881388

13891389
let makeTypeFromDelegate withConstraints ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =

src/Fable.Transforms/FSharp2Fable.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ let rec private getUsedRootNames (com: Compiler) (usedNames: Set<string>) decls
20092009
usedNames
20102010
else
20112011
match getEntityDeclarationName com entRef with
2012-
| "" -> usedNames
2012+
| s when System.String.IsNullOrEmpty(s) -> usedNames
20132013
| entName ->
20142014
let reflectionSuffix =
20152015
match com.Options.Language with
@@ -2056,7 +2056,7 @@ let rec private transformDeclarations (com: FableCompiler) ctx fsDecls =
20562056
// If the file is empty F# creates a class for the module, but Fable clears the name
20572057
// because it matches the root module so it becomes invalid JS, see #2350
20582058
match getEntityDeclarationName com entRef with
2059-
| "" -> []
2059+
| s when System.String.IsNullOrEmpty(s) -> []
20602060
| name ->
20612061
[
20622062
Fable.ClassDeclaration

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ module Util =
10101010
str.Split('\n')
10111011
|> Array.skipWhile (fun line ->
10121012
match line.Trim() with
1013-
| "" -> true
1013+
| s when System.String.IsNullOrEmpty(s) -> true
10141014
| Naming.Regex IMPORT_REGEX (_ :: selector :: path :: _) ->
10151015
if selector.StartsWith("{", StringComparison.Ordinal) then
10161016
for selector in selector.TrimStart('{').TrimEnd('}').Split(',') do

src/Fable.Transforms/Global/Prelude.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ module Path =
418418
let toPath = addDummyFile toIsDir toFullPath |> normalizePath
419419

420420
match (pathDifference fromPath toPath).Replace(dummyFile, "") with
421-
| "" -> "."
421+
| s when System.String.IsNullOrEmpty(s) -> "."
422422
// Some folders start with a period, see #1599
423423
| path when isRelativePath path -> path
424424
| path -> "./" + path
@@ -458,7 +458,7 @@ module Path =
458458

459459
commonPrefix.Length >= parent.Length
460460

461-
let getCommonBaseDir (filePaths: seq<string>) =
461+
let getCommonBaseDir (filePaths: string seq) =
462462
filePaths
463463
|> Seq.map (fun filePath ->
464464
filePath

src/Fable.Transforms/Php/Fable2Php.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ let rec convertExpr (com: IPhpCompiler) (expr: Fable.Expr) =
12051205
//| _ -> printfn "%A" t
12061206

12071207
match fixNsName (Path.GetFileNameWithoutExtension(info.Path)) with
1208-
| "" ->
1208+
| s when System.String.IsNullOrEmpty(s) ->
12091209
match com.IsImport info.Selector with
12101210
| Some true ->
12111211
let name = fixName info.Selector

src/Fable.Transforms/Python/Fable2Python.Annotation.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ let stdlibModuleTypeHint com ctx moduleName memberName genArgs repeatedGenerics
336336
let makeGenTypeParamInst com ctx (genArgs: Fable.Type list) (repeatedGenerics: Set<string> option) =
337337
match genArgs with
338338
| [] -> []
339-
| _ -> genArgs |> List.map (typeAnnotation com ctx repeatedGenerics) |> List.map fst
339+
| _ -> genArgs |> List.map (typeAnnotation com ctx repeatedGenerics >> fst)
340340

341341
let makeGenericTypeAnnotation
342342
(com: IPythonCompiler)

src/Fable.Transforms/Python/Fable2Python.Transforms.fs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ let private getExceptionTypeExpr (com: IPythonCompiler) ctx =
12331233
| Fable.DeclaredType(entRef, _) -> Annotation.tryPyConstructor com ctx (com.GetEntity(entRef))
12341234
| _ -> None
12351235

1236-
let transformTryCatch com (ctx: Context) r returnStrategy (body, catch: option<Fable.Ident * Fable.Expr>, finalizer) =
1236+
let transformTryCatch com (ctx: Context) r returnStrategy (body, catch: (Fable.Ident * Fable.Expr) option, finalizer) =
12371237
// try .. catch statements cannot be tail call optimized
12381238
let ctx = { ctx with TailCallOpportunity = None }
12391239

@@ -3278,32 +3278,35 @@ let declareDataClassType
32783278
let interfaceBases =
32793279
ent.AllInterfaces
32803280
|> List.ofSeq
3281-
|> List.filter (fun int ->
3281+
|> List.choose (fun int ->
32823282
let name = Helpers.removeNamespace (int.Entity.FullName)
3283-
allowedInterfaces |> List.contains name
3284-
)
3285-
|> List.map (fun int ->
3286-
// Filter out self-referential generic arguments to avoid forward reference errors
3287-
let genericArgs =
3288-
int.GenericArgs
3289-
|> List.filter (fun genArg ->
3290-
match genArg with
3291-
| Fable.DeclaredType({ FullName = fullName }, _) -> Helpers.removeNamespace (fullName) <> entName
3292-
| _ -> true
3293-
)
32943283

3295-
// Generate the EnumerableBase reference from bases module
3296-
if List.isEmpty genericArgs then
3297-
libValue com ctx "bases" "EnumerableBase"
3284+
if not (allowedInterfaces |> List.contains name) then
3285+
None
32983286
else
3299-
let typeArgs =
3300-
genericArgs
3301-
|> List.map (fun genArg ->
3302-
let arg, _ = Annotation.typeAnnotation com ctx None genArg
3303-
arg
3287+
// Filter out self-referential generic arguments to avoid forward reference errors
3288+
let genericArgs =
3289+
int.GenericArgs
3290+
|> List.filter (fun genArg ->
3291+
match genArg with
3292+
| Fable.DeclaredType({ FullName = fullName }, _) ->
3293+
Helpers.removeNamespace (fullName) <> entName
3294+
| _ -> true
33043295
)
33053296

3306-
Expression.subscript (libValue com ctx "bases" "EnumerableBase", Expression.tuple typeArgs)
3297+
// Generate the EnumerableBase reference from bases module
3298+
if List.isEmpty genericArgs then
3299+
libValue com ctx "bases" "EnumerableBase" |> Some
3300+
else
3301+
let typeArgs =
3302+
genericArgs
3303+
|> List.map (fun genArg ->
3304+
let arg, _ = Annotation.typeAnnotation com ctx None genArg
3305+
arg
3306+
)
3307+
3308+
Expression.subscript (libValue com ctx "bases" "EnumerableBase", Expression.tuple typeArgs)
3309+
|> Some
33073310
)
33083311

33093312
let bases = (baseExpr |> Option.toList) @ interfaceBases
@@ -4473,8 +4476,12 @@ let transformInterface (com: IPythonCompiler) ctx (classEnt: Fable.Entity) (_cla
44734476
let interfaces =
44744477
classEnt.AllInterfaces
44754478
|> List.ofSeq
4476-
|> List.map (fun int -> int.Entity)
4477-
|> List.filter (fun ent -> ent.FullName <> classEnt.FullName)
4479+
|> List.choose (fun int ->
4480+
if int.Entity.FullName <> classEnt.FullName then
4481+
Some int.Entity
4482+
else
4483+
None
4484+
)
44784485

44794486
for ref in interfaces do
44804487
let entity = com.TryGetEntity(ref)

src/Fable.Transforms/Python/Fable2Python.Util.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ module Util =
731731
let makeStringArray strings =
732732
strings |> List.map (fun x -> Expression.stringConstant x) |> Expression.list
733733

734-
let makePyObject (pairs: seq<string * Expression>) =
734+
let makePyObject (pairs: (string * Expression) seq) =
735735
pairs
736736
|> Seq.map (fun (name, value) ->
737737
let prop = Expression.stringConstant name

0 commit comments

Comments
 (0)