Skip to content

Commit

Permalink
FavourNestedFunctions: hook cfg & add docs
Browse files Browse the repository at this point in the history
Updated Configuration.fs and fsharplint.json to include
FavourNestedFunctions rule. Added docs.
  • Loading branch information
webwarrior-ws committed Dec 21, 2023
1 parent 62375ea commit 8d130ab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/content/how-tos/rule-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ The following rules can be specified for linting.
- [SuggestUseAutoProperty (FL0079)](rules/FL0079.html)
- [UnnestedFunctionNames (FL0080)](rules/FL0080.html)
- [NestedFunctionNames (FL0081)](rules/FL0081.html)
- [FavourNestedFunctions (FL0082)](rules/FL0082.html)
31 changes: 31 additions & 0 deletions docs/content/how-tos/rules/FL0082.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: FL0082
category: how-to
hide_menu: true
---

# FavourNestedFunctions (FL0082)

*Introduced in `0.23.0`*

## Cause

Prefer using local (nested) functions over private module-level functions.

## Rationale

With a nested function, one can clearly see from reading the code that there is only one consumer of the function.
The code being this way becomes more streamlined.
Code is also more concise because nested functions don't need accessibility modifiers.

## How To Fix

Move private function inside function that uses it.

## Rule Settings

{
"FavourNestedFunctions": {
"enabled": false
}
}
9 changes: 7 additions & 2 deletions src/FSharpLint.Core/Application/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ type ConventionsConfig =
binding:BindingConfig option
favourReRaise:EnabledConfig option
favourConsistentThis:RuleConfig<FavourConsistentThis.Config> option
suggestUseAutoProperty:EnabledConfig option}
suggestUseAutoProperty:EnabledConfig option
favourNestedFunctions:EnabledConfig option }
with
member this.Flatten() =
[|
Expand All @@ -344,6 +345,7 @@ with
this.numberOfItems |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
this.binding |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
this.suggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule) |> Option.toArray
this.favourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule) |> Option.toArray
|] |> Array.concat

type TypographyConfig =
Expand Down Expand Up @@ -463,7 +465,8 @@ type Configuration =
TrailingNewLineInFile:EnabledConfig option
NoTabCharacters:EnabledConfig option
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
SuggestUseAutoProperty:EnabledConfig option }
SuggestUseAutoProperty:EnabledConfig option
FavourNestedFunctions:EnabledConfig option }
with
static member Zero = {
Global = None
Expand Down Expand Up @@ -551,6 +554,7 @@ with
NoTabCharacters = None
NoPartialFunctions = None
SuggestUseAutoProperty = None
FavourNestedFunctions = None
}

// fsharplint:enable RecordFieldNames
Expand Down Expand Up @@ -701,6 +705,7 @@ let flattenConfig (config:Configuration) =
config.TrailingNewLineInFile |> Option.bind (constructRuleIfEnabled TrailingNewLineInFile.rule)
config.NoTabCharacters |> Option.bind (constructRuleIfEnabled NoTabCharacters.rule)
config.NoPartialFunctions |> Option.bind (constructRuleWithConfig NoPartialFunctions.rule)
config.FavourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule)
|] |> Array.choose id

if config.NonPublicValuesNames.IsSome &&
Expand Down
1 change: 1 addition & 0 deletions src/FSharpLint.Core/fsharplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
"additionalPartials": []
}
},
"favourNestedFunctions": { "enabled": false },
"hints": {
"add": [
"not (a = b) ===> a <> b",
Expand Down

0 comments on commit 8d130ab

Please sign in to comment.