Skip to content

Commit 13e75e7

Browse files
committed
Core,Tests: fix FSharpLint warning
Fixing the warning for FavourStaticEmptyFields rule.
1 parent 20d8a99 commit 13e75e7

File tree

54 files changed

+342
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+342
-209
lines changed

src/FSharpLint.Core/Application/Configuration.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module FSharpJsonConverter =
3939
else innerType
4040
let value = serializer.Deserialize(reader, innerType)
4141
let cases = FSharpType.GetUnionCases(t)
42-
if isNull value then FSharpValue.MakeUnion(cases.[0], [||])
42+
if isNull value then FSharpValue.MakeUnion(cases.[0], Array.empty)
4343
else FSharpValue.MakeUnion(cases.[1], [|value|])
4444

4545
let private converters =
@@ -104,7 +104,7 @@ module IgnoreFiles =
104104
else doesGlobSeqMatchPathSeq remaining currentlyMatchingGlobs
105105
| [] -> false
106106

107-
doesGlobSeqMatchPathSeq path []
107+
doesGlobSeqMatchPathSeq path List.Empty
108108

109109
let shouldFileBeIgnored (ignorePaths:Ignore list) (filePath:string) =
110110
let segments = filePath.Split Path.DirectorySeparatorChar |> Array.toList
@@ -374,7 +374,7 @@ with
374374
this.noTabCharacters |> Option.bind (constructRuleIfEnabled NoTabCharacters.rule) |> Option.toArray
375375
|] |> Array.concat
376376

377-
let private getOrEmptyList hints = hints |> Option.defaultValue [||]
377+
let private getOrEmptyList hints = hints |> Option.defaultValue Array.empty
378378

379379
type HintConfig = {
380380
add:string [] option

src/FSharpLint.Core/Application/Lint.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ module Lint =
497497
| LintResult.Success warnings ->
498498
(List.append warnings successes, failures)
499499
| LintResult.Failure err ->
500-
(successes, err :: failures)) ([], [])
500+
(successes, err :: failures)) (List.Empty, List.Empty)
501501

502502
match failures with
503503
| [] ->

src/FSharpLint.Core/Framework/AbstractSyntaxArray.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,5 @@ module AbstractSyntaxArray =
300300
else
301301
breadcrumbs
302302

303-
if i = 0 then []
304-
else getBreadcrumbs [] (syntaxArray.[i].ParentIndex) |> List.rev
303+
if i = 0 then List.Empty
304+
else getBreadcrumbs List.Empty (syntaxArray.[i].ParentIndex) |> List.rev

src/FSharpLint.Core/Framework/Ast.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module Ast =
6868

6969
match functionApplication with
7070
| AstNode.Expression(SynExpr.App(_, _, _, _, range) as functionApplication) ->
71-
Some(flatten [] functionApplication, range)
71+
Some(flatten List.Empty functionApplication, range)
7272
| _ -> None
7373

7474
[<NoEquality; NoComparison>]
@@ -100,7 +100,7 @@ module Ast =
100100

101101
match lambda with
102102
| AstNode.Expression(SynExpr.Lambda(_, _, _, _, _, range, _) as lambda) ->
103-
getLambdaParametersAndExpression [] lambda
103+
getLambdaParametersAndExpression List.Empty lambda
104104
|> Option.map (fun x -> (x, range))
105105
| _ -> None
106106

@@ -174,7 +174,7 @@ module Ast =
174174
match pat with
175175
| SynSimplePats.SimplePats(patterns, _range) -> patterns @ acc
176176
| SynSimplePats.Typed(patterns, _type, _range) -> loop patterns acc
177-
loop simplePats []
177+
loop simplePats List.Empty
178178

179179
let inline private memberDefinitionChildren node add =
180180
match node with

src/FSharpLint.Core/Framework/HintParser.fs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace FSharpLint.Framework
22

3+
open System
34
open FParsec
45
open FSharp.Compiler.Tokenization
56

@@ -146,7 +147,7 @@ module HintParser =
146147

147148
override this.GetHashCode() = hash (this.AnyMatch, hash this.Lookup)
148149

149-
static member Empty = { Lookup = Dictionary<_, _>(); AnyMatch = [] }
150+
static member Empty = { Lookup = Dictionary<_, _>(); AnyMatch = List.Empty }
150151

151152
let private getConstKey = function
152153
| Constant.Unit -> SyntaxHintNode.Unit
@@ -235,7 +236,7 @@ module HintParser =
235236
| HintExpr(Expression.Constant(_))
236237
| HintExpr(Expression.Null)
237238
| HintExpr(Expression.Wildcard)
238-
| HintExpr(Expression.Variable(_)) -> []
239+
| HintExpr(Expression.Variable(_)) -> List.Empty
239240
| HintPat(Pattern.Cons(lhs, rhs))
240241
| HintPat(Pattern.Or(lhs, rhs)) -> [HintPat lhs; HintPat rhs]
241242
| HintPat(Pattern.Array(patterns))
@@ -246,7 +247,7 @@ module HintParser =
246247
| HintPat(Pattern.Identifier(_))
247248
| HintPat(Pattern.Constant(_))
248249
| HintPat(Pattern.Wildcard)
249-
| HintPat(Pattern.Null) -> []
250+
| HintPat(Pattern.Null) -> List.Empty
250251

251252
let private getConstantHashCode = function
252253
| Constant.Bool(x) -> hash x
@@ -320,7 +321,7 @@ module HintParser =
320321
transposeHead next rest
321322
| [] -> builtList
322323

323-
transposeHead [] hintLists
324+
transposeHead List.Empty hintLists
324325

325326
let isAnyMatch = function
326327
| ((SyntaxHintNode.Wildcard | SyntaxHintNode.Variable), _, _, _) -> true
@@ -387,7 +388,7 @@ module HintParser =
387388
getEdges transposed
388389

389390
let charListToString charList =
390-
Seq.fold (fun x y -> x + y.ToString()) "" charList
391+
Seq.fold (fun x y -> x + y.ToString()) String.Empty charList
391392

392393
let pischar chars : Parser<char, 'T> =
393394
satisfy (fun x -> List.exists ((=) x) chars)
@@ -424,7 +425,7 @@ module HintParser =
424425
pidentstartchar .>>. many pidentchar
425426
|>> fun (start, rest) -> start::rest
426427
>>= fun ident ->
427-
let identStr = System.String.Join("", ident)
428+
let identStr = System.String.Join(String.Empty, ident)
428429

429430
let isKeyword = List.exists ((=) identStr) FSharpKeywords.KeywordNames
430431

@@ -902,9 +903,9 @@ module HintParser =
902903
let addInfixOperator prefix precedence associativity =
903904
let remainingOpChars =
904905
if prefix = "=" then
905-
notFollowedBy (pstring "==>") |>> fun _ -> ""
906+
notFollowedBy (pstring "==>") |>> fun _ -> String.Empty
906907
else if prefix = "|" then
907-
notFollowedBy (pstring "]") |>> fun _ -> ""
908+
notFollowedBy (pstring "]") |>> fun _ -> String.Empty
908909
else
909910
manySatisfy (isAnyOf Operators.opchars)
910911

@@ -922,7 +923,7 @@ module HintParser =
922923
else if prefix = "~" then
923924
manySatisfy ((=) '~')
924925
else
925-
preturn ""
926+
preturn String.Empty
926927

927928
let checkPrefix remOpChars expr =
928929
if prefix = "&" then Expression.AddressOf(true, expr)
@@ -1026,7 +1027,7 @@ module HintParser =
10261027
let addInfixOperator operator precedence associativity =
10271028
let remainingOpChars =
10281029
if operator = "|" then
1029-
notFollowedBy (pstring "]") |>> fun _ -> ""
1030+
notFollowedBy (pstring "]") |>> fun _ -> String.Empty
10301031
else
10311032
manySatisfy (isAnyOf Operators.opchars)
10321033

src/FSharpLint.Core/Framework/Utilities.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module ExpressionUtilities =
4242
checkFile.GetSymbolUseAtLocation(
4343
range.StartLine,
4444
range.EndColumn,
45-
"",
45+
String.Empty,
4646
identNames)
4747
| _ -> None
4848

@@ -94,7 +94,7 @@ module ExpressionUtilities =
9494
| _ -> None
9595

9696
let getLeadingSpaces (range:Range) (text:string) =
97-
let range = Range.mkRange "" (Position.mkPos range.StartLine 0) range.End
97+
let range = Range.mkRange String.Empty (Position.mkPos range.StartLine 0) range.End
9898
tryFindTextOfRange range text
9999
|> Option.map (fun text ->
100100
text.ToCharArray()
@@ -119,7 +119,7 @@ module ExpressionUtilities =
119119

120120
/// Counts the number of comment lines preceding the given range of text.
121121
let countPrecedingCommentLines (text:string) (startPos:pos) (endPos:pos) =
122-
let range = Range.mkRange "" startPos endPos
122+
let range = Range.mkRange String.Empty startPos endPos
123123

124124
let map (precedingText: string) =
125125
let lines =

src/FSharpLint.Core/Rules/Conventions/AvoidSinglePipeOperator.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let runner (args: AstNodeRuleParams) =
2121
let checkParentPiped (expr: AstNode) =
2222
match expr with
2323
| AstNode.Expression(SynExpr.App(_exprAtomicFlag, _isInfix, funcExpr, _argExpr, _range)) ->
24-
checkExpr funcExpr [] |> Seq.isEmpty
24+
checkExpr funcExpr List.Empty |> Seq.isEmpty
2525
| _ -> false
2626

2727
match expr with

src/FSharpLint.Core/Rules/Conventions/Binding/FavourIgnoreOverLetWild.fs

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ let private checkForBindingToAWildcard pattern range =
1414
| _ -> false
1515

1616
if findWildAndIgnoreParens pattern then
17-
{ Range = range
18-
Message = Resources.GetString("RulesFavourIgnoreOverLetWildError")
19-
SuggestedFix = None
20-
TypeChecks = [] } |> Array.singleton
17+
{
18+
Range = range
19+
Message = Resources.GetString("RulesFavourIgnoreOverLetWildError")
20+
SuggestedFix = None
21+
TypeChecks = List.Empty
22+
}
23+
|> Array.singleton
2124
else
2225
Array.empty
2326

src/FSharpLint.Core/Rules/Conventions/Binding/FavourTypedIgnore.fs

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ let private runner (args: AstNodeRuleParams) =
1919
FromRange = range
2020
ToText = identifier }))
2121

22-
{ Range = range
23-
Message = String.Format(Resources.GetString "RulesFavourTypedIgnore", identifier)
24-
SuggestedFix = Some suggestedFix
25-
TypeChecks = [] }
22+
{
23+
Range = range
24+
Message = String.Format(Resources.GetString "RulesFavourTypedIgnore", identifier)
25+
SuggestedFix = Some suggestedFix
26+
TypeChecks = List.Empty
27+
}
2628

2729
let isTyped expression identifier range text =
2830
match expression with

src/FSharpLint.Core/Rules/Conventions/Binding/TupleOfWildcards.fs

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ let private checkTupleOfWildcards pattern identifier =
2424
let refactorFrom = constructorString (List.length patterns)
2525
let refactorTo = (constructorString 1)
2626
let error = System.String.Format(errorFormat, refactorFrom, refactorTo)
27-
{ Range = range; Message = error; SuggestedFix = None; TypeChecks = [] } |> Array.singleton
27+
{
28+
Range = range
29+
Message = error
30+
SuggestedFix = None
31+
TypeChecks = List.Empty
32+
}
33+
|> Array.singleton
2834
| _ -> Array.empty
2935

3036
let private isTupleMemberArgs breadcrumbs tupleRange =

src/FSharpLint.Core/Rules/Conventions/Binding/UselessBinding.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let private checkForUselessBinding (checkInfo:FSharpCheckFileResults option) pat
2525
let checkNotMutable (ident:Ident) = fun () ->
2626
let symbol =
2727
checkInfo.GetSymbolUseAtLocation(
28-
ident.idRange.StartLine, ident.idRange.EndColumn, "", [ident.idText])
28+
ident.idRange.StartLine, ident.idRange.EndColumn, String.Empty, [ident.idText])
2929

3030
match symbol with
3131
| Some(symbol) -> isNotMutable symbol

src/FSharpLint.Core/Rules/Conventions/Binding/WildcardNamedWithAsPattern.fs

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ open FSharpLint.Framework.Rules
1010
let private checkForWildcardNamedWithAsPattern pattern =
1111
match pattern with
1212
| SynPat.Wild(range) ->
13-
{ Range = range
14-
Message = Resources.GetString("RulesWildcardNamedWithAsPattern")
15-
SuggestedFix = None
16-
TypeChecks = [] } |> Array.singleton
13+
{
14+
Range = range
15+
Message = Resources.GetString("RulesWildcardNamedWithAsPattern")
16+
SuggestedFix = None
17+
TypeChecks = List.Empty
18+
}
19+
|> Array.singleton
1720
| _ -> Array.empty
1821

1922
let private runner (args:AstNodeRuleParams) =

src/FSharpLint.Core/Rules/Conventions/CyclomaticComplexity.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type private BindingScopeComparer() =
3838

3939
/// A two-tiered stack-like structure for containing BindingScopes.
4040
type private BindingStack(maxComplexity: int) =
41-
let mutable tier1 = []
41+
let mutable tier1 = List.Empty
4242
let mutable tier2 = SortedSet<BindingScope>(BindingScopeComparer())
4343

4444
member this.Push (args:AstNodeRuleParams) (bs: BindingScope) =
@@ -76,7 +76,7 @@ type private BindingStack(maxComplexity: int) =
7676

7777
/// Clears the stack.
7878
member this.Clear() =
79-
tier1 <- []
79+
tier1 <- List.Empty
8080
tier2.Clear()
8181

8282
/// A stack to track the current cyclomatic complexity of a binding scope.
@@ -194,7 +194,7 @@ let runner (config:Config) (args:AstNodeRuleParams) : WarningDetails[] =
194194
pos.Column, pos.Line)
195195
|> Seq.map (fun scope -> // transform into WarningDetails
196196
let errMsg = String.Format(Resources.GetString("RulesCyclomaticComplexityError"), scope.Complexity, config.MaxComplexity)
197-
{ Range = scope.Binding.RangeOfBindingWithRhs; Message = errMsg; SuggestedFix = None; TypeChecks = [] })
197+
{ Range = scope.Binding.RangeOfBindingWithRhs; Message = errMsg; SuggestedFix = None; TypeChecks = List.Empty })
198198
|> Seq.toList
199199
let ret = match warningDetails with
200200
| Some x -> x::fromStack

src/FSharpLint.Core/Rules/Conventions/FavourNonMutablePropertyInitialization.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ let rec private processLetBinding (instanceNames: Set<string>) (body: SynExpr) :
5353
Array.append
5454
(processLetBinding instanceNames expr1)
5555
(processLetBinding instanceNames expr2)
56-
| _ -> [||]
56+
| _ -> Array.empty
5757

5858
and processExpression (expression: SynExpr) : array<WarningDetails> =
5959
match expression with
6060
| SynExpr.LetOrUse(_, _, bindings, body, _, _) ->
61-
let instanceNames = extraFromBindings bindings [] |> Set.ofList
61+
let instanceNames = extraFromBindings bindings List.Empty |> Set.ofList
6262
processLetBinding instanceNames body
6363
| SynExpr.Sequential(_, _, expr1, expr2, _) ->
6464
Array.append
@@ -69,7 +69,7 @@ and processExpression (expression: SynExpr) : array<WarningDetails> =
6969
let runner args =
7070
match args.AstNode with
7171
| Binding(SynBinding(_, _, _, _, _, _, _, _, _, SynExpr.LetOrUse(_, _, bindings, body, _, _), _, _, _)) ->
72-
let instanceNames = extraFromBindings bindings [] |> Set.ofList
72+
let instanceNames = extraFromBindings bindings List.Empty |> Set.ofList
7373
processLetBinding instanceNames body
7474
| Match(SynMatchClause(_, _, expr, _, _, _)) ->
7575
processExpression expr

src/FSharpLint.Core/Rules/Conventions/FunctionReimplementation/CanBeReplacedWithComposition.fs

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ let private validateLambdaCannotBeReplacedWithComposition _ lambda range =
4141
| _ -> false
4242

4343
if canBeReplacedWithFunctionComposition lambda.Body then
44-
{ Range = range
45-
Message = Resources.GetString("RulesCanBeReplacedWithComposition")
46-
SuggestedFix = None
47-
TypeChecks = [] } |> Array.singleton
44+
{
45+
Range = range
46+
Message = Resources.GetString("RulesCanBeReplacedWithComposition")
47+
SuggestedFix = None
48+
TypeChecks = List.Empty
49+
}
50+
|> Array.singleton
4851
else
4952
Array.empty
5053

src/FSharpLint.Core/Rules/Conventions/FunctionReimplementation/ReimplementsFunction.fs

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ let private validateLambdaIsNotPointless (text:string) lambda range =
3535
ExpressionUtilities.tryFindTextOfRange range text
3636
|> Option.map (fun fromText -> { FromText = fromText; FromRange = range; ToText = identifier }))
3737

38-
{ Range = range
39-
Message = String.Format(Resources.GetString("RulesReimplementsFunction"), identifier)
40-
SuggestedFix = Some suggestedFix
41-
TypeChecks = [] }
38+
{
39+
Range = range
40+
Message = String.Format(Resources.GetString("RulesReimplementsFunction"), identifier)
41+
SuggestedFix = Some suggestedFix
42+
TypeChecks = List.Empty
43+
}
4244

4345
let argumentsAsIdentifiers =
4446
lambda.Arguments

0 commit comments

Comments
 (0)