Skip to content

Commit d8156e8

Browse files
rjmholtTylerLeonhardt
authored andcommitted
Enable alias corrections (#1053)
1 parent 06b9040 commit d8156e8

File tree

1 file changed

+55
-42
lines changed

1 file changed

+55
-42
lines changed

src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
198198
}
199199
}
200200

201+
public bool AutoCorrectAliases { get; set; }
201202
public CodeFormattingPreset Preset { get; set; }
202203
public bool OpenBraceOnSameLine { get; set; }
203204
public bool NewLineAfterOpenBrace { get; set; }
@@ -257,50 +258,62 @@ public Hashtable GetPSSASettingsHashtable(
257258

258259
private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
259260
{
260-
return new Hashtable
261+
var ruleConfigurations = new Hashtable
261262
{
262-
{"IncludeRules", new string[] {
263-
"PSPlaceCloseBrace",
264-
"PSPlaceOpenBrace",
265-
"PSUseConsistentWhitespace",
266-
"PSUseConsistentIndentation",
267-
"PSAlignAssignmentStatement"
263+
{ "PSPlaceOpenBrace", new Hashtable {
264+
{ "Enable", true },
265+
{ "OnSameLine", OpenBraceOnSameLine },
266+
{ "NewLineAfter", NewLineAfterOpenBrace },
267+
{ "IgnoreOneLineBlock", IgnoreOneLineBlock }
268268
}},
269-
{"Rules", new Hashtable {
270-
{"PSPlaceOpenBrace", new Hashtable {
271-
{"Enable", true},
272-
{"OnSameLine", OpenBraceOnSameLine},
273-
{"NewLineAfter", NewLineAfterOpenBrace},
274-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
275-
}},
276-
{"PSPlaceCloseBrace", new Hashtable {
277-
{"Enable", true},
278-
{"NewLineAfter", NewLineAfterCloseBrace},
279-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
280-
}},
281-
{"PSUseConsistentIndentation", new Hashtable {
282-
{"Enable", true},
283-
{"IndentationSize", tabSize},
284-
{"PipelineIndentation", PipelineIndentationStyle },
285-
{"Kind", insertSpaces ? "space" : "tab"}
286-
}},
287-
{"PSUseConsistentWhitespace", new Hashtable {
288-
{"Enable", true},
289-
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
290-
{"CheckOpenParen", WhitespaceBeforeOpenParen},
291-
{"CheckOperator", WhitespaceAroundOperator},
292-
{"CheckSeparator", WhitespaceAfterSeparator},
293-
{"CheckInnerBrace", WhitespaceInsideBrace},
294-
{"CheckPipe", WhitespaceAroundPipe},
295-
}},
296-
{"PSAlignAssignmentStatement", new Hashtable {
297-
{"Enable", true},
298-
{"CheckHashtable", AlignPropertyValuePairs}
299-
}},
300-
{"PSUseCorrectCasing", new Hashtable {
301-
{"Enable", UseCorrectCasing}
302-
}},
303-
}}
269+
{ "PSPlaceCloseBrace", new Hashtable {
270+
{ "Enable", true },
271+
{ "NewLineAfter", NewLineAfterCloseBrace },
272+
{ "IgnoreOneLineBlock", IgnoreOneLineBlock }
273+
}},
274+
{ "PSUseConsistentIndentation", new Hashtable {
275+
{ "Enable", true },
276+
{ "IndentationSize", tabSize },
277+
{ "PipelineIndentation", PipelineIndentationStyle },
278+
{ "Kind", insertSpaces ? "space" : "tab" }
279+
}},
280+
{ "PSUseConsistentWhitespace", new Hashtable {
281+
{ "Enable", true },
282+
{ "CheckOpenBrace", WhitespaceBeforeOpenBrace },
283+
{ "CheckOpenParen", WhitespaceBeforeOpenParen },
284+
{ "CheckOperator", WhitespaceAroundOperator },
285+
{ "CheckSeparator", WhitespaceAfterSeparator },
286+
{ "CheckInnerBrace", WhitespaceInsideBrace },
287+
{ "CheckPipe", WhitespaceAroundPipe },
288+
}},
289+
{ "PSAlignAssignmentStatement", new Hashtable {
290+
{ "Enable", true },
291+
{ "CheckHashtable", AlignPropertyValuePairs }
292+
}},
293+
{ "PSUseCorrectCasing", new Hashtable {
294+
{ "Enable", UseCorrectCasing }
295+
}},
296+
};
297+
298+
if (AutoCorrectAliases)
299+
{
300+
// Empty hashtable required to activate the rule,
301+
// since PSAvoidUsingCmdletAliases inherits from IScriptRule and not ConfigurableRule
302+
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
303+
}
304+
305+
return new Hashtable()
306+
{
307+
{ "IncludeRules", new string[] {
308+
"PSPlaceCloseBrace",
309+
"PSPlaceOpenBrace",
310+
"PSUseConsistentWhitespace",
311+
"PSUseConsistentIndentation",
312+
"PSAlignAssignmentStatement"
313+
}},
314+
{
315+
"Rules", ruleConfigurations
316+
}
304317
};
305318
}
306319
}

0 commit comments

Comments
 (0)