From 061effe771176a82660eaac21fcb586b2e644a83 Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Tue, 10 Sep 2019 04:07:42 +0100 Subject: [PATCH] Add AutoCorrectAliases setting (PR to be made in VS-Code repo as well) to add support for optionally correcting aliases as well (added in PSSA 1.18.2) (#1021) --- .../Server/LanguageServerSettings.cs | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs index 8ce27bcfb..369c5ee45 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs @@ -190,6 +190,7 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings) } } + public bool AutoCorrectAliases { get; set; } public CodeFormattingPreset Preset { get; set; } public bool OpenBraceOnSameLine { get; set; } public bool NewLineAfterOpenBrace { get; set; } @@ -249,16 +250,7 @@ public Hashtable GetPSSASettingsHashtable( private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces) { - return new Hashtable - { - {"IncludeRules", new string[] { - "PSPlaceCloseBrace", - "PSPlaceOpenBrace", - "PSUseConsistentWhitespace", - "PSUseConsistentIndentation", - "PSAlignAssignmentStatement" - }}, - {"Rules", new Hashtable { + var ruleConfigurations = new Hashtable { {"PSPlaceOpenBrace", new Hashtable { {"Enable", true}, {"OnSameLine", OpenBraceOnSameLine}, @@ -292,7 +284,25 @@ private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces) {"PSUseCorrectCasing", new Hashtable { {"Enable", UseCorrectCasing} }}, - }} + }; + if (AutoCorrectAliases) + { + ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable()); + } + + return new Hashtable + { + {"IncludeRules", new string[] { + "PSPlaceCloseBrace", + "PSPlaceOpenBrace", + "PSUseConsistentWhitespace", + "PSUseConsistentIndentation", + "PSAlignAssignmentStatement", + "PSAvoidUsingCmdletAliases", + }}, + { + "Rules", ruleConfigurations + }, }; } }