Skip to content

Commit

Permalink
SuggestUseAutoProperty: implement fix suggestion
Browse files Browse the repository at this point in the history
Implement quick fix suggestion for the rule.
  • Loading branch information
webwarrior-ws committed Dec 6, 2023
1 parent 6e30839 commit a283f2b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/FSharpLint.Core/Rules/Conventions/SuggestUseAutoProperty.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ let private runner (args: AstNodeRuleParams) =
false,
_attributes,
_xmlDoc,
SynValData(Some(memberFlags), _, _),
SynPat.LongIdent (_, _, _, argPats, _, _),
SynValData (Some memberFlags, _, _),
SynPat.LongIdent (memberIdentifier, _, _, argPats, _, _),
_returnInfo,
expr,
_bindingRange,
Expand All @@ -72,9 +72,19 @@ let private runner (args: AstNodeRuleParams) =
| _, SynArgPats.Pats pats when pats.Length > 0 -> // non-property member
Array.empty
| expression, _ when isImmutableValueExpression args expression ->
let suggestedFix =
lazy
(match memberIdentifier.Lid with
| [ _; memberName ] ->
Some
{ FromText = args.FileContent
FromRange = memberIdentifier.Range
ToText = "val " + memberName.idText }
| _ -> None)

{ Range = memberRange
Message = Resources.GetString "RulesSuggestUseAutoProperty"
SuggestedFix = None
SuggestedFix = Some suggestedFix
TypeChecks = List.Empty }
|> Array.singleton
| _ -> Array.empty
Expand Down

0 comments on commit a283f2b

Please sign in to comment.