Skip to content

Commit 6efbad1

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 7a893d9 commit 6efbad1

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

@@ -141,30 +141,30 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
141141

142142
let handleFixResult (target: string) (ruleName: string) = function
143143
| LintResult.Success warnings ->
144-
String.Format(Resources.GetString "ConsoleApplyingSuggestedFixFile", target) |> output.WriteInfo
144+
String.Format(Resources.GetString "ConsoleApplyingFixFile", target) |> output.WriteInfo
145145
let increment = 1
146146
let noFixIncrement = 0
147147

148148
let countFixes (element: Suggestion.LintWarning) =
149149
let sourceCode = File.ReadAllText element.FilePath
150150
if String.Equals(ruleName, element.RuleName, StringComparison.InvariantCultureIgnoreCase) then
151-
match element.Details.SuggestedFix with
152-
| Some lazySuggestedFix ->
153-
match lazySuggestedFix.Force() with
154-
| Some suggestedFix ->
151+
match element.Details.Fix with
152+
| Some lazyFix ->
153+
match lazyFix.Force() with
154+
| Some fix ->
155155
let updatedSourceCode =
156-
let builder = StringBuilder(sourceCode.Length + suggestedFix.ToText.Length)
156+
let builder = StringBuilder(sourceCode.Length + fix.ToText.Length)
157157
let firstPart =
158158
sourceCode.AsSpan(
159159
0,
160-
(ExpressionUtilities.findPos suggestedFix.FromRange.Start sourceCode).Value
160+
(ExpressionUtilities.findPos fix.FromRange.Start sourceCode).Value
161161
)
162162
let secondPart =
163163
sourceCode.AsSpan
164-
(ExpressionUtilities.findPos suggestedFix.FromRange.End sourceCode).Value
164+
(ExpressionUtilities.findPos fix.FromRange.End sourceCode).Value
165165
builder
166166
.Append(firstPart)
167-
.Append(suggestedFix.ToText)
167+
.Append(fix.ToText)
168168
.Append(secondPart)
169169
.ToString()
170170
File.WriteAllText(
@@ -177,14 +177,14 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
177177
else
178178
noFixIncrement
179179

180-
let countSuggestedFix =
180+
let countFix =
181181
warnings |> List.sumBy countFixes
182182
outputWarnings warnings
183183

184-
if countSuggestedFix > 0 then
184+
if countFix > 0 then
185185
exitCode <- ExitCode.Success
186186
else
187-
exitCode <- ExitCode.NoSuggestedFix
187+
exitCode <- ExitCode.NoFix
188188

189189
| LintResult.Failure failure -> handleError ExitCode.Error failure.Description
190190

@@ -235,7 +235,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
235235
ShouldFix = false
236236
MaybeRuleName = None }
237237

238-
let applySuggestedFix (fixArgs: ParseResults<FixArgs>) =
238+
let applyFix (fixArgs: ParseResults<FixArgs>) =
239239
let fixParams = getParams None
240240
let ruleName, target = fixArgs.GetResult Fix_Target
241241
let fileType = fixArgs.TryGetResult Fix_File_Type |> Option.defaultValue (inferFileType target)
@@ -268,7 +268,7 @@ let private start (arguments:ParseResults<ToolArgs>) (toolsPath:Ionide.ProjInfo.
268268

269269
match arguments.GetSubCommand() with
270270
| Lint lintArgs -> applyLint lintArgs
271-
| Fix fixArgs -> applySuggestedFix fixArgs
271+
| Fix fixArgs -> applyFix fixArgs
272272
| _ -> ()
273273

274274
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)