Skip to content

Commit 8f09e08

Browse files
committed
FavourNestedFunctions: hook cfg & add docs
Updated Configuration.fs and fsharplint.json to include FavourNestedFunctions rule. Added docs.
1 parent 1d37b03 commit 8f09e08

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

docs/content/how-tos/rule-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ The following rules can be specified for linting.
127127
- [FavourNonMutablePropertyInitialization (FL0084)](rules/FL0084.html)
128128
- [EnsureTailCallDiagnosticsInRecursiveFunctions (FL0085)](rules/FL0085.html)
129129
- [FavourAsKeyword (FL0086)](rules/FL0086.html)
130+
- [FavourNestedFunctions (FL0087)](rules/FL0087.html)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: FL0087
3+
category: how-to
4+
hide_menu: true
5+
---
6+
7+
# FavourNestedFunctions (FL0087)
8+
9+
*Introduced in `0.24.3`*
10+
11+
## Cause
12+
13+
Prefer using local (nested) functions over private module-level functions.
14+
15+
## Rationale
16+
17+
With a nested function, one can clearly see from reading the code that there is only one consumer of the function.
18+
The code being this way becomes more streamlined.
19+
Code is also more concise because nested functions don't need accessibility modifiers.
20+
21+
## How To Fix
22+
23+
Move private function inside function that uses it.
24+
25+
## Rule Settings
26+
27+
{
28+
"FavourNestedFunctions": {
29+
"enabled": false
30+
}
31+
}

src/FSharpLint.Core/Application/Configuration.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ type ConventionsConfig =
309309
favourConsistentThis:RuleConfig<FavourConsistentThis.Config> option
310310
suggestUseAutoProperty:EnabledConfig option
311311
usedUnderscorePrefixedElements:EnabledConfig option
312-
ensureTailCallDiagnosticsInRecursiveFunctions:EnabledConfig option}
312+
ensureTailCallDiagnosticsInRecursiveFunctions:EnabledConfig option
313+
favourNestedFunctions:EnabledConfig option }
313314
with
314315
member this.Flatten() =
315316
[|
@@ -335,6 +336,7 @@ with
335336
this.binding |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
336337
this.suggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule) |> Option.toArray
337338
this.ensureTailCallDiagnosticsInRecursiveFunctions |> Option.bind (constructRuleIfEnabled EnsureTailCallDiagnosticsInRecursiveFunctions.rule) |> Option.toArray
339+
this.favourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule) |> Option.toArray
338340
|] |> Array.concat
339341

340342
type TypographyConfig =
@@ -461,7 +463,9 @@ type Configuration =
461463
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
462464
SuggestUseAutoProperty:EnabledConfig option
463465
EnsureTailCallDiagnosticsInRecursiveFunctions:EnabledConfig option
464-
FavourAsKeyword:EnabledConfig option }
466+
FavourAsKeyword:EnabledConfig option
467+
SuggestUseAutoProperty:EnabledConfig option
468+
FavourNestedFunctions:EnabledConfig option }
465469
with
466470
static member Zero = {
467471
Global = None
@@ -556,6 +560,7 @@ with
556560
SuggestUseAutoProperty = None
557561
EnsureTailCallDiagnosticsInRecursiveFunctions = None
558562
FavourAsKeyword = None
563+
FavourNestedFunctions = None
559564
}
560565

561566
// fsharplint:enable RecordFieldNames
@@ -714,6 +719,7 @@ let flattenConfig (config:Configuration) =
714719
config.SuggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule)
715720
config.EnsureTailCallDiagnosticsInRecursiveFunctions |> Option.bind (constructRuleIfEnabled EnsureTailCallDiagnosticsInRecursiveFunctions.rule)
716721
config.FavourAsKeyword |> Option.bind (constructRuleIfEnabled FavourAsKeyword.rule)
722+
config.FavourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule)
717723
|] |> Array.choose id
718724

719725
if config.NonPublicValuesNames.IsSome &&

src/FSharpLint.Core/fsharplint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
},
334334
"ensureTailCallDiagnosticsInRecursiveFunctions": { "enabled": false },
335335
"favourAsKeyword": { "enabled": true },
336+
"favourNestedFunctions": { "enabled": false },
336337
"hints": {
337338
"add": [
338339
"not (a = b) ===> a <> b",

0 commit comments

Comments
 (0)