Skip to content

Commit 26d5573

Browse files
knoctewebwarrior-ws
andcommitted
Core,Console,Tests: fix selfCheck
Co-authored-by: webwarrior-ws <reg@webwarrior.ws>
1 parent 03d1790 commit 26d5573

Some content is hidden

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

45 files changed

+265
-274
lines changed

src/FSharpLint.Console/Program.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,25 @@ let internal inferFileType (target:string) =
109109

110110
/// Must be called only once per process.
111111
/// We're calling it globally so we can call main multiple times from our tests.
112-
let toolsPath = Ionide.ProjInfo.Init.init (DirectoryInfo <| Directory.GetCurrentDirectory()) None
112+
let globalToolsPath = Ionide.ProjInfo.Init.init (DirectoryInfo <| Directory.GetCurrentDirectory()) None
113113

114114
[<EntryPoint>]
115115
let main argv =
116+
let parserProgress (output:Output.IOutput) = function
117+
| Starting file ->
118+
String.Format(Resources.GetString("ConsoleStartingFile"), file) |> output.WriteInfo
119+
| ReachedEnd (_, warnings) ->
120+
String.Format(Resources.GetString("ConsoleFinishedFile"), List.length warnings) |> output.WriteInfo
121+
| Failed (file, parseException) ->
122+
String.Format(Resources.GetString("ConsoleFailedToParseFile"), file) |> output.WriteError
123+
output.WriteError
124+
$"Exception Message:{Environment.NewLine}{parseException.Message}{Environment.NewLine}Exception Stack Trace:{Environment.NewLine}{parseException.StackTrace}{Environment.NewLine}"
125+
116126
let lint
117127
(lintArgs: ParseResults<LintArgs>)
118128
(output: Output.IOutput)
119129
(toolsPath:Ionide.ProjInfo.Types.ToolsPath)
120130
: ExitCode =
121-
let parserProgress (output:Output.IOutput) = function
122-
| Starting file ->
123-
String.Format(Resources.GetString("ConsoleStartingFile"), file) |> output.WriteInfo
124-
| ReachedEnd (_, warnings) ->
125-
String.Format(Resources.GetString("ConsoleFinishedFile"), List.length warnings) |> output.WriteInfo
126-
| Failed (file, parseException) ->
127-
String.Format(Resources.GetString("ConsoleFailedToParseFile"), file) |> output.WriteError
128-
output.WriteError
129-
$"Exception Message:{Environment.NewLine}{parseException.Message}{Environment.NewLine}Exception Stack Trace:{Environment.NewLine}{parseException.StackTrace}{Environment.NewLine}"
130-
131131
let mutable exitCode = ExitCode.Success
132132

133133
let handleError (str:string) =
@@ -181,9 +181,9 @@ let main argv =
181181
handleLintResult lintResult
182182
with
183183
| exn ->
184-
let target = if fileType = FileType.Source then "source" else target
184+
let targetStr = if fileType = FileType.Source then "source" else target
185185
handleError
186-
$"Lint failed while analysing %s{target}.{Environment.NewLine}Failed with: %s{exn.Message}{Environment.NewLine}Stack trace: {exn.StackTrace}"
186+
$"Lint failed while analysing %s{targetStr}.{Environment.NewLine}Failed with: %s{exn.Message}{Environment.NewLine}Stack trace: {exn.StackTrace}"
187187

188188
exitCode
189189

@@ -217,5 +217,5 @@ let main argv =
217217
| _ -> Some ConsoleColor.Red)
218218
let parser = ArgumentParser.Create<ToolArgs>(programName = "fsharplint", errorHandler = errorHandler)
219219
let parseResults = parser.ParseCommandLine argv
220-
start parseResults toolsPath
220+
start parseResults globalToolsPath
221221
|> int

src/FSharpLint.Core/Application/Configuration.fs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,14 @@ module IgnoreFiles =
107107
match remainingPath with
108108
| [_] when isDirectory -> false
109109
| currentSegment::remaining ->
110-
let currentlyMatchingGlobs = globs::currentlyMatchingGlobs
110+
let updatedCurrentlyMatchingGlobs = getRemainingGlobSeqForMatches currentSegment (globs::currentlyMatchingGlobs)
111111

112-
let currentlyMatchingGlobs = getRemainingGlobSeqForMatches currentSegment currentlyMatchingGlobs
113-
114-
let aGlobWasCompletelyMatched = List.exists List.isEmpty currentlyMatchingGlobs
112+
let aGlobWasCompletelyMatched = List.exists List.isEmpty updatedCurrentlyMatchingGlobs
115113

116114
let matched = aGlobWasCompletelyMatched && (isDirectory || (not isDirectory && List.isEmpty remaining))
117115

118116
if matched then true
119-
else doesGlobSeqMatchPathSeq globs isDirectory remaining currentlyMatchingGlobs
117+
else doesGlobSeqMatchPathSeq globs isDirectory remaining updatedCurrentlyMatchingGlobs
120118
| [] -> false
121119

122120
let private pathMatchesGlob (globs:Regex list) (path:string list) isDirectory =
@@ -692,7 +690,7 @@ let defaultConfiguration =
692690
use stream = assembly.GetManifestResourceStream(resourceName)
693691
match stream with
694692
| null -> failwithf "Resource '%s' not found in assembly '%s'" resourceName (assembly.FullName)
695-
| stream ->
693+
| _ ->
696694
use reader = new System.IO.StreamReader(stream)
697695

698696
reader.ReadToEnd()
@@ -709,8 +707,8 @@ type LoadedRules =
709707
LineRules:LineRules
710708
DeprecatedRules:Rule [] }
711709

712-
let getGlobalConfig (globalConfig:GlobalConfig option) =
713-
globalConfig
710+
let getGlobalConfig (maybeGlobalConfig: GlobalConfig option) =
711+
maybeGlobalConfig
714712
|> Option.map (fun globalConfig -> {
715713
Rules.GlobalRuleConfig.numIndentationSpaces = globalConfig.numIndentationSpaces |> Option.defaultValue Rules.GlobalRuleConfig.Default.numIndentationSpaces
716714
}) |> Option.defaultValue Rules.GlobalRuleConfig.Default
@@ -751,11 +749,11 @@ let findDeprecation config deprecatedAllRules allRules =
751749
// fsharplint:disable MaxLinesInFunction
752750
let flattenConfig (config:Configuration) =
753751
let parseHints (hints:string []) =
754-
let parseHint hint =
755-
match FParsec.CharParsers.run HintParser.phint hint with
752+
let parseHint hintString =
753+
match FParsec.CharParsers.run HintParser.phint hintString with
756754
| FParsec.CharParsers.Success(hint, _, _) -> hint
757755
| FParsec.CharParsers.Failure(error, _, _) ->
758-
raise <| ConfigurationException $"Failed to parse hint: {hint}{Environment.NewLine}{error}"
756+
raise <| ConfigurationException $"Failed to parse hint: {hintString}{Environment.NewLine}{error}"
759757

760758
hints
761759
|> Array.filter (System.String.IsNullOrWhiteSpace >> not)
@@ -769,12 +767,12 @@ let flattenConfig (config:Configuration) =
769767
Array.concat
770768
[|
771769
// Deprecated grouped configs. TODO: remove in next major release
772-
config.formatting |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
773-
config.conventions |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
774-
config.typography |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
770+
config.formatting |> Option.map (fun formattingConfig -> formattingConfig.Flatten()) |> Option.toArray |> Array.concat
771+
config.conventions |> Option.map (fun conventionsConfig -> conventionsConfig.Flatten()) |> Option.toArray |> Array.concat
772+
config.typography |> Option.map (fun typographyConfig -> typographyConfig.Flatten()) |> Option.toArray |> Array.concat
775773
// </Deprecated>
776774

777-
config.Hints |> Option.map (fun config -> HintMatcher.rule { HintMatcher.Config.HintTrie = parseHints (getOrEmptyList config.add) }) |> Option.toArray
775+
config.Hints |> Option.map (fun hintsConfig -> HintMatcher.rule { HintMatcher.Config.HintTrie = parseHints (getOrEmptyList hintsConfig.add) }) |> Option.toArray
778776
|]
779777

780778
let allRules =

src/FSharpLint.Core/Application/Lint.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,12 @@ module Lint =
523523

524524
let (successes, failures) =
525525
lintResults
526-
|> Array.fold (fun (successes, failures) result ->
526+
|> Array.fold (fun (successList, failureList) result ->
527527
match result with
528528
| LintResult.Success warnings ->
529-
(List.append warnings successes, failures)
529+
(List.append warnings successList, failureList)
530530
| LintResult.Failure err ->
531-
(successes, err :: failures)) (List.Empty, List.Empty)
531+
(successList, err :: failureList)) (List.Empty, List.Empty)
532532

533533
match failures with
534534
| [] ->

src/FSharpLint.Core/Framework/AbstractSyntaxArray.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ module AbstractSyntaxArray =
250250
tryAddPossibleSkips depth
251251

252252
// Strip out "extra info".
253-
let node =
253+
let strippedNode =
254254
let extractExtraInfo actual extraInfoNode =
255255
possibleSkips.Push (PossibleSkip(nodes.Count, depth))
256256
nodes.Add (TempNode(Utilities.hash2 extraInfoNode 0, actual))
@@ -262,13 +262,13 @@ module AbstractSyntaxArray =
262262
| Else(body) -> extractExtraInfo (Expression(body)) SyntaxNode.Else
263263
| _ -> node
264264

265-
traverseNode node (fun node -> left.Push (StackedNode(node, depth + 1)))
265+
traverseNode strippedNode (fun aNode -> left.Push (StackedNode(aNode, depth + 1)))
266266

267-
match astNodeToSyntaxNode node with
267+
match astNodeToSyntaxNode strippedNode with
268268
| SyntaxNode.Other -> ()
269269
| syntaxNode ->
270270
possibleSkips.Push (PossibleSkip(nodes.Count, depth))
271-
nodes.Add (TempNode(Utilities.hash2 syntaxNode (getHashCode node), node))
271+
nodes.Add (TempNode(Utilities.hash2 syntaxNode (getHashCode strippedNode), strippedNode))
272272

273273
tryAddPossibleSkips 0
274274

src/FSharpLint.Core/Framework/AstInfo.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ module AstInfo =
120120
if Seq.isEmpty str then
121121
true
122122
else
123-
let operator = List.tryFind (fun (op: string) -> str.StartsWith(op)) operators
123+
let maybeOperator = List.tryFind (fun (op: string) -> str.StartsWith(op)) operators
124124

125-
match operator with
125+
match maybeOperator with
126126
| Some(operator) -> str.Substring(operator.Length) |> isSequenceOfOperators
127127
| None -> false
128128

src/FSharpLint.Core/Framework/HintParser.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ module HintParser =
8383
[ attempt pident
8484
.>>. many (attempt (skipChar '.' >>. pident))
8585
.>>. opt (skipChar '.' >>. pidentorop)
86-
|>> (fun ((startIdent, idents), operator) ->
86+
|>> (fun ((startIdent, idents), maybeOperator) ->
8787
let identifiers = startIdent::idents
88-
match operator with
88+
match maybeOperator with
8989
| Some(operator) -> identifiers@[operator]
9090
| None -> identifiers)
9191
attempt (pidentorop |>> fun identOrOpChars -> [identOrOpChars])

src/FSharpLint.Core/Framework/Suppression.fs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type SuppressionInfo =
1616
type LineSuppression = { Line:int; Suppressions:SuppressionInfo list }
1717

1818
/// Parses a given file to find lines containing rule suppressions.
19-
let parseSuppressionInfo (rules:Set<String>) (lines:string list) =
19+
let parseSuppressionInfo (originalRuleNames:Set<String>) (lines:string list) =
2020
/// Extracts rule names from a whitespace separated string of rule names.
2121
let extractRules (rules:Set<String>) (str:string) =
2222
let (splitOnWhitespace:char[]) = null
@@ -29,16 +29,16 @@ let parseSuppressionInfo (rules:Set<String>) (lines:string list) =
2929
// If no rules set, then all rules are applied.
3030
if Seq.isEmpty entries then rules else entries
3131

32-
let rules = Set.map (fun (rule: String) -> rule.ToLowerInvariant()) rules
32+
let lowerCasedRules = Set.map (fun (rule: String) -> rule.ToLowerInvariant()) originalRuleNames
3333

3434
let choose lineNum line =
3535
let matched = Regex.Match (line, ".*fsharplint:([a-z\-]+)\s*(.*)$")
3636
if matched.Success then
3737
let suppressionTarget =
3838
if matched.Groups.Count = 3 then
39-
extractRules rules matched.Groups.[2].Value
39+
extractRules lowerCasedRules matched.Groups.[2].Value
4040
else
41-
rules
41+
lowerCasedRules
4242
match matched.Groups.[1].Value with
4343
| "enable" -> Some (lineNum, Enable suppressionTarget)
4444
| "disable" -> Some (lineNum, Disable suppressionTarget)
@@ -62,26 +62,25 @@ let isSuppressed (rule:String) (line:int) (lineSuppressions:LineSuppression list
6262
if List.isEmpty lineSuppressions then
6363
false
6464
else
65-
let rule = rule.ToLowerInvariant()
66-
65+
let ruleLowercase = rule.ToLowerInvariant()
6766

6867
let fold (disabledRules:Set<String>) (lineSuppression:LineSuppression) =
69-
let innerFold (disabledRules:Set<String>) suppression =
68+
let innerFold (currentDisabledRules:Set<String>) suppression =
7069
match suppression with
7170
| Enable(rules) ->
72-
Set.difference disabledRules rules
71+
Set.difference currentDisabledRules rules
7372
| Disable(rules) ->
74-
Set.union disabledRules rules
73+
Set.union currentDisabledRules rules
7574
| DisableLine(rules) ->
7675
if line = lineSuppression.Line then
77-
Set.union disabledRules rules
76+
Set.union currentDisabledRules rules
7877
else
79-
disabledRules
78+
currentDisabledRules
8079
List.fold innerFold disabledRules lineSuppression.Suppressions
8180

8281
let disabledRules =
8382
lineSuppressions
8483
|> List.takeWhile (fun lineSupression -> lineSupression.Line <= line)
8584
|> List.fold fold Set.empty
8685

87-
disabledRules.Contains(rule)
86+
disabledRules.Contains(ruleLowercase)

src/FSharpLint.Core/Framework/Utilities.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ module ExpressionUtilities =
8888

8989
/// Tries to find the source code within a given range.
9090
let tryFindTextOfRange (range:Range) (text:string) =
91-
let startIndex = findPos range.Start text
92-
let endIndex = findPos range.End text
91+
let maybeStartIndex = findPos range.Start text
92+
let maybeEndIndex = findPos range.End text
9393

94-
match (startIndex, endIndex) with
94+
match (maybeStartIndex, maybeEndIndex) with
9595
| Some(startIndex), Some(endIndex) ->
9696
text.Substring(startIndex, endIndex - startIndex) |> Some
9797
| _ -> None

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ and [<TailCall>] private checkExprContinuationPassingStyle (arguments: CheckExpr
9191
arguments.Continuation Array.empty
9292

9393
let runner (args: AstNodeRuleParams) =
94-
let checkExpr (args: AstNodeRuleParams) (expr: SynExpr) (outerArgExpr: SynExpr) (range: FSharp.Compiler.Text.range) (parentList: AstNode list): WarningDetails array =
94+
let checkExpr (expr: SynExpr) (outerArgExpr: SynExpr) (range: FSharp.Compiler.Text.range) (parentList: AstNode list): WarningDetails array =
9595
checkExprContinuationPassingStyle
9696
{
9797
Args = args
@@ -110,7 +110,7 @@ let runner (args: AstNodeRuleParams) =
110110
// function has extra arguments
111111
Array.empty
112112
| _ ->
113-
checkExpr args funcExpr argExpr range (args.GetParents args.NodeIndex)
113+
checkExpr funcExpr argExpr range (args.GetParents args.NodeIndex)
114114
| _ ->
115115
Array.empty
116116

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

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

1111
let private runner (args:AstNodeRuleParams) =
12-
let checkForNamedPatternEqualsConstant (args:AstNodeRuleParams) pattern whenExpr (range:Range) =
12+
let checkForNamedPatternEqualsConstant pattern whenExpr (range:Range) =
1313
let patternIdent =
1414
match pattern with
1515
| SynPat.Named(SynIdent.SynIdent(ident, _), _, _, _) -> Some(ident.idText)
@@ -45,7 +45,7 @@ let private runner (args:AstNodeRuleParams) =
4545

4646
match args.AstNode with
4747
| AstNode.Match(SynMatchClause.SynMatchClause(pat, Some(whenExpr), _, range, _, _)) ->
48-
checkForNamedPatternEqualsConstant args pat whenExpr range
48+
checkForNamedPatternEqualsConstant pat whenExpr range
4949

5050
| _ -> Array.empty
5151

0 commit comments

Comments
 (0)