Skip to content

Commit

Permalink
Core: implement new rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho committed Dec 27, 2023
1 parent 1efe4fe commit 2f2c570
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,33 @@ open FSharpLint.Framework.Rules
open FSharpLint.Framework
open FSharpLint.Framework.Suggestion

let runner (args:AstNodeRuleParams) =
printfn "%A" args.AstNode
failwith "not implemented"
let runner (args: AstNodeRuleParams) =
match args.AstNode, args.CheckInfo with
| AstNode.ModuleDeclaration (SynModuleDecl.Let (isRecursive, bindings, _)), Some checkInfo when isRecursive ->
match bindings with
| SynBinding (_, _, _, _, _, _, _, SynPat.LongIdent (longDotId, _, _, _, _, range), _, _, _, _) :: _ ->
let symbolUses = checkInfo.GetAllUsesOfAllSymbolsInFile()
let funcName = longDotId.Lid.Head.idText

let functionCalls =
symbolUses
|> Seq.filter (fun (symbol) -> symbol.Symbol.DisplayName = funcName)

if (functionCalls |> Seq.length) <= 1 then
{ Range = range
Message =
String.Format(
Resources.GetString "RulesAvoidMisleadingRecursiveKeywordInNonRecursiveFuncs",
funcName
)
SuggestedFix = None
TypeChecks = list.Empty }
|> Array.singleton
else
Array.empty
| _ -> Array.empty

| _ -> Array.empty

let rule =
{ Name = "AvoidMisleadingRecursiveKeywordInNonRecursiveFuncs"
Expand Down
3 changes: 3 additions & 0 deletions src/FSharpLint.Core/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,7 @@
<data name="RulesSuggestUseAutoProperty" xml:space="preserve">
<value>Consider using auto-properties via the 'val' keyword.</value>
</data>
<data name="RulesAvoidMisleadingRecursiveKeywordInNonRecursiveFuncs" xml:space="preserve">
<value>The '{0}' function has a "rec" keyword, but it is not really recursive, consider removing it.</value>
</data>
</root>

0 comments on commit 2f2c570

Please sign in to comment.