-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathTestNoTabCharactersRule.fs
More file actions
58 lines (48 loc) · 2.31 KB
/
Copy pathTestNoTabCharactersRule.fs
File metadata and controls
58 lines (48 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module FSharpLint.Core.Tests.TestNoTabCharactersRuleBase
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text
open FSharpLint.Application
open FSharpLint.Framework
open FSharpLint.Framework.Configuration
open FSharpLint.Framework.Rules
[<AbstractClass>]
type TestNoTabCharactersRuleBase (rule:Rule) =
inherit TestRuleBase.TestRuleBase()
override this.Parse (input:string, ?fileName:string, ?_checkFile:bool, ?globalConfig:GlobalRuleConfig) =
let checker = FSharpChecker.Create(keepAssemblyContents=true)
let sourceText = SourceText.ofString input
let resolvedFileName = Option.defaultValue "Test.fsx" fileName
let projectOptions, _ = checker.GetProjectOptionsFromScript(resolvedFileName, sourceText) |> Async.RunSynchronously
let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions projectOptions
let parseResults = checker.ParseFile("test.fsx", sourceText, parsingOptions) |> Async.RunSynchronously
let noTabCharactersRule =
match rule with
| NoTabCharactersRule ntcRule -> ntcRule
| _ -> failwith "TestNoTabCharactersRuleBase only accepts NoTabCharactersRules"
let resolvedGlobalConfig = Option.defaultValue GlobalRuleConfig.Default globalConfig
let lines = input.Split "\n"
let syntaxArray = AbstractSyntaxArray.astToArray parseResults.ParseTree
let (_, context) =
runAstNodeRules
{
Rules = Array.empty
GlobalConfig = resolvedGlobalConfig
TypeCheckResults = None
ProjectCheckResults = None
ProjectFileName = Lazy<_>()
FilePath = resolvedFileName
FileContent = input
Lines = lines
SyntaxArray = syntaxArray
}
let lineRules = { LineRules.IndentationRule = None; NoTabCharactersRule = Some noTabCharactersRule; GenericLineRules = Array.empty }
runLineRules
{
LineRules = lineRules
GlobalConfig = resolvedGlobalConfig
FilePath = resolvedFileName
FileContent = input
Lines = lines
Context = context
}
|> Array.iter this.PostSuggestion