Skip to content

Commit 9dbef3c

Browse files
authored
Merge pull request #552 from janus/UpdateGenericTypeNames-squashed
GenericTypesNames: fix some false negative and add unit test
2 parents 41787e7 + 4580673 commit 9dbef3c

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/FSharpLint.Core/Rules/Conventions/Naming/GenericTypesNames.fs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ let private getIdentifiers (args: AstNodeRuleParams) =
1010
| AstNode.TypeDefinition(SynTypeDefn(componentInfo, _typeDef, _, _, _)) ->
1111
let checkTypes types =
1212
seq {
13-
for SynTyparDecl(_attr, synTypeDecl) in types do
14-
match synTypeDecl with
15-
| SynTypar(id, _, _) when not (isPascalCase id.idText) ->
16-
yield (id, id.idText, None)
17-
| _ -> ()
13+
for SynTyparDecl(_attr, SynTypar(id, _, _)) in types do
14+
yield (id, id.idText, None)
1815
}
1916

2017
match componentInfo with
2118
| SynComponentInfo(_attrs, types, _, _identifier, _, _, _, _) ->
2219
checkTypes types |> Array.ofSeq
20+
| AstNode.Type(SynType.Var(SynTypar(id, _, _), _)) ->
21+
(id, id.idText, None) |> Array.singleton
2322
| _ -> Array.empty
2423

2524
let rule config =

tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/GenericTypesNames.fs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ type Foo<'T> = Option<'T>
2626
type Foo<'a> = Option<'a>
2727
"""
2828
Assert.IsTrue(this.ErrorsExist)
29-
Assert.IsTrue(this.ErrorExistsAt(2, 9))
29+
Assert.IsTrue(this.ErrorExistsOnLine 2)
3030

3131
[<Test>]
3232
member this.``generic type names shouldn't be camelCase (2 generic types)``() =
3333
this.Parse """
3434
type Foo<'a, 'T> = Option<'a * 'T>
3535
"""
3636
Assert.IsTrue(this.ErrorsExist)
37-
Assert.IsTrue(this.ErrorExistsAt(2, 9))
37+
Assert.IsTrue(this.ErrorExistsOnLine 2)
3838

3939
[<Test>]
4040
member this.``generic type names shouldn't be camelCase (2 generic types with different order)``() =
4141
this.Parse """
4242
type Foo<'T, 'a> = Option<'T * 'a>
4343
"""
4444
Assert.IsTrue(this.ErrorsExist)
45-
Assert.IsTrue(this.ErrorExistsAt(2, 13))
45+
Assert.IsTrue(this.ErrorExistsOnLine 2)
4646

4747
[<Test>]
4848
member this.``generic type names are PascalCase``() =
@@ -57,3 +57,37 @@ type Foo<'K, 'V> = Option<'K * 'V>
5757
type Foo<'T1, 'T2, 'T3, 'T4, 'T5, 'a, 'T6> = Option<'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'a * 'T6>
5858
"""
5959
Assert.IsTrue(this.ErrorsExist)
60+
Assert.IsTrue(this.ErrorExistsOnLine 2)
61+
62+
[<Test>]
63+
member this.``generic type names shouldn't be camelCase even for types in methods``() =
64+
this.Parse """
65+
module PeerChannelEncryptorMonad =
66+
type PeerChannelEncryptorComputation<'T> =
67+
| PeerChannelEncryptorComputation of
68+
(PeerChannelEncryptor -> Result<'T * PeerChannelEncryptor, PeerError>)
69+
70+
let runP pcec initialState =
71+
let (PeerChannelEncryptorComputation innerFn) = pcec
72+
innerFn initialState
73+
74+
let returnP x =
75+
let innerFn state =
76+
Ok(x, state)
77+
78+
PeerChannelEncryptorComputation innerFn
79+
80+
let bindP
81+
(f: 'a -> PeerChannelEncryptorComputation<'b>)
82+
(xT: PeerChannelEncryptorComputation<'a>)
83+
: PeerChannelEncryptorComputation<'b> =
84+
let innerFn state =
85+
runP xT state
86+
>>= fun (res, state2) ->
87+
let h = runP (f res) state2
88+
h
89+
90+
PeerChannelEncryptorComputation innerFn
91+
"""
92+
Assert.IsTrue(this.ErrorsExist)
93+
Assert.IsTrue(this.ErrorExistsOnLine 18)

0 commit comments

Comments
 (0)