Skip to content

Commit fdb83e4

Browse files
committed
Pass an FSharpProjectOptions down into the lint machinery when available
Rather than reading it from FSharpCheckProjectResults on every use, which appears to have a substantional performance cost. The project options is stored as a Lazy because it's expensive to calculate and only used by a few rules, so the work can be avoided altogether if those rules aren't being run. refs fsprojects#770
1 parent 8e20e0b commit fdb83e4

11 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/FSharpLint.Core/Application/Lint.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ module Lint =
125125
GlobalConfig: Rules.GlobalRuleConfig
126126
TypeCheckResults: FSharpCheckFileResults option
127127
ProjectCheckResults: FSharpCheckProjectResults option
128+
ProjectOptions: Lazy<FSharpProjectOptions option>
128129
FilePath: string
129130
FileContent: string
130131
Lines: string[]
@@ -149,6 +150,7 @@ module Lint =
149150
Lines = config.Lines
150151
CheckInfo = config.TypeCheckResults
151152
ProjectCheckInfo = config.ProjectCheckResults
153+
ProjectOptions = config.ProjectOptions
152154
GlobalConfig = config.GlobalConfig
153155
}
154156
// Build state for rules with context.
@@ -263,6 +265,10 @@ module Lint =
263265
GlobalConfig = enabledRules.GlobalConfig
264266
TypeCheckResults = fileInfo.TypeCheckResults
265267
ProjectCheckResults = fileInfo.ProjectCheckResults
268+
ProjectOptions = lazy(
269+
fileInfo.ProjectCheckResults
270+
|> Option.map _.ProjectContext.ProjectOptions
271+
)
266272
FilePath = fileInfo.File
267273
FileContent = fileInfo.Text
268274
Lines = lines

src/FSharpLint.Core/Application/Lint.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ module Lint =
129129
GlobalConfig: Rules.GlobalRuleConfig
130130
TypeCheckResults: FSharpCheckFileResults option
131131
ProjectCheckResults: FSharpCheckProjectResults option
132+
ProjectOptions: Lazy<FSharpProjectOptions option>
132133
FilePath: string
133134
FileContent: string
134135
Lines: string[]

src/FSharpLint.Core/Framework/Rules.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type AstNodeRuleParams =
3131
Lines:string []
3232
CheckInfo:FSharpCheckFileResults option
3333
ProjectCheckInfo:FSharpCheckProjectResults option
34+
ProjectOptions: Lazy<FSharpProjectOptions option>
3435
GlobalConfig:GlobalRuleConfig }
3536

3637
type LineRuleParams =

src/FSharpLint.Core/Rules/Conventions/Naming/AsynchronousFunctionNames.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ let runner (config: Config) (args: AstNodeRuleParams) =
3232
| _ -> config.Mode = AllAPIs
3333

3434
let likelyhoodOfBeingInLibrary =
35-
match args.ProjectCheckInfo with
36-
| Some projectInfo -> howLikelyProjectIsLibrary projectInfo.ProjectContext.ProjectOptions.ProjectFileName
35+
match args.ProjectOptions.Value with
36+
| Some projectOptions -> howLikelyProjectIsLibrary projectOptions.ProjectFileName
3737
| None -> Unlikely
3838

3939
if config.Mode = OnlyPublicAPIsInLibraries && likelyhoodOfBeingInLibrary <> Likely then

src/FSharpLint.Core/Rules/Conventions/Naming/SimpleAsyncComplementaryHelpers.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ let runner (config: Config) (args: AstNodeRuleParams) =
205205
Array.append (checkFuncs asyncFuncs taskFuncs) (checkFuncs taskFuncs asyncFuncs)
206206

207207
let likelyhoodOfBeingInLibrary =
208-
match args.ProjectCheckInfo with
209-
| Some projectInfo -> howLikelyProjectIsLibrary projectInfo.ProjectContext.ProjectOptions.ProjectFileName
208+
match args.ProjectOptions.Value with
209+
| Some projectOptions -> howLikelyProjectIsLibrary projectOptions.ProjectFileName
210210
| None -> Unlikely
211211

212212
if config.Mode = OnlyPublicAPIsInLibraries && likelyhoodOfBeingInLibrary <> Likely then

src/FSharpLint.Core/Rules/Smells/NoAsyncRunSynchronouslyInLibrary.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ let checkIfInLibrary (args: AstNodeRuleParams) (range: range) : array<WarningDet
9595
let ruleNotApplicable =
9696
isInObsoleteMethodOrFunction (args.GetParents args.NodeIndex)
9797
||
98-
match (args.CheckInfo, args.ProjectCheckInfo) with
99-
| Some checkFileResults, Some checkProjectResults ->
100-
let projectFile = System.IO.FileInfo checkProjectResults.ProjectContext.ProjectOptions.ProjectFileName
98+
match (args.CheckInfo, args.ProjectOptions.Value) with
99+
| Some checkFileResults, Some projectOptions ->
100+
let projectFile = System.IO.FileInfo projectOptions.ProjectFileName
101101
match howLikelyProjectIsLibrary projectFile.Name with
102102
| Likely -> false
103103
| Unlikely -> true

tests/FSharpLint.Core.Tests/Rules/TestAstNodeRule.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type TestAstNodeRuleBase (rule:Rule) =
4343
GlobalConfig = resolvedGlobalConfig
4444
TypeCheckResults = checkResult
4545
ProjectCheckResults = None
46+
ProjectOptions = Lazy<_>(None)
4647
FilePath = (Option.defaultValue String.Empty maybeFileName)
4748
FileContent = input
4849
Lines = (input.Split("\n"))

tests/FSharpLint.Core.Tests/Rules/TestHintMatcherBase.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type TestHintMatcherBase () =
6565
GlobalConfig = resolvedGlobalConfig
6666
TypeCheckResults = checkResult
6767
ProjectCheckResults = None
68+
ProjectOptions = Lazy<_>()
6869
FilePath = (Option.defaultValue String.Empty maybeFileName)
6970
FileContent = input
7071
Lines = (input.Split("\n"))

tests/FSharpLint.Core.Tests/Rules/TestIndentationRule.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type TestIndentationRuleBase (rule:Rule) =
3838
GlobalConfig = resolvedGlobalConfig
3939
TypeCheckResults = None
4040
ProjectCheckResults = None
41+
ProjectOptions = Lazy<_>(None)
4142
FilePath = resolvedFileName
4243
FileContent = input
4344
Lines = lines

tests/FSharpLint.Core.Tests/Rules/TestLineRule.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type TestLineRuleBase (rule:Rule) =
3838
GlobalConfig = resolvedGlobalConfig
3939
TypeCheckResults = None
4040
ProjectCheckResults = None
41+
ProjectOptions = Lazy<_>(None)
4142
FilePath = resolvedFileName
4243
FileContent = input
4344
Lines = lines

0 commit comments

Comments
 (0)