File tree Expand file tree Collapse file tree 5 files changed +68
-0
lines changed
tests/FSharpLint.Core.Tests Expand file tree Collapse file tree 5 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 6969 <Compile Include =" Rules\Smells\RaiseWithTooManyArguments\InvalidArgWithTwoArguments.fs" />
7070 <Compile Include =" Rules\Smells\RaiseWithTooManyArguments\FailwithfWithArgumentsMatchingFormatString.fs" />
7171 <Compile Include =" Rules\Conventions\FailwithBadUsage.fs" />
72+ <Compile Include =" Rules\Conventions\NoAsyncRunSynchronouslyInLibrary.fs" />
7273 <Compile Include =" Rules\Conventions\SourceLength\SourceLengthHelper.fs" />
7374 <Compile Include =" Rules\Conventions\SourceLength\MaxLinesInLambdaFunction.fs" />
7475 <Compile Include =" Rules\Conventions\SourceLength\MaxLinesInMatchLambdaFunction.fs" />
Original file line number Diff line number Diff line change 1+ module FSharpLint.Rules.NoAsyncRunSynchronouslyInLibrary
2+
3+ open FSharp.Compiler .Syntax
4+ open FSharp.Compiler .Text
5+ open FSharpLint.Framework
6+ open FSharpLint.Framework .Suggestion
7+ open FSharpLint.Framework .Ast
8+ open FSharpLint.Framework .Rules
9+ open FSharpLint.Framework .Utilities
10+
11+ let checkIfInLibrary ( syntaxArray : array < AbstractSyntaxArray.Node >) ( range : range ) : array < WarningDetails > =
12+ failwith " Not implemented"
13+
14+ let runner args =
15+ match args.AstNode with
16+ | AstNode.Identifier([ " Async" ; " RunSynchronously" ], range) ->
17+ checkIfInLibrary args.SyntaxArray range
18+ | _ -> Array.empty
19+
20+ let rule =
21+ AstNodeRule
22+ {
23+ Name = " NoAsyncRunSynchronouslyInLibrary"
24+ Identifier = Identifiers.NoAsyncRunSynchronouslyInLibrary
25+ RuleConfig =
26+ {
27+ AstNodeRuleConfig.Runner = runner
28+ Cleanup = ignore
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -92,3 +92,4 @@ let FavourNonMutablePropertyInitialization = identifier 84
9292let EnsureTailCallDiagnosticsInRecursiveFunctions = identifier 85
9393let FavourAsKeyword = identifier 86
9494let InterpolatedStringWithNoSubstitution = identifier 87
95+ let NoAsyncRunSynchronouslyInLibrary = identifier 88
Original file line number Diff line number Diff line change 4747 <Compile Include =" Rules\Conventions\UsedUnderscorePrefixedElements.fs" />
4848 <Compile Include =" Rules\Conventions\FavourNonMutablePropertyInitialization.fs" />
4949 <Compile Include =" Rules\Conventions\EnsureTailCallDiagnosticsInRecursiveFunctions.fs" />
50+ <Compile Include =" Rules\Conventions\NoAsyncRunSynchronouslyInLibrary.fs" />
5051 <Compile Include =" Rules\Conventions\Naming\NamingHelpers.fs" />
5152 <Compile Include =" Rules\Conventions\Naming\InterfaceNames.fs" />
5253 <Compile Include =" Rules\Conventions\Naming\ExceptionNames.fs" />
Original file line number Diff line number Diff line change 1+ module FSharpLint.Core.Tests.Rules.Conventions.NoAsyncRunSynchronouslyInLibrary
2+
3+ open NUnit.Framework
4+ open FSharpLint.Framework .Rules
5+ open FSharpLint.Rules
6+
7+ [<TestFixture>]
8+ type TestNoAsyncRunSynchronouslyInLibrary () =
9+ inherit FSharpLint.Core.Tests.TestAstNodeRuleBase.TestAstNodeRuleBase( NoAsyncRunSynchronouslyInLibrary.rule)
10+
11+ [<Test>]
12+ member this. ``Async.RunSynchronously should not be used in library code`` () =
13+ this.Parse( """
14+ module Program
15+
16+ async {
17+ return ()
18+ }
19+ |> Async.RunSynchronously""" )
20+
21+ Assert.IsTrue this.ErrorsExist
22+
23+ [<Test>]
24+ member this. ``Async.RunSynchronously may be used in code that declares entry point`` () =
25+ this.Parse( """
26+ module Program
27+
28+ [<EntryPoint>]
29+ let main () =
30+ async {
31+ return ()
32+ }
33+ |> Async.RunSynchronously""" )
34+
35+ this.AssertNoWarnings()
You can’t perform that action at this time.
0 commit comments