Skip to content

Commit 0de6e84

Browse files
committed
FavourNestedFunctions: hook cfg & add docs
Updated Configuration.fs and fsharplint.json to include FavourNestedFunctions rule. Added docs.
1 parent 39bc94a commit 0de6e84

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
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 & 3 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 =
@@ -459,9 +461,10 @@ type Configuration =
459461
TrailingNewLineInFile:EnabledConfig option
460462
NoTabCharacters:EnabledConfig option
461463
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
462-
SuggestUseAutoProperty:EnabledConfig option
463464
EnsureTailCallDiagnosticsInRecursiveFunctions:EnabledConfig option
464-
FavourAsKeyword:EnabledConfig option }
465+
FavourAsKeyword:EnabledConfig option
466+
SuggestUseAutoProperty:EnabledConfig option
467+
FavourNestedFunctions:EnabledConfig option }
465468
with
466469
static member Zero = {
467470
Global = None
@@ -556,6 +559,7 @@ with
556559
SuggestUseAutoProperty = None
557560
EnsureTailCallDiagnosticsInRecursiveFunctions = None
558561
FavourAsKeyword = None
562+
FavourNestedFunctions = None
559563
}
560564

561565
// fsharplint:enable RecordFieldNames
@@ -714,6 +718,7 @@ let flattenConfig (config:Configuration) =
714718
config.SuggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule)
715719
config.EnsureTailCallDiagnosticsInRecursiveFunctions |> Option.bind (constructRuleIfEnabled EnsureTailCallDiagnosticsInRecursiveFunctions.rule)
716720
config.FavourAsKeyword |> Option.bind (constructRuleIfEnabled FavourAsKeyword.rule)
721+
config.FavourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule)
717722
|] |> Array.choose id
718723

719724
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)