Skip to content

Commit c8c9918

Browse files
committed
FSharpLint code-cleanup
1 parent 22fe794 commit c8c9918

24 files changed

+215
-220
lines changed

fsharplint.json

+5
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@
424424
"id >> f ===> f",
425425
"f >> id ===> f",
426426

427+
"x = null ===> isNull x",
428+
"null = x ===> isNull x",
429+
"x <> null ===> not (isNull x)",
430+
"null <> x ===> not (isNull x)",
431+
427432
"Array.append a (Array.append b c) ===> Array.concat [|a; b; c|]"
428433
]
429434
}

paket.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -2584,10 +2584,10 @@ GROUP SourceFiles
25842584
STORAGE: NONE
25852585
GITHUB
25862586
remote: fsprojects/FSharp.TypeProviders.SDK
2587-
src/ProvidedTypes.fs (d3888ccc3945ca846c01945d4876bdd5701490f6)
2588-
src/ProvidedTypes.fsi (d3888ccc3945ca846c01945d4876bdd5701490f6)
2587+
src/ProvidedTypes.fs (b7c930b0bd9e0e0476981ba0813ac17e7d61742b)
2588+
src/ProvidedTypes.fsi (b7c930b0bd9e0e0476981ba0813ac17e7d61742b)
25892589
remote: Thorium/Linq.Expression.Optimizer
2590-
src/Code/ExpressionOptimizer.fs (c983f5148fccf860d84fee244f6c903cb2627c41)
2590+
src/Code/ExpressionOptimizer.fs (5becd34b8e1c20477cd462a7699a8af764ecb6e4)
25912591
GROUP Tests
25922592
STORAGE: PACKAGES
25932593
RESTRICTION: || (== net472) (== netcoreapp3.1)

src/SQLProvider.DesignTime/SqlDesignTime.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ type public SqlTypeProvider(config: TypeProviderConfig) as this =
529529
| sproc::rest -> generateTypeTree con (walkSproc con [] None createdTypes sproc) rest
530530

531531
serviceType.AddMembersDelayed( fun () ->
532-
let schemaMap = new System.Collections.Generic.Dictionary<string, ProvidedTypeDefinition>()
532+
let schemaMap = System.Collections.Generic.Dictionary<string, ProvidedTypeDefinition>()
533533
let getOrAddSchema name =
534534
match schemaMap.TryGetValue name with
535535
| true, pt -> pt

src/SQLProvider.Runtime/DataTable.fs

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ module DataTable =
3030
cache.Values |> Seq.toList
3131

3232
let mapChoose (f:DataRow -> 'a option) (dt:DataTable) =
33-
if dt <> null
34-
then
33+
if isNull dt then []
34+
else
3535
[
3636
for row in dt.Rows do
3737
match f row with
3838
| Some(a) -> yield a
3939
| None -> ()
4040
]
41-
else []
4241

4342
let choose (f : DataRow -> DataRow option) (dt:DataTable) =
4443
let copy = dt.Clone()
@@ -63,9 +62,9 @@ module DataTable =
6362
]
6463

6564
let printDataTable (dt:System.Data.DataTable) =
66-
if dt <> null
67-
then
68-
let widths = new Dictionary<int, int>()
65+
if isNull dt then ()
66+
else
67+
let widths = Dictionary<int, int>()
6968

7069
let computeMaxWidth indx length =
7170
let len =

src/SQLProvider.Runtime/Providers.Firebird.fs

+19-21
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ module Firebird =
131131
let mutable findDbType : (string -> TypeMapping option) = fun _ -> failwith "!"
132132

133133
let createCommandParameter sprocCommand (param:QueryParameter) value =
134-
let mapping = if value <> null && (not sprocCommand) then (findClrType (value.GetType().ToString())) else None
135-
let value = if value = null then (box System.DBNull.Value) else value
134+
let mapping = if (not(isNull value)) && (not sprocCommand) then (findClrType (value.GetType().ToString())) else None
135+
let value = if isNull value then (box System.DBNull.Value) else value
136136

137137
let parameterType = parameterType.Value
138138
let firebirdDbTypeSetter =
@@ -211,19 +211,19 @@ module Firebird =
211211
| :? System.Reflection.ReflectionTypeLoadException as ex ->
212212
let errorfiles = ex.LoaderExceptions |> Array.map(fun e -> e.GetBaseException().Message) |> Seq.distinct |> Seq.toArray
213213
let msg = ex.GetBaseException().Message + "\r\n" + String.Join("\r\n", errorfiles)
214-
raise(new System.Reflection.TargetInvocationException(msg, ex))
215-
| :? System.Reflection.TargetInvocationException as ex when (ex.InnerException <> null && ex.InnerException :? DllNotFoundException) ->
214+
raise(System.Reflection.TargetInvocationException(msg, ex))
215+
| :? System.Reflection.TargetInvocationException as ex when ((not(isNull ex.InnerException)) && ex.InnerException :? DllNotFoundException) ->
216216
let platform = Reflection.getPlatform(System.Reflection.Assembly.GetExecutingAssembly())
217217
let msg = ex.GetBaseException().Message + ", Path: " + (System.IO.Path.GetFullPath resolutionPath) +
218218
(if platform <> "" then Environment.NewLine + "Current execution platform: " + platform else "")
219-
raise(new System.Reflection.TargetInvocationException(msg, ex))
219+
raise(System.Reflection.TargetInvocationException(msg, ex))
220220
| :? System.TypeInitializationException as te when (te.InnerException :? System.Reflection.TargetInvocationException) ->
221221
let ex = te.InnerException :?> System.Reflection.TargetInvocationException
222222
let platform = Reflection.getPlatform(System.Reflection.Assembly.GetExecutingAssembly())
223223
let msg = ex.GetBaseException().Message + ", Path: " + (System.IO.Path.GetFullPath resolutionPath) +
224224
(if platform <> "" then Environment.NewLine + "Current execution platform: " + platform else "")
225-
raise(new System.Reflection.TargetInvocationException(msg, ex.InnerException))
226-
| :? System.TypeInitializationException as te when (te.InnerException <> null) -> raise (te.GetBaseException())
225+
raise(System.Reflection.TargetInvocationException(msg, ex.InnerException))
226+
| :? System.TypeInitializationException as te when not(isNull te.InnerException) -> raise (te.GetBaseException())
227227

228228
let createCommand commandText connection =
229229
Activator.CreateInstance(commandType.Value,[|box commandText;box connection|]) :?> IDbCommand
@@ -279,15 +279,15 @@ module Firebird =
279279
|> Option.map (fun m ->
280280
let ordinal_position = Sql.dbUnboxWithDefault<int16> 0s row.["ORDINAL_POSITION"] |> Convert.ToInt32
281281
let parameter_mode = Sql.dbUnbox<int16> row.["PARAMETER_MODE"] |> Convert.ToInt32
282-
//let returnValue = argumentName = null && ordinal_position = 0
282+
//let returnValue = isNull argumentName && ordinal_position = 0
283283
let direction =
284284
match parameter_mode with
285285
| 0 -> ParameterDirection.Input
286286
| 1 -> ParameterDirection.Output
287287
//| "INOUT" -> ParameterDirection.InputOutput
288288
//| null when returnValue -> ParameterDirection.ReturnValue
289289
| a -> failwithf "Direction not supported %s %i" argumentName a
290-
{ Name = if argumentName = null then failwithf "Parameter name is null for procedure %s" argumentName else argumentName
290+
{ Name = if isNull argumentName then failwithf "Parameter name is null for procedure %s" argumentName else argumentName
291291
TypeMapping = m
292292
Direction = direction
293293
Length = maxLength
@@ -324,11 +324,9 @@ module Firebird =
324324
|> Seq.toList
325325

326326
let readParameter (parameter:IDbDataParameter) =
327-
if parameter <> null then
327+
if isNull parameter then null else
328328
let par = parameter
329329
par.Value
330-
else null
331-
332330

333331
let processReturnColumn reader (outps:(int*IDbDataParameter)[]) (retCol:QueryParameter) =
334332
match retCol.TypeMapping.ProviderTypeName with
@@ -558,7 +556,7 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
558556
use reader = com.ExecuteReader()
559557
if reader.Read() then
560558
let comm = reader.GetString(0)
561-
if comm <> null then comm else ""
559+
if isNull comm then "" else comm
562560
else ""
563561
member __.GetColumnDescription(con,tableName,columnName) =
564562
let sn = tableName.Substring(0,tableName.LastIndexOf("."))
@@ -574,7 +572,7 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
574572
use reader = com.ExecuteReader()
575573
if reader.Read() then
576574
let comm = reader.GetString(0)
577-
if comm <> null then comm else ""
575+
if isNull comm then "" else comm
578576
else ""
579577
member __.CreateConnection(connectionString) = Firebird.createConnection connectionString
580578
member __.CreateCommand(connection,commandText) = Firebird.createCommand commandText connection
@@ -828,14 +826,14 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
828826
match operator with
829827
| FSharp.Data.Sql.In -> "1<>1" // nothing is in the empty set
830828
| FSharp.Data.Sql.NotIn -> "1=1" // anything is not in the empty set
831-
| _ -> failwith "Should not be called with any other operator"
829+
| _ -> failwithf "Should not be called with any other operator (%O)" operator
832830
else
833831
let text = String.Join(",", array |> Array.map (fun p -> p.ParameterName))
834832
Array.iter parameters.Add array
835833
match operator with
836834
| FSharp.Data.Sql.In -> sprintf "%s IN (%s)" column text
837835
| FSharp.Data.Sql.NotIn -> sprintf "%s NOT IN (%s)" column text
838-
| _ -> failwith "Should not be called with any other operator"
836+
| _ -> failwithf "Should not be called with any other operator (%O)" operator
839837

840838
let prefix = if i>0 then (sprintf " %s " op) else ""
841839
let paras = extractData data
@@ -848,7 +846,7 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
848846
| FSharp.Data.Sql.NestedNotIn -> sprintf "%s NOT IN (%s)" column innersql
849847
| FSharp.Data.Sql.NestedExists -> sprintf "EXISTS (%s)" innersql
850848
| FSharp.Data.Sql.NestedNotExists -> sprintf "NOT EXISTS (%s)" innersql
851-
| _ -> failwith "Should not be called with any other operator"
849+
| _ -> failwithf "Should not be called with any other operator (%O)" operator
852850

853851
~~(sprintf "%s%s" prefix <|
854852
match operator with
@@ -1109,9 +1107,9 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
11091107
// remove the pk to prevent this attempting to be used again
11101108
e.SetPkColumnOptionSilent(schemaCache.PrimaryKeys.[e.Table.Name], None)
11111109
e._State <- Deleted
1112-
| Deleted | Unchanged -> failwith "Unchanged entity encountered in update list - this should not be possible!")
1110+
| Deleted | Unchanged -> failwithf "Unchanged entity encountered in update list - this should not be possible! (%O)" e)
11131111

1114-
if scope<>null then scope.Complete() //scope.Complete()
1112+
if not(isNull scope) then scope.Complete() //scope.Complete()
11151113

11161114
finally
11171115
con.Close()
@@ -1166,11 +1164,11 @@ type internal FirebirdProvider(resolutionPath, contextSchemaPath, owner, referen
11661164
e.SetPkColumnOptionSilent(schemaCache.PrimaryKeys.[e.Table.Name], None)
11671165
e._State <- Deleted
11681166
}
1169-
| Deleted | Unchanged -> failwith "Unchanged entity encountered in update list - this should not be possible!"
1167+
| Deleted | Unchanged -> failwithf "Unchanged entity encountered in update list - this should not be possible! (%O)" e
11701168

11711169
let! _ = Sql.evaluateOneByOne handleEntity (CommonTasks.sortEntities entities |> Seq.toList)
11721170

1173-
if scope<>null then scope.Complete()
1171+
if not(isNull scope) then scope.Complete()
11741172

11751173
finally
11761174
con.Close()

src/SQLProvider.Runtime/Providers.MSAccess.fs

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type internal MSAccessProvider(contextSchemaPath) =
3535
let dt = con.GetSchema("DataTypes")
3636

3737
let getDbType(providerType:int) =
38-
let p = new OleDbParameter()
38+
let p = OleDbParameter()
3939
p.OleDbType <- (Enum.ToObject(typeof<OleDbType>, providerType) :?> OleDbType)
4040
p.DbType
4141

@@ -584,7 +584,7 @@ type internal MSAccessProvider(contextSchemaPath) =
584584
//add in 'numLinks' open parens, after FROM, closing each after each JOIN statement
585585
let numLinks = sqlQuery.Links.Length
586586
if isDeleteScript then
587-
~~(sprintf "DELETE FROM %s[%s] " (new String('(',numLinks)) (baseTable.Name.Replace("\"","")))
587+
~~(sprintf "DELETE FROM %s[%s] " (String('(',numLinks)) (baseTable.Name.Replace("\"","")))
588588
else
589589
// SELECT
590590
if sqlQuery.Distinct && sqlQuery.Count then
@@ -597,7 +597,7 @@ type internal MSAccessProvider(contextSchemaPath) =
597597
// FROM
598598

599599
let bal = if baseAlias = "" then baseTable.Name else baseAlias
600-
~~(sprintf "FROM %s[%s] as [%s] " (new String('(',numLinks)) (baseTable.Name.Replace("\"","")) bal)
600+
~~(sprintf "FROM %s[%s] as [%s] " (String('(',numLinks)) (baseTable.Name.Replace("\"","")) bal)
601601
sqlQuery.CrossJoins |> Seq.iter(fun (a,t) -> ~~(sprintf ", [%s] as [%s] " (t.Name.Replace("\"","")) a))
602602

603603
fromBuilder(numLinks)
@@ -696,7 +696,7 @@ type internal MSAccessProvider(contextSchemaPath) =
696696
// remove the pk to prevent this attempting to be used again
697697
e.SetPkColumnOptionSilent(schemaCache.PrimaryKeys.[e.Table.FullName], None)
698698
e._State <- Deleted
699-
| Deleted | Unchanged -> failwith "Unchanged entity encountered in update list - this should not be possible!")
699+
| Deleted | Unchanged -> failwithf "Unchanged entity encountered in update list - this should not be possible! (%O)" e)
700700
trnsx.Commit()
701701

702702
with _ ->
@@ -760,7 +760,7 @@ type internal MSAccessProvider(contextSchemaPath) =
760760
e.SetPkColumnOptionSilent(schemaCache.PrimaryKeys.[e.Table.FullName], None)
761761
e._State <- Deleted
762762
}
763-
| Deleted | Unchanged -> failwith "Unchanged entity encountered in update list - this should not be possible!"
763+
| Deleted | Unchanged -> failwithf "Unchanged entity encountered in update list - this should not be possible! (%O)" e
764764

765765
let! _ = Sql.evaluateOneByOne handleEntity (CommonTasks.sortEntities entities |> Seq.toList)
766766
trnsx.Commit()

0 commit comments

Comments
 (0)