Skip to content

Commit

Permalink
TypePrefixing(Always): make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Dec 30, 2023
1 parent 1e474d3 commit 0264faf
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/FSharpLint.Core/Rules/Formatting/TypePrefixing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ type Config = { Mode: Mode }
let checkTypePrefixing (config:Config) (args:AstNodeRuleParams) range typeName typeArgs isPostfix =
match typeName with
| SynType.LongIdent lid ->
let prefixSuggestion typeName =
let suggestedFix = lazy(
(ExpressionUtilities.tryFindTextOfRange range args.FileContent, typeArgs)
||> Option.map2 (fun fromText typeArgs -> { FromText = fromText; FromRange = range; ToText = typeName + "<" + typeArgs + ">" }))
{ Range = range
Message = Resources.GetString("RulesFormattingGenericPrefixError")
SuggestedFix = Some suggestedFix
TypeChecks = [] } |> Some

match lid |> longIdentWithDotsToString with
| "list"
| "List"
| "option"
| "Option"
| "ref"
| "Ref" as typeName ->

// Prefer postfix.
if not isPostfix
if not isPostfix && config.Mode <> Mode.Always
then
let errorFormatString = Resources.GetString("RulesFormattingF#PostfixGenericError")
let suggestedFix = lazy(
Expand All @@ -38,7 +48,10 @@ let checkTypePrefixing (config:Config) (args:AstNodeRuleParams) range typeName t
SuggestedFix = Some suggestedFix
TypeChecks = [] } |> Some
else
None
if isPostfix && config.Mode = Mode.Always then
prefixSuggestion typeName
else
None
| "array" ->
// Prefer special postfix (e.g. int []).
let suggestedFix = lazy(
Expand All @@ -51,13 +64,7 @@ let checkTypePrefixing (config:Config) (args:AstNodeRuleParams) range typeName t
| typeName ->
// Prefer prefix.
if isPostfix then
let suggestedFix = lazy(
(ExpressionUtilities.tryFindTextOfRange range args.FileContent, typeArgs)
||> Option.map2 (fun fromText typeArgs -> { FromText = fromText; FromRange = range; ToText = typeName + "<" + typeArgs + ">" }))
{ Range = range
Message = Resources.GetString("RulesFormattingGenericPrefixError")
SuggestedFix = Some suggestedFix
TypeChecks = [] } |> Some
prefixSuggestion typeName
else
None
| _ ->
Expand Down

0 comments on commit 0264faf

Please sign in to comment.