@@ -10,6 +10,11 @@ open FSharpLint.Framework.Ast
1010open FSharpLint.Framework .Rules
1111open FSharpLint.Framework .Utilities
1212
13+ type LibraryHeuristicResultByProjectName =
14+ | Likely
15+ | Unlikely
16+ | Uncertain
17+
1318let hasEntryPoint ( checkFileResults : FSharpCheckFileResults ) ( maybeProjectCheckResults : FSharpCheckProjectResults option ) =
1419 let hasEntryPointInTheSameFile =
1520 match checkFileResults.ImplementationFile with
@@ -26,15 +31,16 @@ let hasEntryPoint (checkFileResults: FSharpCheckFileResults) (maybeProjectCheckR
2631
2732let excludedProjectNames = [ " test" ; " console" ]
2833
29- let isInTestProject ( checkFileResults : FSharpCheckFileResults ) =
30- let namespaceIncludesTest =
31- match checkFileResults.ImplementationFile with
32- | Some implFile ->
33- excludedProjectNames |> List.exists ( fun name -> implFile.QualifiedName.ToLowerInvariant() .Contains name)
34- | None -> false
35- let projectFileInfo = System.IO.FileInfo checkFileResults.ProjectContext.ProjectOptions.ProjectFileName
36- namespaceIncludesTest
37- || excludedProjectNames |> List.exists ( fun name -> projectFileInfo.Name.ToLowerInvariant() .Contains name)
34+ let howLikelyProjectIsLibrary ( projectFileName : string ): LibraryHeuristicResultByProjectName =
35+ let nameSegments = Helper.Naming.QuickFixes.splitByCaseChange projectFileName
36+ if nameSegments |> Seq.contains " Lib" then
37+ Likely
38+ elif excludedProjectNames |> List.exists ( fun name -> projectFileName.ToLowerInvariant() .Contains name) then
39+ Unlikely
40+ elif projectFileName.ToLowerInvariant() .EndsWith " lib" then
41+ Likely
42+ else
43+ Uncertain
3844
3945let extractAttributeNames ( attributes : SynAttributes ) =
4046 seq {
@@ -94,15 +100,19 @@ let isInObsoleteMethodOrFunction parents =
94100
95101let checkIfInLibrary ( args : AstNodeRuleParams ) ( range : range ) : array < WarningDetails > =
96102 let ruleNotApplicable =
103+ isInObsoleteMethodOrFunction ( args.GetParents args.NodeIndex)
104+ ||
97105 match args.CheckInfo with
98106 | Some checkFileResults ->
99- hasEntryPoint checkFileResults args.ProjectCheckInfo
100- || isInTestProject checkFileResults
101- || isInObsoleteMethodOrFunction ( args.GetParents args.NodeIndex)
102- || isInTheSameModuleAsTest args.SyntaxArray args.ProjectCheckInfo
107+ let projectFileName = System.IO.FileInfo( checkFileResults.ProjectContext.ProjectOptions.ProjectFileName) .Name
108+ match howLikelyProjectIsLibrary projectFileName with
109+ | Likely -> false
110+ | Unlikely -> true
111+ | Uncertain ->
112+ hasEntryPoint checkFileResults args.ProjectCheckInfo
113+ || isInTheSameModuleAsTest args.SyntaxArray args.ProjectCheckInfo
103114 | None ->
104- isInObsoleteMethodOrFunction ( args.GetParents args.NodeIndex)
105- || isInTheSameModuleAsTest args.SyntaxArray args.ProjectCheckInfo
115+ isInTheSameModuleAsTest args.SyntaxArray args.ProjectCheckInfo
106116
107117 if ruleNotApplicable then
108118 Array.empty
0 commit comments