Skip to content

Commit 501528b

Browse files
bergmeisterrjmholt
authored andcommitted
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) (PowerShell#1021)
1 parent 161a3ed commit 501528b

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

+44-30
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
168168
}
169169
}
170170

171+
public bool AutoCorrectAliases { get; set; }
171172
public CodeFormattingPreset Preset { get; set; }
172173
public bool OpenBraceOnSameLine { get; set; }
173174
public bool NewLineAfterOpenBrace { get; set; }
@@ -223,44 +224,57 @@ public Hashtable GetPSSASettingsHashtable(
223224

224225
private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
225226
{
227+
var ruleConfigurations = new Hashtable {
228+
{"PSPlaceOpenBrace", new Hashtable {
229+
{"Enable", true},
230+
{"OnSameLine", OpenBraceOnSameLine},
231+
{"NewLineAfter", NewLineAfterOpenBrace},
232+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
233+
}},
234+
{"PSPlaceCloseBrace", new Hashtable {
235+
{"Enable", true},
236+
{"NewLineAfter", NewLineAfterCloseBrace},
237+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
238+
}},
239+
{"PSUseConsistentIndentation", new Hashtable {
240+
{"Enable", true},
241+
{"IndentationSize", tabSize},
242+
{"Kind", insertSpaces ? "space" : "tab"}
243+
}},
244+
{"PSUseConsistentWhitespace", new Hashtable {
245+
{"Enable", true},
246+
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
247+
{"CheckOpenParen", WhitespaceBeforeOpenParen},
248+
{"CheckOperator", WhitespaceAroundOperator},
249+
{"CheckSeparator", WhitespaceAfterSeparator}
250+
}},
251+
{"PSAlignAssignmentStatement", new Hashtable {
252+
{"Enable", true},
253+
{"CheckHashtable", AlignPropertyValuePairs}
254+
}},
255+
{"PSUseCorrectCasing", new Hashtable {
256+
{"Enable", UseCorrectCasing}
257+
}},
258+
};
259+
260+
if (AutoCorrectAliases)
261+
{
262+
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
263+
}
264+
226265
return new Hashtable
227266
{
228267
{"IncludeRules", new string[] {
229268
"PSPlaceCloseBrace",
230269
"PSPlaceOpenBrace",
231270
"PSUseConsistentWhitespace",
232271
"PSUseConsistentIndentation",
233-
"PSAlignAssignmentStatement"
272+
"PSAlignAssignmentStatement",
273+
"PSAvoidUsingCmdletAliases",
234274
}},
235-
{"Rules", new Hashtable {
236-
{"PSPlaceOpenBrace", new Hashtable {
237-
{"Enable", true},
238-
{"OnSameLine", OpenBraceOnSameLine},
239-
{"NewLineAfter", NewLineAfterOpenBrace},
240-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
241-
}},
242-
{"PSPlaceCloseBrace", new Hashtable {
243-
{"Enable", true},
244-
{"NewLineAfter", NewLineAfterCloseBrace},
245-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
246-
}},
247-
{"PSUseConsistentIndentation", new Hashtable {
248-
{"Enable", true},
249-
{"IndentationSize", tabSize},
250-
{"Kind", insertSpaces ? "space" : "tab"}
251-
}},
252-
{"PSUseConsistentWhitespace", new Hashtable {
253-
{"Enable", true},
254-
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
255-
{"CheckOpenParen", WhitespaceBeforeOpenParen},
256-
{"CheckOperator", WhitespaceAroundOperator},
257-
{"CheckSeparator", WhitespaceAfterSeparator}
258-
}},
259-
{"PSAlignAssignmentStatement", new Hashtable {
260-
{"Enable", true},
261-
{"CheckHashtable", AlignPropertyValuePairs}
262-
}},
263-
}}
275+
{
276+
"Rules", ruleConfigurations
277+
},
264278
};
265279
}
266280
}

0 commit comments

Comments
 (0)