Skip to content

Commit d25dadd

Browse files
committed
DisallowShadowing: docs and config
Added config and docs for DisallowShadowing rule.
1 parent 6432d8f commit d25dadd

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ The following rules can be specified for linting.
124124
- [NestedFunctionNames (FL0081)](rules/FL0081.html)
125125
- [UsedUnderscorePrefixedElements (FL0082)](rules/FL0082.html)
126126
- [UnneededRecKeyword (FL0083)](rules/FL0083.html)
127+
- [DisallowShadowing (FL0084)](rules/FL0084.html)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: FL0084
3+
category: how-to
4+
hide_menu: true
5+
---
6+
7+
# DisallowShadowing (FL0084)
8+
9+
*Introduced in `0.23.8`*
10+
11+
## Cause
12+
13+
A variable or parameter shadows another one with the same name.
14+
15+
## Rationale
16+
17+
Sometimes shadowing can cause confusion.
18+
19+
## How To Fix
20+
21+
Rename varaible or parameter in question so it has unique name in its scope.
22+
23+
## Rule Settings
24+
25+
{
26+
"disallowShadowing": {
27+
"enabled": true
28+
}
29+
}

src/FSharpLint.Core/Application/Configuration.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ type ConventionsConfig =
324324
favourReRaise:EnabledConfig option
325325
favourConsistentThis:RuleConfig<FavourConsistentThis.Config> option
326326
suggestUseAutoProperty:EnabledConfig option
327-
usedUnderscorePrefixedElements:EnabledConfig option }
327+
usedUnderscorePrefixedElements:EnabledConfig option
328+
disallowShadowing:EnabledConfig option }
328329
with
329330
member this.Flatten() =
330331
[|
@@ -348,6 +349,7 @@ with
348349
this.numberOfItems |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
349350
this.binding |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat
350351
this.suggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule) |> Option.toArray
352+
this.disallowShadowing |> Option.bind (constructRuleIfEnabled DisallowShadowing.rule) |> Option.toArray
351353
|] |> Array.concat
352354

353355
type TypographyConfig =
@@ -469,7 +471,8 @@ type Configuration =
469471
TrailingNewLineInFile:EnabledConfig option
470472
NoTabCharacters:EnabledConfig option
471473
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
472-
SuggestUseAutoProperty:EnabledConfig option }
474+
SuggestUseAutoProperty:EnabledConfig option
475+
DisallowShadowing:EnabledConfig option }
473476
with
474477
static member Zero = {
475478
Global = None
@@ -559,6 +562,7 @@ with
559562
NoTabCharacters = None
560563
NoPartialFunctions = None
561564
SuggestUseAutoProperty = None
565+
DisallowShadowing = None
562566
}
563567

564568
// fsharplint:enable RecordFieldNames
@@ -711,6 +715,7 @@ let flattenConfig (config:Configuration) =
711715
config.TrailingNewLineInFile |> Option.bind (constructRuleIfEnabled TrailingNewLineInFile.rule)
712716
config.NoTabCharacters |> Option.bind (constructRuleIfEnabled NoTabCharacters.rule)
713717
config.NoPartialFunctions |> Option.bind (constructRuleWithConfig NoPartialFunctions.rule)
718+
config.DisallowShadowing |> Option.bind (constructRuleIfEnabled DisallowShadowing.rule)
714719
|] |> Array.choose id
715720

716721
if config.NonPublicValuesNames.IsSome &&

src/FSharpLint.Core/fsharplint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
}
291291
},
292292
"suggestUseAutoProperty": { "enabled": false },
293+
"disallowShadowing": { "enabled": false },
293294
"avoidTooShortNames": { "enabled": false },
294295
"asyncExceptionWithoutReturn": { "enabled": false },
295296
"unneededRecKeyword": { "enabled": true },

0 commit comments

Comments
 (0)