Skip to content

Commit

Permalink
Merge pull request #48 from dawedawe/empty_string_name_exn
Browse files Browse the repository at this point in the history
use TryGetFullName to get the full name of the type
  • Loading branch information
dawedawe committed Dec 6, 2023
2 parents 36457f0 + 3f2fbab commit 786a965
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixed
* Handle types without a FullName more gracefully in the EmptyStringAnalyzer. [#48](https://github.com/ionide/ionide-analyzers/pull/48)

## 0.5.0 - 2023-11-23

### Changed
Expand Down
11 changes: 5 additions & 6 deletions src/Ionide.Analyzers/Suggestion/EmptyStringAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ open FSharp.Compiler.Symbols
open FSharp.Compiler.Text

let (|EmptyStringConst|_|) (e: FSharpExpr) =
if e.Type.ErasedType.BasicQualifiedName = "System.String" then
match e with
| FSharpExprPatterns.Const(o, _type) when not (isNull o) && (string o).Length = 0 -> Some()
| _ -> None
else
None
let name = e.Type.ErasedType.TypeDefinition.TryGetFullName()

match name, e with
| Some("System.String"), FSharpExprPatterns.Const(o, _type) when not (isNull o) && (string o).Length = 0 -> Some()
| _ -> None

let invalidStringFunctionUseAnalyzer (typedTree: FSharpImplementationFileContents) =
let ranges = ResizeArray<range>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,21 @@ let x = s.Length = 0
let! msgs = emptyStringCliAnalyzer ctx
Assert.IsEmpty msgs
}

[<Test>]
let ``Handle types without a FullName gracefully`` () =
async {
let source =
"""
module M
let f () =
let mutable bom = Array.zeroCreate 3
let mutable bom2 = Array.zeroCreate 3
bom = bom2
"""

let ctx = getContext projectOptions source
let! msgs = emptyStringCliAnalyzer ctx
Assert.IsEmpty msgs
}

0 comments on commit 786a965

Please sign in to comment.