Skip to content

Commit

Permalink
Update F# analyzers (fsprojects#2997)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 23, 2023
1 parent 3ea6849 commit 7e7a90a
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
"fsharp-analyzers": {
"version": "0.20.2",
"version": "0.21.0",
"commands": [
"fsharp-analyzers"
]
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ Some common use cases include:
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="G-Research.FSharp.Analyzers" Version="0.3.1">
<PackageReference Include="G-Research.FSharp.Analyzers" Version="0.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>build</IncludeAssets>
</PackageReference>
<PackageReference Include="Ionide.Analyzers" Version="0.4.0">
<PackageReference Include="Ionide.Analyzers" Version="0.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<FSharpAnalyzersOtherFlags>--analyzers-path &quot;$(PkgG-Research_FSharp_Analyzers)/analyzers/dotnet/fs&quot;</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --analyzers-path &quot;$(PkgIonide_Analyzers)/analyzers/dotnet/fs&quot;</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --exclude-analyzer PartialAppAnalyzer</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --treat-as-warning GRA-STRING-001 GRA-STRING-002 GRA-STRING-003 GRA-UNIONCASE-001 IONIDE-001 IONIDE-002 IONIDE-003 IONIDE-004 IONIDE-005</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --treat-as-warning GRA-STRING-001 GRA-STRING-002 GRA-STRING-003 GRA-UNIONCASE-001 GRA-VIRTUALCALL-001 GRA-TYPE-ANNOTATE-001 GRA-UNIONCASE-001 IONIDE-001 IONIDE-002 IONIDE-003 IONIDE-004 IONIDE-005 IONIDE-006</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --verbose</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --code-root $(CodeRoot)</FSharpAnalyzersOtherFlags>
<FSharpAnalyzersOtherFlags>$(FSharpAnalyzersOtherFlags) --report &quot;$(CodeRoot)/analysisreports/$(MSBuildProjectName)-analysis.sarif&quot;</FSharpAnalyzersOtherFlags>
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Benchmarks/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"BenchmarkDotNet.Annotations": {
"type": "Transitive",
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Client.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Client/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let ``traversing collections`` () =
// It is easy to compose a function when everything is fixed, but what to do when the AST has a list of items?
let items = [ 2; 3; 4 ]
// The `col` function will traverse the collection and apply the first function between elements and the last function for each individual element.
let f (items: seq<int>) : Context -> Context =
let f (items: int seq) : Context -> Context =
col (!- " + ") items (fun (item: int) -> !- $"{item}")

// Note that there are some variants of `col` that can be used to process a collection in a different way.
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Core.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"Microsoft.NET.Test.Sdk": {
"type": "Direct",
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Core/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ let (+>) (ctx: Context -> Context) (f: _ -> Context) x =
let (!-) (str: string) = writerEvent (Write str)

/// Similar to col, and supply index as well
let coli f' (c: seq<'T>) f (ctx: Context) =
let coli f' (c: 'T seq) f (ctx: Context) =
let mutable tryPick = true
let mutable st = ctx
let mutable i = 0
Expand All @@ -453,7 +453,7 @@ let coli f' (c: seq<'T>) f (ctx: Context) =
/// Process collection - keeps context through the whole processing
/// calls f for every element in sequence and f' between every two elements
/// as a separator. This is a variant that works on typed collections.
let col f' (c: seq<'T>) f (ctx: Context) =
let col f' (c: 'T seq) f (ctx: Context) =
let mutable tryPick = true
let mutable st = ctx
let e = c.GetEnumerator()
Expand All @@ -465,7 +465,7 @@ let col f' (c: seq<'T>) f (ctx: Context) =
st

// Similar to col but pass the item of 'T to f' as well
let colEx f' (c: seq<'T>) f (ctx: Context) =
let colEx f' (c: 'T seq) f (ctx: Context) =
let mutable tryPick = true
let mutable st = ctx
let e = c.GetEnumerator()
Expand All @@ -477,11 +477,11 @@ let colEx f' (c: seq<'T>) f (ctx: Context) =
st

/// Similar to col, apply one more function f2 at the end if the input sequence is not empty
let colPost f2 f1 (c: seq<'T>) f (ctx: Context) =
let colPost f2 f1 (c: 'T seq) f (ctx: Context) =
if Seq.isEmpty c then ctx else f2 (col f1 c f ctx)

/// Similar to col, apply one more function f2 at the beginning if the input sequence is not empty
let colPre f2 f1 (c: seq<'T>) f (ctx: Context) =
let colPre f2 f1 (c: 'T seq) f (ctx: Context) =
if Seq.isEmpty c then ctx else col f1 c f (f2 ctx)

/// If there is a value, apply f and f' accordingly, otherwise do nothing
Expand Down Expand Up @@ -837,7 +837,7 @@ let exceedsWidth maxWidth f (ctx: Context) =
|| currentColumn > ctx.Config.MaxLineLength

/// Similar to col, skip auto newline for index 0
let colAutoNlnSkip0i f' (c: seq<'T>) f (ctx: Context) =
let colAutoNlnSkip0i f' (c: 'T seq) f (ctx: Context) =
coli
f'
c
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Core/Context.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ val (+>): ctx: (Context -> Context) -> f: (Context -> Context) -> x: Context ->
val (!-): str: string -> (Context -> Context)

/// Similar to col, and supply index as well
val coli: f': (Context -> Context) -> c: seq<'T> -> f: (int -> 'T -> Context -> Context) -> ctx: Context -> Context
val coli: f': (Context -> Context) -> c: 'T seq -> f: (int -> 'T -> Context -> Context) -> ctx: Context -> Context

/// Process collection - keeps context through the whole processing
/// calls f for every element in sequence and f' between every two elements
/// as a separator. This is a variant that works on typed collections.
val col: f': (Context -> Context) -> c: seq<'T> -> f: ('T -> Context -> Context) -> ctx: Context -> Context
val colEx: f': ('T -> Context -> Context) -> c: seq<'T> -> f: ('T -> Context -> Context) -> ctx: Context -> Context
val col: f': (Context -> Context) -> c: 'T seq -> f: ('T -> Context -> Context) -> ctx: Context -> Context
val colEx: f': ('T -> Context -> Context) -> c: 'T seq -> f: ('T -> Context -> Context) -> ctx: Context -> Context

/// Similar to col, apply one more function f2 at the end if the input sequence is not empty
val colPost:
f2: (Context -> Context) ->
f1: (Context -> Context) ->
c: seq<'T> ->
c: 'T seq ->
f: ('T -> Context -> Context) ->
ctx: Context ->
Context
Expand All @@ -124,7 +124,7 @@ val colPost:
val colPre:
f2: (Context -> Context) ->
f1: (Context -> Context) ->
c: seq<'T> ->
c: 'T seq ->
f: ('T -> Context -> Context) ->
ctx: Context ->
Context
Expand Down Expand Up @@ -243,7 +243,7 @@ val futureNlnCheck: f: (Context -> Context) -> ctx: Context -> bool
val exceedsWidth: maxWidth: int -> f: (Context -> Context) -> ctx: Context -> bool

/// Similar to col, skip auto newline for index 0
val colAutoNlnSkip0: f': (Context -> Context) -> c: seq<'a> -> f: ('a -> Context -> Context) -> (Context -> Context)
val colAutoNlnSkip0: f': (Context -> Context) -> c: 'a seq -> f: ('a -> Context -> Context) -> (Context -> Context)
val sepSpaceBeforeClassConstructor: ctx: Context -> Context
val sepColon: ctx: Context -> Context
val sepColonFixed: (Context -> Context)
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Core/Queue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Fantomas.Core

/// append only collection optimized for quick append of block of data and query operations
/// data - list of blocks in reverse order
type Queue<'T>(data: list<'T array>, length: int) =
type Queue<'T>(data: 'T array list, length: int) =
let mutable hashCode = None

override x.GetHashCode() =
Expand Down Expand Up @@ -118,12 +118,12 @@ module Queue =
let ofList xs =
Queue<'T>([ List.toArray xs ], List.length xs)

let ofSeq (xs: seq<_>) =
let ofSeq (xs: _ seq) =
Queue<'T>([ Seq.toArray xs ], Seq.length xs)

let inline rev (q: Queue<'T>) = q.Rev()

let inline toSeq (q: Queue<'T>) = q :> seq<'T>
let inline toSeq (q: Queue<'T>) = q :> 'T seq

let inline append (q: Queue<'T>) xs = q.Append xs

Expand Down
78 changes: 39 additions & 39 deletions src/Fantomas.Core/Selection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -392,43 +392,43 @@ let formatSelection
|> Option.bind (findNode selection)
|> Option.map mkTreeWithSingleNode

if treeWithSelection.IsNone then
raise (FormatException("No suitable AST node was found for the given selection."))

let tree = treeWithSelection.Value
let maxLineLength = config.MaxLineLength - selection.StartColumn

let selectionConfig =
{ config with
InsertFinalNewline = false
MaxLineLength = maxLineLength }

let formattedSelection =
let context = Context.Context.Create selectionConfig

match tree with
| TreeForSelection.Unsupported ->
raise (FormatException("The current selection is not supported right now."))
| TreeForSelection.Standalone tree ->
let enrichedTree = Trivia.enrichTree selectionConfig sourceText baseUntypedTree tree

CodePrinter.genFile enrichedTree context
|> Context.dump true
|> fun result -> result.Code
| TreeForSelection.RequiresExtraction(tree, t) ->
let enrichedTree = Trivia.enrichTree selectionConfig sourceText baseUntypedTree tree

let { Code = formattedCode } =
CodePrinter.genFile enrichedTree context |> Context.dump true

let source = SourceText.ofString formattedCode
let formattedAST, _ = Fantomas.FCS.Parse.parseFile isSignature source []
let formattedTree = ASTTransformer.mkOak (Some source) formattedAST
let rangeOfSelection = findRangeOf t formattedTree

match rangeOfSelection with
| None -> raise (FormatException("No suitable AST node could be extracted from formatted selection."))
| Some m -> source.GetContentAt m

return formattedSelection.TrimEnd([| '\r'; '\n' |]), selection
match treeWithSelection with
| None -> return raise (FormatException("No suitable AST node was found for the given selection."))
| Some tree ->
let maxLineLength = config.MaxLineLength - selection.StartColumn

let selectionConfig =
{ config with
InsertFinalNewline = false
MaxLineLength = maxLineLength }

let formattedSelection =
let context = Context.Context.Create selectionConfig

match tree with
| TreeForSelection.Unsupported ->
raise (FormatException("The current selection is not supported right now."))
| TreeForSelection.Standalone tree ->
let enrichedTree = Trivia.enrichTree selectionConfig sourceText baseUntypedTree tree

CodePrinter.genFile enrichedTree context
|> Context.dump true
|> fun result -> result.Code
| TreeForSelection.RequiresExtraction(tree, t) ->
let enrichedTree = Trivia.enrichTree selectionConfig sourceText baseUntypedTree tree

let { Code = formattedCode } =
CodePrinter.genFile enrichedTree context |> Context.dump true

let source = SourceText.ofString formattedCode
let formattedAST, _ = Fantomas.FCS.Parse.parseFile isSignature source []
let formattedTree = ASTTransformer.mkOak (Some source) formattedAST
let rangeOfSelection = findRangeOf t formattedTree

match rangeOfSelection with
| None ->
raise (FormatException("No suitable AST node could be extracted from formatted selection."))
| Some m -> source.GetContentAt m

return formattedSelection.TrimEnd([| '\r'; '\n' |]), selection
}
2 changes: 1 addition & 1 deletion src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let noa<'n when 'n :> Node> (n: 'n option) =
| None -> Array.empty
| Some n -> [| n :> Node |]

let nodes<'n when 'n :> Node> (ns: seq<'n>) = Seq.cast<Node> ns
let nodes<'n when 'n :> Node> (ns: 'n seq) = Seq.cast<Node> ns

let nodeRange (n: Node) = n.Range

Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.FCS/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
},
"G-Research.FSharp.Analyzers": {
"type": "Direct",
"requested": "[0.3.1, )",
"resolved": "0.3.1",
"contentHash": "XDA1uHaPBVM65YASFSnrX/cfgMLfDm6rXZotv4TAIDh52vKt9lPIwxQxbX9JlsmIZ1LfVvq0/+4J+EKo2vl0Ig=="
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "+eZ7Xmq6W9X31X/vYfMi93Zxg6t8oFnZhrsVOWOS6NfQsFYyk3kF+YEq8JqO5DEFPwf9YlvJpjcf+3hOx99yKw=="
},
"Ionide.Analyzers": {
"type": "Direct",
"requested": "[0.4.0, )",
"resolved": "0.4.0",
"contentHash": "8ZwHwSRU7wkYFDCeFJ7Lp54bp0eccjcvmsS3jS/HKJc9kw5qMvZh+5XvfIC9IynHGSIhV6wv5R0R+9a51mjt3g=="
"requested": "[0.5.0, )",
"resolved": "0.5.0",
"contentHash": "dAjYoWOMhAYM10Q4bfSLbrDokuMtH0XjLFgKTp7N9qEy7goZIx/LPe2Wo9Qrpnulj50JgYtbO5V4KEUw8C/T1A=="
},
"Ionide.KeepAChangelog.Tasks": {
"type": "Direct",
Expand Down
Loading

0 comments on commit 7e7a90a

Please sign in to comment.