File tree Expand file tree Collapse file tree 5 files changed +98
-0
lines changed
tests/FSharpLint.Core.Tests Expand file tree Collapse file tree 5 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 5858 <Compile Include =" Rules\Conventions\UsedUnderscorePrefixedElements.fs" />
5959 <Compile Include =" Rules\Conventions\FavourNonMutablePropertyInitialization.fs" />
6060 <Compile Include =" Rules\Conventions\EnsureTailCallDiagnosticsInRecursiveFunctions.fs" />
61+ <Compile Include =" Rules\Conventions\FavourNestedFunctions.fs" />
6162 <Compile Include =" Rules\Conventions\RaiseWithTooManyArguments\RaiseWithTooManyArgumentsHelper.fs" />
6263 <Compile Include =" Rules\Conventions\RaiseWithTooManyArguments\FailwithWithSingleArgument.fs" />
6364 <Compile Include =" Rules\Conventions\RaiseWithTooManyArguments\RaiseWithSingleArgument.fs" />
Original file line number Diff line number Diff line change 1+ module FSharpLint.Rules.FavourNestedFunctions
2+
3+ open System
4+ open FSharp.Compiler .Syntax
5+ open FSharpLint.Framework .Ast
6+ open FSharpLint.Framework .Rules
7+ open FSharpLint.Framework
8+ open FSharpLint.Framework .Suggestion
9+
10+ let runner ( args : AstNodeRuleParams ) =
11+ failwith " Not yet implemeted"
12+
13+ let rule =
14+ { Name = " FavourNestedFunctions"
15+ Identifier = Identifiers.FavourNestedFunctions
16+ RuleConfig =
17+ { AstNodeRuleConfig.Runner = runner
18+ Cleanup = ignore } }
19+ |> AstNodeRule
Original file line number Diff line number Diff line change @@ -92,3 +92,4 @@ let UnneededRecKeyword = identifier 83
9292let FavourNonMutablePropertyInitialization = identifier 84
9393let EnsureTailCallDiagnosticsInRecursiveFunctions = identifier 85
9494let FavourAsKeyword = identifier 86
95+ let FavourNestedFunctions = identifier 87
Original file line number Diff line number Diff line change 4646 <Compile Include =" Rules\Conventions\UsedUnderscorePrefixedElements.fs" />
4747 <Compile Include =" Rules\Conventions\FavourNonMutablePropertyInitialization.fs" />
4848 <Compile Include =" Rules\Conventions\EnsureTailCallDiagnosticsInRecursiveFunctions.fs" />
49+ <Compile Include =" Rules\Conventions\FavourNestedFunctions.fs" />
4950 <Compile Include =" Rules\Conventions\Naming\NamingHelpers.fs" />
5051 <Compile Include =" Rules\Conventions\Naming\InterfaceNames.fs" />
5152 <Compile Include =" Rules\Conventions\Naming\ExceptionNames.fs" />
Original file line number Diff line number Diff line change 1+ module FSharpLint.Core.Tests.Rules.Conventions.FavourNestedFunctions
2+
3+ open NUnit.Framework
4+ open FSharpLint.Rules
5+ open FSharpLint.Core .Tests
6+
7+ [<TestFixture>]
8+ type TestFavourNestedFunctions () =
9+ inherit TestAstNodeRuleBase.TestAstNodeRuleBase( FavourNestedFunctions.rule)
10+
11+ [<Test>]
12+ member this. ``Top level functions that are not used in another function should not give an error`` () =
13+ this.Parse """
14+ let Foo () =
15+ ()
16+
17+ let Bar () =
18+ ()
19+ """
20+
21+ this.AssertNoWarnings()
22+
23+ [<Test>]
24+ member this. ``Top level private functions that are not used in another function should not give an error`` () =
25+ this.Parse """
26+ let private Foo () =
27+ ()
28+
29+ let Bar () =
30+ ()
31+ """
32+
33+ this.AssertNoWarnings()
34+
35+ [<Test>]
36+ member this. ``Top level private function that is used in single function should give an error`` () =
37+ this.Parse """
38+ let private Foo () =
39+ ()
40+
41+ let Bar () =
42+ Foo()
43+ ()
44+ """
45+
46+ Assert.IsTrue this.ErrorsExist
47+
48+ [<Test>]
49+ member this. ``Nested functions should not give an error`` () =
50+ this.Parse """
51+ let Bar () =
52+ let Foo() =
53+ ()
54+
55+ Foo()
56+ ()
57+ """
58+
59+ this.AssertNoWarnings()
60+
61+ [<Test>]
62+ member this. ``Private function that is used in more than one function should not give an error`` () =
63+ this.Parse """
64+ let private Foo () =
65+ ()
66+
67+ let Bar () =
68+ Foo()
69+ ()
70+
71+ let Baz () =
72+ Foo ()
73+ ()
74+ """
75+
76+ this.AssertNoWarnings()
You can’t perform that action at this time.
0 commit comments