Skip to content

Commit 0d149cf

Browse files
committed
SimpleAsyncComplementaryHelpers: implemented modes
Mode OnlyPublicAPIsInLibraries only runs in projects that are likely library projects. Mode AnyPublicAPIs flags all public APIs like before. Mode AllAPIs also flags (give violations about) internal, private, and nested APIs.
1 parent 6b22d7b commit 0d149cf

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open FSharpLint.Framework
55
open FSharpLint.Framework.Suggestion
66
open FSharpLint.Framework.Ast
77
open FSharpLint.Framework.Rules
8+
open FSharpLint.Rules.Utilities.LibraryHeuristics
89
open Helper.Naming.Asynchronous
910
open FSharp.Compiler.Syntax
1011
open 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

195210
let rule config =
196211
AstNodeRule

0 commit comments

Comments
 (0)