Skip to content

Commit 01a2f12

Browse files
webwarrior-wsknocte
authored andcommitted
IndexerAccesorStyleConsistency: fix false negative
1 parent 06ca9c2 commit 01a2f12

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,14 @@ let runner (config: Config) (args: AstNodeRuleParams) =
3030
match config.Style with
3131
| IndexerAccessorStyle.OCaml ->
3232
match args.AstNode with
33-
| AstNode.Binding binding ->
34-
match binding with
35-
| SynBinding (_, _, _, _, _, _, _, SynPat.Named _, _,
36-
SynExpr.App (ExprAtomicFlag.Atomic, _, SynExpr.Ident _, SynExpr.ArrayOrListComputed (_, expr, range), _),
37-
_, _, _)
38-
->
39-
generateOutput range IndexerAccessorStyle.OCaml
40-
| _ ->
41-
Array.empty
33+
| AstNode.Expression (SynExpr.App (ExprAtomicFlag.Atomic, _, SynExpr.Ident _, SynExpr.ArrayOrListComputed (_, _expr, range), _)) ->
34+
generateOutput range IndexerAccessorStyle.OCaml
4235
| _ ->
4336
Array.empty
4437
| IndexerAccessorStyle.CSharp ->
4538
match args.AstNode with
46-
| AstNode.Binding binding ->
47-
match binding with
48-
| SynBinding (_, _, _, _, _, _, _, SynPat.Named _, _
49-
, SynExpr.DotIndexedGet (_, _, _, range), _, _, _) ->
50-
generateOutput range IndexerAccessorStyle.CSharp
51-
| _ ->
52-
Array.empty
39+
| AstNode.Expression (SynExpr.DotIndexedGet (_, _, _, range)) ->
40+
generateOutput range IndexerAccessorStyle.CSharp
5341
| _ ->
5442
Array.empty
5543

tests/FSharpLint.Core.Tests/Rules/Conventions/IndexerAccessorStyleConsistency.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ System.Console.WriteLine bar"""
4646

4747
Assert.IsTrue this.ErrorsExist
4848

49+
[<Test>]
50+
member this.IndexerAccessorStyleConsistencyCSharpStyleWhenUsingOCaml2() =
51+
this.Parse """
52+
module Program
53+
54+
let withoutPrefix = [ "foo" ]
55+
let firstChar = withoutPrefix[0] |> string
56+
let rest = withoutPrefix.Substring 1
57+
prefix + firstChar + rest"""
58+
59+
Assert.IsTrue this.ErrorsExist
60+
4961
[<Test>]
5062
member this.IndexerAccessorStyleConsistencyOCamlStyleWhenUsingOCaml() =
5163
this.Parse """

0 commit comments

Comments
 (0)