From d25daddcba32b754e0072481b5da258e7f5562b6 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Tue, 9 Jan 2024 10:32:02 +0100 Subject: [PATCH] DisallowShadowing: docs and config Added config and docs for DisallowShadowing rule. --- docs/content/how-tos/rule-configuration.md | 1 + docs/content/how-tos/rules/FL0084.md | 29 +++++++++++++++++++ .../Application/Configuration.fs | 9 ++++-- src/FSharpLint.Core/fsharplint.json | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 docs/content/how-tos/rules/FL0084.md diff --git a/docs/content/how-tos/rule-configuration.md b/docs/content/how-tos/rule-configuration.md index 41c276352..2405a2acf 100644 --- a/docs/content/how-tos/rule-configuration.md +++ b/docs/content/how-tos/rule-configuration.md @@ -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) diff --git a/docs/content/how-tos/rules/FL0084.md b/docs/content/how-tos/rules/FL0084.md new file mode 100644 index 000000000..19258a26e --- /dev/null +++ b/docs/content/how-tos/rules/FL0084.md @@ -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 + } + } diff --git a/src/FSharpLint.Core/Application/Configuration.fs b/src/FSharpLint.Core/Application/Configuration.fs index 20c30cc4c..534da1c2d 100644 --- a/src/FSharpLint.Core/Application/Configuration.fs +++ b/src/FSharpLint.Core/Application/Configuration.fs @@ -324,7 +324,8 @@ type ConventionsConfig = favourReRaise:EnabledConfig option favourConsistentThis:RuleConfig option suggestUseAutoProperty:EnabledConfig option - usedUnderscorePrefixedElements:EnabledConfig option } + usedUnderscorePrefixedElements:EnabledConfig option + disallowShadowing:EnabledConfig option } with member this.Flatten() = [| @@ -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 = @@ -469,7 +471,8 @@ type Configuration = TrailingNewLineInFile:EnabledConfig option NoTabCharacters:EnabledConfig option NoPartialFunctions:RuleConfig option - SuggestUseAutoProperty:EnabledConfig option } + SuggestUseAutoProperty:EnabledConfig option + DisallowShadowing:EnabledConfig option } with static member Zero = { Global = None @@ -559,6 +562,7 @@ with NoTabCharacters = None NoPartialFunctions = None SuggestUseAutoProperty = None + DisallowShadowing = None } // fsharplint:enable RecordFieldNames @@ -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 && diff --git a/src/FSharpLint.Core/fsharplint.json b/src/FSharpLint.Core/fsharplint.json index 70156d75e..cb3574c7f 100644 --- a/src/FSharpLint.Core/fsharplint.json +++ b/src/FSharpLint.Core/fsharplint.json @@ -290,6 +290,7 @@ } }, "suggestUseAutoProperty": { "enabled": false }, + "disallowShadowing": { "enabled": false }, "avoidTooShortNames": { "enabled": false }, "asyncExceptionWithoutReturn": { "enabled": false }, "unneededRecKeyword": { "enabled": true },