@@ -8,48 +8,50 @@ open FSharpLint.Framework.Suggestion
88open FSharpLint.Framework
99open System
1010
11+ type IndexerAccessorStyle =
12+ | OCaml
13+ | CSharp
14+
1115[<RequireQualifiedAccess>]
1216type Config = {
13- Style: string
17+ Style: IndexerAccessorStyle
1418}
1519
16- let generateOutput ( range : FSharp.Compiler.Text.Range ) msg =
20+ let generateOutput ( range : FSharp.Compiler.Text.Range ) ( style : IndexerAccessorStyle ) =
1721 Array.singleton
1822 {
1923 Range = range
20- Message = Resources.GetString msg
24+ Message = String.Format ( Resources.GetString " RulesIndexerAccessorStyleConsistency " , style.ToString ())
2125 SuggestedFix = None
2226 TypeChecks = List.Empty
2327 }
2428
2529let runner ( config : Config ) ( args : AstNodeRuleParams ) =
26- let styleType = config.Style
27- if String.Equals ( styleType , " ocaml " , StringComparison.InvariantCultureIgnoreCase ) then
30+ match config.Style with
31+ | IndexerAccessorStyle.OCaml ->
2832 match args.AstNode with
2933 | AstNode.Binding binding ->
3034 match binding with
3135 | SynBinding (_, _, _, _, _, _, _, SynPat.Named _, _,
3236 SynExpr.App ( ExprAtomicFlag.Atomic, _, SynExpr.Ident _, SynExpr.ArrayOrListComputed (_, expr, range), _),
3337 _, _, _)
3438 ->
35- generateOutput range " RulesIndexerAccessorStyleConsistencyToOCaml "
39+ generateOutput range IndexerAccessorStyle.OCaml
3640 | _ ->
3741 Array.empty
3842 | _ ->
3943 Array.empty
40- elif String.Equals ( styleType , " csharp " , StringComparison.InvariantCultureIgnoreCase ) then
44+ | IndexerAccessorStyle.CSharp ->
4145 match args.AstNode with
4246 | AstNode.Binding binding ->
4347 match binding with
4448 | SynBinding (_, _, _, _, _, _, _, SynPat.Named _, _
4549 , SynExpr.DotIndexedGet (_, _, _, range), _, _, _) ->
46- generateOutput range " RulesIndexerAccessorStyleConsistencyToCSharp "
50+ generateOutput range IndexerAccessorStyle.CSharp
4751 | _ ->
4852 Array.empty
4953 | _ ->
5054 Array.empty
51- else
52- failwithf " Unknown style type %s " styleType
5355
5456let rule config =
5557 AstNodeRule
0 commit comments