@@ -5,6 +5,7 @@ open FSharpLint.Framework
55open FSharpLint.Framework .Suggestion
66open FSharpLint.Framework .Ast
77open FSharpLint.Framework .Rules
8+ open FSharpLint.Rules .Utilities .LibraryHeuristics
89open Helper.Naming .Asynchronous
910open FSharp.Compiler .Syntax
1011open FSharp.Compiler .Text
@@ -111,10 +112,16 @@ let runner (config: Config) (args: AstNodeRuleParams) =
111112 let processDeclarations ( declarations : list < SynModuleDecl >) =
112113 let bindings = getBindings List.Empty declarations
113114
115+ let isAccessibilityLevelApplicable ( accessibility : Option < SynAccess >) =
116+ match accessibility with
117+ | None
118+ | Some( SynAccess.Public _) -> true
119+ | _ -> config.Mode = AllAPIs
120+
114121 let tryGetFunction ( binding : SynBinding ) =
115122 match binding with
116- | SynBinding(_, _, _, _, _, _, _, SynPat.LongIdent( funcIdent, _, _, argPats, ( None | Some ( SynAccess.Public _)) , _), returnInfo, _, _, _, _)
117- when not argPats.Patterns.IsEmpty ->
123+ | SynBinding(_, _, _, _, _, _, _, SynPat.LongIdent( funcIdent, _, _, argPats, accessibility , _), returnInfo, _, _, _, _)
124+ when isAccessibilityLevelApplicable accessibility && not argPats.Patterns.IsEmpty ->
118125 let returnTypeParam =
119126 match returnInfo with
120127 | Some( SynBindingReturnInfo( SynType.App( SynType.LongIdent( SynLongIdent _), _, [ typeParam ], _, _, _, _), _, _, _)) ->
@@ -184,13 +191,21 @@ let runner (config: Config) (args: AstNodeRuleParams) =
184191 |> Array.concat
185192
186193 Array.append ( checkFuncs asyncFuncs taskFuncs) ( checkFuncs taskFuncs asyncFuncs)
187-
188- match args.AstNode with
189- | Ast.ModuleOrNamespace( SynModuleOrNamespace(_, _, _, declarations, _, _, _, _, _)) ->
190- processDeclarations declarations
191- | ModuleDeclaration( SynModuleDecl.NestedModule(_, _, declarations, _, _, _)) ->
192- processDeclarations declarations
193- | _ -> Array.empty
194+
195+ let likelyhoodOfBeingInLibrary =
196+ match args.ProjectCheckInfo with
197+ | Some projectInfo -> howLikelyProjectIsLibrary projectInfo.ProjectContext.ProjectOptions.ProjectFileName
198+ | None -> Unlikely
199+
200+ if config.Mode = OnlyPublicAPIsInLibraries && likelyhoodOfBeingInLibrary <> Likely then
201+ Array.empty
202+ else
203+ match args.AstNode with
204+ | Ast.ModuleOrNamespace( SynModuleOrNamespace(_, _, _, declarations, _, _, _, _, _)) ->
205+ processDeclarations declarations
206+ | ModuleDeclaration( SynModuleDecl.NestedModule(_, _, declarations, _, _, _)) ->
207+ processDeclarations declarations
208+ | _ -> Array.empty
194209
195210let rule config =
196211 AstNodeRule
0 commit comments