@@ -118,67 +118,87 @@ module Lint =
118
118
{ IndentationRuleContext: Map < int , bool * int >
119
119
NoTabCharactersRuleContext:( string * Range ) list }
120
120
121
- let runAstNodeRules ( rules : RuleMetadata < AstNodeRuleConfig > []) ( globalConfig : Rules.GlobalRuleConfig ) typeCheckResults ( filePath : string ) ( fileContent : string ) ( lines : string []) syntaxArray =
121
+ type RunAstNodeRulesConfig =
122
+ {
123
+ Rules: RuleMetadata < AstNodeRuleConfig >[]
124
+ GlobalConfig: Rules .GlobalRuleConfig
125
+ TypeCheckResults: FSharpCheckFileResults option
126
+ FilePath: string
127
+ FileContent: string
128
+ Lines: string []
129
+ SyntaxArray: AbstractSyntaxArray .Node array
130
+ }
131
+
132
+ let runAstNodeRules ( config : RunAstNodeRulesConfig ) =
122
133
let mutable indentationRuleState = Map.empty
123
134
let mutable noTabCharactersRuleState = List.empty
124
135
125
136
let collect index ( astNode : AbstractSyntaxArray.Node ) =
126
- let getParents ( depth : int ) = AbstractSyntaxArray.getBreadcrumbs depth syntaxArray index
137
+ let getParents ( depth : int ) = AbstractSyntaxArray.getBreadcrumbs depth config.SyntaxArray index
127
138
let astNodeParams =
128
139
{
129
140
AstNode = astNode.Actual
130
141
NodeHashcode = astNode.Hashcode
131
142
NodeIndex = index
132
- SyntaxArray = syntaxArray
143
+ SyntaxArray = config.SyntaxArray
133
144
GetParents = getParents
134
- FilePath = filePath
135
- FileContent = fileContent
136
- Lines = lines
137
- CheckInfo = typeCheckResults
138
- GlobalConfig = globalConfig }
145
+ FilePath = config.FilePath
146
+ FileContent = config.FileContent
147
+ Lines = config.Lines
148
+ CheckInfo = config.TypeCheckResults
149
+ GlobalConfig = config.GlobalConfig }
139
150
// Build state for rules with context.
140
151
indentationRuleState <- Indentation.ContextBuilder.builder indentationRuleState astNode.Actual
141
152
noTabCharactersRuleState <- NoTabCharacters.ContextBuilder.builder noTabCharactersRuleState astNode.Actual
142
153
143
- rules
154
+ config.Rules
144
155
|> Array.collect ( fun rule -> runAstNodeRule rule astNodeParams)
145
156
146
157
// Collect suggestions for AstNode rules, and build context for following rules.
147
158
let astNodeSuggestions =
148
- syntaxArray
159
+ config.SyntaxArray
149
160
|> Array.mapi ( fun index astNode -> ( index, astNode))
150
161
|> Array.collect ( fun ( index , astNode ) -> collect index astNode)
151
162
152
163
let context =
153
164
{ IndentationRuleContext = indentationRuleState
154
165
NoTabCharactersRuleContext = noTabCharactersRuleState }
155
166
156
- rules |> Array.iter ( fun rule -> rule.RuleConfig.Cleanup())
167
+ config.Rules |> Array.iter ( fun rule -> rule.RuleConfig.Cleanup())
157
168
( astNodeSuggestions, context)
158
169
159
- let runLineRules ( lineRules : Configuration.LineRules ) ( globalConfig : Rules.GlobalRuleConfig ) ( filePath : string ) ( fileContent : string ) ( lines : string []) ( context : Context ) =
170
+ type RunLineRulesConfig =
171
+ {
172
+ LineRules: Configuration .LineRules
173
+ GlobalConfig: Rules .GlobalRuleConfig
174
+ FilePath: string
175
+ FileContent: string
176
+ Lines: string []
177
+ Context: Context
178
+ }
179
+ let runLineRules ( config : RunLineRulesConfig ) =
160
180
let collectErrors ( line : string ) ( lineNumber : int ) ( isLastLine : bool ) =
161
181
let lineParams =
162
- {
182
+ {
163
183
LineRuleParams.Line = line
164
184
LineNumber = lineNumber + 1
165
185
IsLastLine = isLastLine
166
- FilePath = filePath
167
- FileContent = fileContent
168
- Lines = lines
169
- GlobalConfig = globalConfig
186
+ FilePath = config.FilePath
187
+ FileContent = config.FileContent
188
+ Lines = config.Lines
189
+ GlobalConfig = config.GlobalConfig
170
190
}
171
191
172
192
let indentationError =
173
- lineRules .IndentationRule
174
- |> Option.map ( fun rule -> runLineRuleWithContext rule context .IndentationRuleContext lineParams)
193
+ config.LineRules .IndentationRule
194
+ |> Option.map ( fun rule -> runLineRuleWithContext rule config.Context .IndentationRuleContext lineParams)
175
195
176
196
let noTabCharactersError =
177
- lineRules .NoTabCharactersRule
178
- |> Option.map ( fun rule -> runLineRuleWithContext rule context .NoTabCharactersRuleContext lineParams)
197
+ config.LineRules .NoTabCharactersRule
198
+ |> Option.map ( fun rule -> runLineRuleWithContext rule config.Context .NoTabCharactersRuleContext lineParams)
179
199
180
200
let lineErrors =
181
- lineRules .GenericLineRules
201
+ config.LineRules .GenericLineRules
182
202
|> Array.collect ( fun rule -> runLineRule rule lineParams)
183
203
184
204
[|
@@ -187,7 +207,7 @@ module Lint =
187
207
lineErrors |> Array.singleton
188
208
|]
189
209
190
- fileContent
210
+ config.FileContent
191
211
|> String.toLines
192
212
|> Array.collect ( fun ( line , lineNumber , isLastLine ) -> collectErrors line lineNumber isLastLine)
193
213
|> Array.concat
@@ -230,8 +250,28 @@ module Lint =
230
250
let syntaxArray = AbstractSyntaxArray.astToArray fileInfo.Ast
231
251
232
252
// Collect suggestions for AstNode rules
233
- let ( astNodeSuggestions , context ) = runAstNodeRules enabledRules.AstNodeRules enabledRules.GlobalConfig fileInfo.TypeCheckResults fileInfo.File fileInfo.Text lines syntaxArray
234
- let lineSuggestions = runLineRules enabledRules.LineRules enabledRules.GlobalConfig fileInfo.File fileInfo.Text lines context
253
+ let ( astNodeSuggestions , context ) =
254
+ runAstNodeRules
255
+ {
256
+ Rules = enabledRules.AstNodeRules
257
+ GlobalConfig = enabledRules.GlobalConfig
258
+ TypeCheckResults = fileInfo.TypeCheckResults
259
+ FilePath = fileInfo.File
260
+ FileContent = fileInfo.Text
261
+ Lines = lines
262
+ SyntaxArray = syntaxArray
263
+ }
264
+
265
+ let lineSuggestions =
266
+ runLineRules
267
+ {
268
+ LineRules = enabledRules.LineRules
269
+ GlobalConfig = enabledRules.GlobalConfig
270
+ FilePath = fileInfo.File
271
+ FileContent = fileInfo.Text
272
+ Lines = lines
273
+ Context = context
274
+ }
235
275
236
276
[| lineSuggestions; astNodeSuggestions |]
237
277
|> Array.concat
0 commit comments