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
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ let private getIdentifiers (args: AstNodeRuleParams) =
| AstNode.TypeDefinition(SynTypeDefn(componentInfo, _typeDef, _, _, _)) ->
let checkTypes types =
seq {
for SynTyparDecl(_attr, synTypeDecl) in types do
match synTypeDecl with
| SynTypar(id, _, _) when not (isPascalCase id.idText) ->
yield (id, id.idText, None)
| _ -> ()
for SynTyparDecl(_attr, SynTypar(id, _, _)) in types do
yield (id, id.idText, None)
}

match componentInfo with
| SynComponentInfo(_attrs, types, _, _identifier, _, _, _, _) ->
checkTypes types |> Array.ofSeq
| AstNode.Type(SynType.Var(SynTypar(id, _, _), _)) ->
(id, id.idText, None) |> Array.singleton
| _ -> Array.empty

let rule config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ type Foo<'T> = Option<'T>
type Foo<'a> = Option<'a>
"""
Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsAt(2, 9))
Assert.IsTrue(this.ErrorExistsOnLine 2)

[<Test>]
member this.``generic type names shouldn't be camelCase (2 generic types)``() =
this.Parse """
type Foo<'a, 'T> = Option<'a * 'T>
"""
Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsAt(2, 9))
Assert.IsTrue(this.ErrorExistsOnLine 2)

[<Test>]
member this.``generic type names shouldn't be camelCase (2 generic types with different order)``() =
this.Parse """
type Foo<'T, 'a> = Option<'T * 'a>
"""
Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsAt(2, 13))
Assert.IsTrue(this.ErrorExistsOnLine 2)

[<Test>]
member this.``generic type names are PascalCase``() =
Expand All @@ -57,3 +57,37 @@ type Foo<'K, 'V> = Option<'K * 'V>
type Foo<'T1, 'T2, 'T3, 'T4, 'T5, 'a, 'T6> = Option<'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'a * 'T6>
"""
Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsOnLine 2)

[<Test>]
member this.``generic type names shouldn't be camelCase even for types in methods``() =
this.Parse """
module PeerChannelEncryptorMonad =
type PeerChannelEncryptorComputation<'T> =
| PeerChannelEncryptorComputation of
(PeerChannelEncryptor -> Result<'T * PeerChannelEncryptor, PeerError>)

let runP pcec initialState =
let (PeerChannelEncryptorComputation innerFn) = pcec
innerFn initialState

let returnP x =
let innerFn state =
Ok(x, state)

PeerChannelEncryptorComputation innerFn

let bindP
(f: 'a -> PeerChannelEncryptorComputation<'b>)
(xT: PeerChannelEncryptorComputation<'a>)
: PeerChannelEncryptorComputation<'b> =
let innerFn state =
runP xT state
>>= fun (res, state2) ->
let h = runP (f res) state2
h

PeerChannelEncryptorComputation innerFn
"""
Assert.IsTrue(this.ErrorsExist)
Assert.IsTrue(this.ErrorExistsOnLine 18)