Skip to content

Commit

Permalink
Core: introduce new rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho committed Dec 26, 2023
1 parent 237280f commit 1efe4fe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/FSharpLint.Core/FSharpLint.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Compile Include="Rules\Formatting\TypedItemSpacing.fs" />
<Compile Include="Rules\Formatting\TypePrefixing.fs" />
<Compile Include="Rules\Formatting\UnionDefinitionIndentation.fs" />
<Compile Include="Rules\Conventions\AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs.fs" />
<Compile Include="Rules\Conventions\AsyncExceptionWithoutReturn.fs" />
<Compile Include="Rules\Conventions\FavourStaticEmptyFields.fs" />
<Compile Include="Rules\Conventions\RecursiveAsyncFunction.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module FSharpLint.Rules.AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs

open System
open FSharp.Compiler.Syntax
open FSharpLint.Framework.Ast
open FSharpLint.Framework.Rules
open FSharpLint.Framework
open FSharpLint.Framework.Suggestion

let runner (args:AstNodeRuleParams) =
printfn "%A" args.AstNode
failwith "not implemented"

let rule =
{ Name = "AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs"
Identifier = Identifiers.AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs
RuleConfig =
{ AstNodeRuleConfig.Runner = runner
Cleanup = ignore } }
|> AstNodeRule
1 change: 1 addition & 0 deletions src/FSharpLint.Core/Rules/Identifiers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ let AsyncExceptionWithoutReturn = identifier 78
let SuggestUseAutoProperty = identifier 79
let UnnestedFunctionNames = identifier 80
let NestedFunctionNames = identifier 81
let AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs = identifier 82
1 change: 1 addition & 0 deletions tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="Rules\Formatting\TypedItemSpacing.fs" />
<Compile Include="Rules\Formatting\UnionDefinitionIndentation.fs" />
<Compile Include="Rules\Formatting\TypePrefixing.fs" />
<Compile Include="Rules\Conventions\AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs.fs" />
<Compile Include="Rules\Conventions\AsyncExceptionWithoutReturn.fs" />
<Compile Include="Rules\Conventions\FavourStaticEmptyFields.fs" />
<Compile Include="Rules\Conventions\RecursiveAsyncFunction.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module FSharpLint.Core.Tests.Rules.Conventions.AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs

open NUnit.Framework
open FSharpLint.Framework.Rules
open FSharpLint.Rules

[<TestFixture>]
type TestConventionsAvoidMisleadingRecursiveKeywordInNonRecursiveFuncs() =
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs.rule)

[<Test>]
member this.AvoidMisleadingRecursiveKeywordInNonRecursiveFuncsShouldNotProduceError() =
this.Parse """
let rec Foo () =
if someParam then
Foo()
else
()"""

Assert.IsTrue this.NoErrorsExist

[<Test>]
member this.AvoidMisleadingRecursiveKeywordInNonRecursiveFuncsShouldProduceError() =
this.Parse """
let rec Foo someParam =
()"""

Assert.IsTrue this.ErrorsExist

0 comments on commit 1efe4fe

Please sign in to comment.