Skip to content

Commit 2e3a715

Browse files
committed
Converge QuickFix & SuggestedFix terminology into one
It was a bit confusing that in some parts of the codebase, the rule's fixes were called "QuickFix" sometimes (more like towards the user) and "SuggestedFix" in others (more API-wise). With this commit we just converge both ways into one, and a much simpler one: fix.
1 parent 8beb004 commit 2e3a715

File tree

83 files changed

+224
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+224
-225
lines changed

src/FSharpLint.Console/Program.fs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ExitCode =
2525
| Error = -1
2626
| Success = 0
2727
| NoSuchRuleName = 1
28-
| NoSuggestedFix = 2
28+
| NoFix = 2
2929

3030
let fileTypeHelp = "Input type the linter will run against. If this is not set, the file type will be inferred from the file extension."
3131

@@ -42,7 +42,7 @@ with
4242
match this with
4343
| Format _ -> "Output format of the linter."
4444
| Lint _ -> "Runs FSharpLint against a file or a collection of files."
45-
| Fix _ -> "Apply quickfixes for specified rule name or names (comma separated)."
45+
| Fix _ -> "Apply fixes for specified rule name or names (comma separated)."
4646
| Version -> "Prints current version."
4747

4848
// TODO: investigate erroneous warning on this type definition
@@ -70,7 +70,7 @@ with
7070
interface IArgParserTemplate with
7171
member this.Usage =
7272
match this with
73-
| Fix_Target _ -> "Rule name to be applied with suggestedFix and input to lint."
73+
| Fix_Target _ -> "Rule name to be applied with fix and input to lint."
7474
| Fix_File_Type _ -> fileTypeHelp
7575
// fsharplint:enable UnionCasesNames
7676

@@ -129,31 +129,31 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
129129

130130
let handleFixResult (target: string) (ruleName: string) = function
131131
| LintResult.Success warnings ->
132-
String.Format(Resources.GetString "ConsoleApplyingSuggestedFixFile", target) |> output.WriteInfo
132+
String.Format(Resources.GetString "ConsoleApplyingFixFile", target) |> output.WriteInfo
133133
let increment = 1
134134
let noFixIncrement = 0
135-
let countSuggestedFix =
135+
let countFix =
136136
warnings
137137
|> List.sumBy (fun (element: Suggestion.LintWarning) ->
138138
let sourceCode = File.ReadAllText element.FilePath
139139
if String.Equals(ruleName, element.RuleName, StringComparison.InvariantCultureIgnoreCase) then
140-
match element.Details.SuggestedFix with
141-
| Some lazySuggestedFix ->
142-
lazySuggestedFix.Force()
143-
|> Option.iter (fun suggestedFix ->
140+
match element.Details.Fix with
141+
| Some lazyFix ->
142+
lazyFix.Force()
143+
|> Option.iter (fun fix ->
144144
let updatedSourceCode =
145-
let builder = StringBuilder(sourceCode.Length + suggestedFix.ToText.Length)
145+
let builder = StringBuilder(sourceCode.Length + fix.ToText.Length)
146146
let firstPart =
147147
sourceCode.AsSpan(
148148
0,
149-
(ExpressionUtilities.findPos suggestedFix.FromRange.Start sourceCode).Value
149+
(ExpressionUtilities.findPos fix.FromRange.Start sourceCode).Value
150150
)
151151
let secondPart =
152152
sourceCode.AsSpan
153-
(ExpressionUtilities.findPos suggestedFix.FromRange.End sourceCode).Value
153+
(ExpressionUtilities.findPos fix.FromRange.End sourceCode).Value
154154
builder
155155
.Append(firstPart)
156-
.Append(suggestedFix.ToText)
156+
.Append(fix.ToText)
157157
.Append(secondPart)
158158
.ToString()
159159
File.WriteAllText(
@@ -167,10 +167,10 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
167167
noFixIncrement)
168168
outputWarnings warnings
169169

170-
if countSuggestedFix > 0 then
170+
if countFix > 0 then
171171
exitCode <- ExitCode.Success
172172
else
173-
exitCode <- ExitCode.NoSuggestedFix
173+
exitCode <- ExitCode.NoFix
174174

175175
| LintResult.Failure failure -> handleError ExitCode.Error failure.Description
176176

@@ -215,7 +215,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
215215

216216
linting fileType lintParams target toolsPath false None
217217

218-
let applySuggestedFix (fixArgs: ParseResults<FixArgs>) =
218+
let applyFix (fixArgs: ParseResults<FixArgs>) =
219219
let fixParams = getParams None
220220
let ruleName, target = fixArgs.GetResult Fix_Target
221221
let fileType = fixArgs.TryGetResult Fix_File_Type |> Option.defaultValue (inferFileType target)
@@ -242,7 +242,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
242242

243243
match arguments.GetSubCommand() with
244244
| Lint lintArgs -> applyLint lintArgs
245-
| Fix fixArgs -> applySuggestedFix fixArgs
245+
| Fix fixArgs -> applyFix fixArgs
246246
| _ -> ()
247247

248248
int exitCode

src/FSharpLint.Core/Framework/Suggestion.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open FSharp.Compiler.Text
55

66
/// Information for consuming applications to provide an automated fix for a lint suggestion.
77
[<NoEquality; NoComparison>]
8-
type SuggestedFix = {
8+
type Fix = {
99
/// Location of the text to be replaced.
1010
FromRange:Range
1111

@@ -22,7 +22,7 @@ type WarningDetails = {
2222
Message:string
2323

2424
/// Information to provide an automated fix.
25-
SuggestedFix:Lazy<SuggestedFix option> option
25+
Fix:Lazy<Fix option> option
2626

2727
/// Type checks to be performed to confirm this suggestion is valid.
2828
/// Suggestion is only considered valid when all type checks resolve to true.

src/FSharpLint.Core/Rules/Conventions/AsyncExceptionWithoutReturn.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let rec checkExpression (expression: SynExpr) (range: range) =
4646
->
4747
{ Range = range
4848
Message = Resources.GetString "RulesAsyncExceptionWithoutReturn"
49-
SuggestedFix = None
49+
Fix = None
5050
TypeChecks = List.Empty }
5151
|> Array.singleton
5252
| SynExpr.App (_, _, funcExpr, _, range) ->

src/FSharpLint.Core/Rules/Conventions/AvoidSinglePipeOperator.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ open FSharpLint.Framework.Ast
99
open FSharpLint.Framework.Rules
1010

1111
let runner (args: AstNodeRuleParams) =
12-
let errors range suggestedFix =
12+
let errors range fix =
1313
{
1414
Range = range
1515
Message = String.Format(Resources.GetString ("RulesAvoidSinglePipeOperator"))
16-
SuggestedFix = suggestedFix
16+
Fix = fix
1717
TypeChecks = List.Empty
1818
} |> Array.singleton
1919

@@ -42,15 +42,15 @@ let runner (args: AstNodeRuleParams) =
4242
if isParentPiped then
4343
Array.empty
4444
else
45-
let suggestedFix = lazy(
45+
let fix = lazy(
4646
let maybeFuncText = ExpressionUtilities.tryFindTextOfRange outerArgExpr.Range args.FileContent
4747
let maybeArgText = ExpressionUtilities.tryFindTextOfRange argExpr.Range args.FileContent
4848
match maybeFuncText, maybeArgText with
4949
| Some(funcText), Some(argText) ->
5050
let replacementText = sprintf "%s %s" funcText argText
5151
Some { FromRange=range; ToText=replacementText }
5252
| _ -> None)
53-
errors ident.idRange (Some suggestedFix)
53+
errors ident.idRange (Some fix)
5454
else
5555
Array.empty
5656
| _ ->

src/FSharpLint.Core/Rules/Conventions/AvoidTooShortNames.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let private checkIdentifier (identifier:Ident) (idText:string) =
2323
|> Array.map (fun message ->
2424
{ Range = identifier.idRange
2525
Message = message
26-
SuggestedFix = None
26+
Fix = None
2727
TypeChecks = List.Empty })
2828
else
2929
Array.empty

src/FSharpLint.Core/Rules/Conventions/Binding/FavourAsKeyword.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let private checkForNamedPatternEqualsConstant (args:AstNodeRuleParams) pattern
2323

2424
let fromRange = Range.mkRange "" range.Start constRange.End
2525

26-
let suggestedFix =
26+
let fix =
2727
ExpressionUtilities.tryFindTextOfRange fromRange args.FileContent
2828
|> Option.bind (fun text ->
2929

@@ -38,7 +38,7 @@ let private checkForNamedPatternEqualsConstant (args:AstNodeRuleParams) pattern
3838

3939
{ Range = fromRange
4040
Message = Resources.GetString("RulesFavourAsKeyword")
41-
SuggestedFix = suggestedFix
41+
Fix = fix
4242
TypeChecks = [] } |> Array.singleton
4343

4444
| _ -> Array.empty

src/FSharpLint.Core/Rules/Conventions/Binding/FavourIgnoreOverLetWild.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let private checkForBindingToAWildcard pattern range fileContent (expr: SynExpr)
1818
if findWildAndIgnoreParens pattern then
1919
{ Range = range
2020
Message = Resources.GetString("RulesFavourIgnoreOverLetWildError")
21-
SuggestedFix = Some (lazy (Some({ FromRange = letBindingRange
22-
ToText = sprintf "(%s) |> ignore" exprText })))
21+
Fix = Some (lazy (Some({ FromRange = letBindingRange
22+
ToText = sprintf "(%s) |> ignore" exprText })))
2323
TypeChecks = [] } |> Array.singleton
2424
else
2525
Array.empty

src/FSharpLint.Core/Rules/Conventions/Binding/FavourTypedIgnore.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open FSharpLint.Framework.Rules
1010
let private runner (args: AstNodeRuleParams) =
1111
let generateError identifier range text =
1212

13-
let suggestedFix =
13+
let fix =
1414
lazy
1515
(ExpressionUtilities.tryFindTextOfRange range text
1616
|> Option.map
@@ -20,7 +20,7 @@ let private runner (args: AstNodeRuleParams) =
2020

2121
{ Range = range
2222
Message = String.Format(Resources.GetString "RulesFavourTypedIgnore", identifier)
23-
SuggestedFix = Some suggestedFix
23+
Fix = Some fix
2424
TypeChecks = [] }
2525

2626
let isTyped expression identifier range text =

src/FSharpLint.Core/Rules/Conventions/Binding/TupleOfWildcards.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ let private checkTupleOfWildcards fileContents pattern identifier identifierRang
2727
let refactorFrom = constructorString (List.length patterns)
2828
let refactorTo = constructorString 1
2929
let error = String.Format(errorFormat, refactorFrom, refactorTo)
30-
let suggestedFix = lazy(
31-
Some { SuggestedFix.FromRange = identifierRange; ToText = refactorTo })
32-
{ Range = range; Message = error; SuggestedFix = Some suggestedFix; TypeChecks = [] } |> Array.singleton
30+
let fix = lazy(
31+
Some { Fix.FromRange = identifierRange; ToText = refactorTo })
32+
{ Range = range; Message = error; Fix = Some fix; TypeChecks = [] } |> Array.singleton
3333
| _ -> Array.empty
3434

3535
let private isTupleMemberArgs breadcrumbs tupleRange =

src/FSharpLint.Core/Rules/Conventions/Binding/UselessBinding.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open FSharp.Compiler.CodeAnalysis
99
open FSharpLint.Framework.Ast
1010
open FSharpLint.Framework.Rules
1111

12-
let private checkForUselessBinding (checkInfo:FSharpCheckFileResults option) pattern expr range maybeSuggestedFix =
12+
let private checkForUselessBinding (checkInfo:FSharpCheckFileResults option) pattern expr range maybeFix =
1313
match checkInfo with
1414
| Some checkInfo ->
1515
let rec findBindingIdentifier = function
@@ -42,13 +42,13 @@ let private checkForUselessBinding (checkInfo:FSharpCheckFileResults option) pat
4242
|> Option.map (fun ident ->
4343
{ Range = range
4444
Message = Resources.GetString("RulesUselessBindingError")
45-
SuggestedFix = Some (lazy(maybeSuggestedFix))
45+
Fix = Some (lazy(maybeFix))
4646
TypeChecks = [ checkNotMutable ident ] })
4747
|> Option.toArray
4848
| _ -> Array.empty
4949

5050
let private runner (args:AstNodeRuleParams) =
51-
let maybeSuggestedFix =
51+
let maybeFix =
5252
match args.GetParents(args.NodeIndex) with
5353
| AstNode.ModuleDeclaration(SynModuleDecl.Let(_, _, range)) :: _ ->
5454
Some({ FromRange = range; ToText = "" })
@@ -57,8 +57,8 @@ let private runner (args:AstNodeRuleParams) =
5757
| _ -> None
5858
match args.AstNode with
5959
| AstNode.Binding(SynBinding(_, _, _, isMutable, _, _, _, pattern, _, expr, range, _, _))
60-
when maybeSuggestedFix.IsSome && not isMutable ->
61-
checkForUselessBinding args.CheckInfo pattern expr range maybeSuggestedFix
60+
when maybeFix.IsSome && not isMutable ->
61+
checkForUselessBinding args.CheckInfo pattern expr range maybeFix
6262
| _ ->
6363
Array.empty
6464

0 commit comments

Comments
 (0)