Skip to content

Commit 2857119

Browse files
committed
FavourNestedFunctions: update configuration and docs
Updated Configuration.fs and fsharplint.json to include FavourNestedFunctions rule. Added docs.
1 parent 62375ea commit 2857119

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@ The following rules can be specified for linting.
122122
- [SuggestUseAutoProperty (FL0079)](rules/FL0079.html)
123123
- [UnnestedFunctionNames (FL0080)](rules/FL0080.html)
124124
- [NestedFunctionNames (FL0081)](rules/FL0081.html)
125+
- [FavourNestedFunctions (FL0082)](rules/FL0082.html)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: FL0082
3+
category: how-to
4+
hide_menu: true
5+
---
6+
7+
# FavourNestedFunctions (FL0082)
8+
9+
*Introduced in `0.23.0`*
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ type ConventionsConfig =
322322
binding:BindingConfig option
323323
favourReRaise:EnabledConfig option
324324
favourConsistentThis:RuleConfig<FavourConsistentThis.Config> option
325-
suggestUseAutoProperty:EnabledConfig option}
325+
suggestUseAutoProperty:EnabledConfig option
326+
favourNestedFunctions:EnabledConfig option }
326327
with
327328
member this.Flatten() =
328329
[|
@@ -344,6 +345,7 @@ with
344345
this.numberOfItems |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
345346
this.binding |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
346347
this.suggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule) |> Option.toArray
348+
this.favourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule) |> Option.toArray
347349
|] |> Array.concat
348350

349351
type TypographyConfig =
@@ -463,7 +465,8 @@ type Configuration =
463465
TrailingNewLineInFile:EnabledConfig option
464466
NoTabCharacters:EnabledConfig option
465467
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
466-
SuggestUseAutoProperty:EnabledConfig option }
468+
SuggestUseAutoProperty:EnabledConfig option
469+
FavourNestedFunctions:EnabledConfig option }
467470
with
468471
static member Zero = {
469472
Global = None
@@ -551,6 +554,7 @@ with
551554
NoTabCharacters = None
552555
NoPartialFunctions = None
553556
SuggestUseAutoProperty = None
557+
FavourNestedFunctions = None
554558
}
555559

556560
// fsharplint:enable RecordFieldNames
@@ -701,6 +705,7 @@ let flattenConfig (config:Configuration) =
701705
config.TrailingNewLineInFile |> Option.bind (constructRuleIfEnabled TrailingNewLineInFile.rule)
702706
config.NoTabCharacters |> Option.bind (constructRuleIfEnabled NoTabCharacters.rule)
703707
config.NoPartialFunctions |> Option.bind (constructRuleWithConfig NoPartialFunctions.rule)
708+
config.FavourNestedFunctions |> Option.bind (constructRuleIfEnabled FavourNestedFunctions.rule)
704709
|] |> Array.choose id
705710

706711
if config.NonPublicValuesNames.IsSome &&

src/FSharpLint.Core/fsharplint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@
323323
"additionalPartials": []
324324
}
325325
},
326+
"favourNestedFunctions": { "enabled": false },
326327
"hints": {
327328
"add": [
328329
"not (a = b) ===> a <> b",

0 commit comments

Comments
 (0)