Skip to content

Commit

Permalink
DisallowShadowing: docs and config
Browse files Browse the repository at this point in the history
Added config and docs for DisallowShadowing rule.
  • Loading branch information
webwarrior-ws committed Jan 9, 2024
1 parent 6432d8f commit d25dadd
Show file tree
Hide file tree
Showing 4 changed files with 38 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 @@ -124,3 +124,4 @@ The following rules can be specified for linting.
- [NestedFunctionNames (FL0081)](rules/FL0081.html)
- [UsedUnderscorePrefixedElements (FL0082)](rules/FL0082.html)
- [UnneededRecKeyword (FL0083)](rules/FL0083.html)
- [DisallowShadowing (FL0084)](rules/FL0084.html)
29 changes: 29 additions & 0 deletions docs/content/how-tos/rules/FL0084.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: FL0084
category: how-to
hide_menu: true
---

# DisallowShadowing (FL0084)

*Introduced in `0.23.8`*

## Cause

A variable or parameter shadows another one with the same name.

## Rationale

Sometimes shadowing can cause confusion.

## How To Fix

Rename varaible or parameter in question so it has unique name in its scope.

## Rule Settings

{
"disallowShadowing": {
"enabled": true
}
}
9 changes: 7 additions & 2 deletions src/FSharpLint.Core/Application/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ type ConventionsConfig =
favourReRaise:EnabledConfig option
favourConsistentThis:RuleConfig<FavourConsistentThis.Config> option
suggestUseAutoProperty:EnabledConfig option
usedUnderscorePrefixedElements:EnabledConfig option }
usedUnderscorePrefixedElements:EnabledConfig option
disallowShadowing:EnabledConfig option }
with
member this.Flatten() =
[|
Expand All @@ -348,6 +349,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.disallowShadowing |> Option.bind (constructRuleIfEnabled DisallowShadowing.rule) |> Option.toArray
|] |> Array.concat

type TypographyConfig =
Expand Down Expand Up @@ -469,7 +471,8 @@ type Configuration =
TrailingNewLineInFile:EnabledConfig option
NoTabCharacters:EnabledConfig option
NoPartialFunctions:RuleConfig<NoPartialFunctions.Config> option
SuggestUseAutoProperty:EnabledConfig option }
SuggestUseAutoProperty:EnabledConfig option
DisallowShadowing:EnabledConfig option }
with
static member Zero = {
Global = None
Expand Down Expand Up @@ -559,6 +562,7 @@ with
NoTabCharacters = None
NoPartialFunctions = None
SuggestUseAutoProperty = None
DisallowShadowing = None
}

// fsharplint:enable RecordFieldNames
Expand Down Expand Up @@ -711,6 +715,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.DisallowShadowing |> Option.bind (constructRuleIfEnabled DisallowShadowing.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 @@ -290,6 +290,7 @@
}
},
"suggestUseAutoProperty": { "enabled": false },
"disallowShadowing": { "enabled": false },
"avoidTooShortNames": { "enabled": false },
"asyncExceptionWithoutReturn": { "enabled": false },
"unneededRecKeyword": { "enabled": true },
Expand Down

0 comments on commit d25dadd

Please sign in to comment.