Skip to content

Commit 53574ca

Browse files
knoctewebwarrior-ws
authored andcommitted
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 35a59bf commit 53574ca

File tree

83 files changed

+258
-319
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

+258
-319
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
@@ -50,7 +50,7 @@ let rec checkExpression (expression: SynExpr) (range: range) (continuation: unit
5050
{
5151
Range = range
5252
Message = Resources.GetString "RulesAsyncExceptionWithoutReturn"
53-
SuggestedFix = None
53+
Fix = None
5454
TypeChecks = List.Empty
5555
}
5656
| 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,12 +9,12 @@ 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
Array.singleton
1414
{
1515
Range = range
1616
Message = String.Format(Resources.GetString ("RulesAvoidSinglePipeOperator"))
17-
SuggestedFix = suggestedFix
17+
Fix = fix
1818
TypeChecks = List.Empty
1919
}
2020

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

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: 3 additions & 3 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 String.Empty range.Start constRange.End
2525

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

@@ -36,8 +36,8 @@ let private checkForNamedPatternEqualsConstant (args:AstNodeRuleParams) pattern
3636
Array.singleton
3737
{ Range = fromRange
3838
Message = Resources.GetString("RulesFavourAsKeyword")
39-
SuggestedFix = suggestedFix
40-
TypeChecks = List.Empty }
39+
Fix = fix
40+
TypeChecks = [] }
4141

4242
| _ -> Array.empty
4343
| _ -> Array.empty

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

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

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ 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
1717
(fun fromText ->
1818
{ FromRange = range
1919
ToText = identifier }))
2020

21-
{
22-
Range = range
23-
Message = String.Format(Resources.GetString "RulesFavourTypedIgnore", identifier)
24-
SuggestedFix = Some suggestedFix
25-
TypeChecks = List.Empty
26-
}
21+
{ Range = range
22+
Message = String.Format(Resources.GetString "RulesFavourTypedIgnore", identifier)
23+
Fix = Some fix
24+
TypeChecks = List.Empty }
2725

2826
let isTyped expression identifier range text =
2927
match expression with

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ 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 })
30+
let fix = lazy(
31+
Some { Fix.FromRange = identifierRange; ToText = refactorTo })
3232
Array.singleton
33-
{
34-
Range = range
35-
Message = error
36-
SuggestedFix = Some suggestedFix
37-
TypeChecks = List.Empty
38-
}
33+
{ Range = range; Message = error; Fix = Some fix; TypeChecks = List.Empty }
3934
| _ -> Array.empty
4035

4136
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 = String.Empty })
@@ -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)