Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [0.1.3] - 2023-10-11
* Fix StringAnalyzers for netstandard projects

## [0.1.2] - 2023-10-10
* Update FSharp.Analyzers.SDK to `0.15.0`

Expand Down
3 changes: 2 additions & 1 deletion src/FSharp.Analyzers/StringAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ let invalidStringFunctionUseAnalyzer
let handler : Handler =
Handler.CallHandler (fun (m : range) (mfv : FSharpMemberOrFunctionOrValue) (args : FSharpExpr list) ->
if
mfv.Assembly.SimpleName = "System.Runtime"
(mfv.Assembly.SimpleName = "System.Runtime"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, why of course not.
Could we cover this with a unit test somehow?
Do the matrix thing where we run them for both net7.0 and netstandard2.0?

|| mfv.Assembly.SimpleName = "netstandard")
&& mfv.FullName = $"System.String.{functionName}"
&& typedArgumentPredicate args
then
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"foo".EndsWith("p")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-001 | Warning | (1,0 - 1,19) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-001 | Warning | (3,0 - 3,19) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/endswith/Function call - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let f () = "f"
"g".EndsWith(f())
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-001 | Warning | (2,0 - 2,17) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-001 | Warning | (4,0 - 4,17) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module M

module A =
let b = "b"

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-001 | Warning | (4,0 - 4,17) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-001 | Warning | (6,0 - 6,17) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/endswith/Value - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let a = "a"
a.EndsWith("a")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-001 | Warning | (2,0 - 2,15) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-001 | Warning | (4,0 - 4,15) | The usage of String.EndsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/endswith/negative/Boolean CultureInfo.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module M

open System.Globalization

"a".EndsWith("b", false, CultureInfo.InvariantCulture)
2 changes: 2 additions & 0 deletions tests/data/string/endswith/negative/Char.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"a".EndsWith('b')
2 changes: 2 additions & 0 deletions tests/data/string/endswith/negative/StringComparison.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"a".EndsWith("b", System.StringComparison.InvariantCulture)
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"foo".IndexOf("p")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (1,0 - 1,18) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (3,0 - 3,18) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/Constant String - String Int Int.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"foo".IndexOf("p", 0 ,1)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (1,0 - 1,24) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (3,0 - 3,24) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/Constant String - String Int.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"foo".IndexOf("p", 0)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (1,0 - 1,21) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (3,0 - 3,21) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/Function call - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let f () = "f"
"g".IndexOf(f())
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (2,0 - 2,16) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (4,0 - 4,16) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/Prefixed Value - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module M

module A =
let b = "b"

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (4,0 - 4,16) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (6,0 - 6,16) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/Value - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let a = "a"
a.IndexOf("a")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-003 | Warning | (2,0 - 2,14) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-003 | Warning | (4,0 - 4,14) | The usage of String.IndexOf with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/indexof/negative/Char Int32 Int32.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf('f',0,1)
2 changes: 2 additions & 0 deletions tests/data/string/indexof/negative/Char Int32.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf('f',0)
2 changes: 2 additions & 0 deletions tests/data/string/indexof/negative/Char StringComparison.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf('f',StringComparison.InvariantCulture)
2 changes: 2 additions & 0 deletions tests/data/string/indexof/negative/Char.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf('f')
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf("f",0,1,StringComparison.InvariantCulture)
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf("f",0,StringComparison.InvariantCulture)
2 changes: 2 additions & 0 deletions tests/data/string/indexof/negative/String StringComparison.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

open System
"foo".IndexOf("f",StringComparison.InvariantCulture)
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"foo".StartsWith("p")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-002 | Warning | (1,0 - 1,21) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-002 | Warning | (3,0 - 3,21) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let f () = "f"
"g".StartsWith(f())
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-002 | Warning | (2,0 - 2,19) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-002 | Warning | (4,0 - 4,19) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module M

module A =
let b = "b"

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-002 | Warning | (4,0 - 4,19) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-002 | Warning | (6,0 - 6,19) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/startswith/Value - Single Argument.fs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
module M

let a = "a"
a.StartsWith("a")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRA-STRING-002 | Warning | (2,0 - 2,17) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
GRA-STRING-002 | Warning | (4,0 - 4,17) | The usage of String.StartsWith with a single string argument is discouraged. Signal your intention explicitly by calling an overload.
2 changes: 2 additions & 0 deletions tests/data/string/startswith/negative/Boolean CultureInfo.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module M

open System.Globalization

"a".StartsWith("b", false, CultureInfo.InvariantCulture)
2 changes: 2 additions & 0 deletions tests/data/string/startswith/negative/Char.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"a".StartsWith('b')
2 changes: 2 additions & 0 deletions tests/data/string/startswith/negative/StringComparison.fs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module M

"a".StartsWith("b", System.StringComparison.InvariantCulture)