Skip to content

Commit 4710355

Browse files
rjmholtTylerLeonhardt
authored andcommitted
Backport #1023 and #1021 (#1024)
* 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) * Update PSSA version
1 parent fbecd3f commit 4710355

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

modules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"PSScriptAnalyzer":{
3-
"MinimumVersion":"1.6",
3+
"MinimumVersion":"1.18.2",
44
"MaximumVersion":"1.99",
55
"AllowPrerelease":false
66
},

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
189189
}
190190
}
191191

192+
public bool AutoCorrectAliases { get; set; }
192193
public CodeFormattingPreset Preset { get; set; }
193194
public bool OpenBraceOnSameLine { get; set; }
194195
public bool NewLineAfterOpenBrace { get; set; }
@@ -248,50 +249,57 @@ public Hashtable GetPSSASettingsHashtable(
248249

249250
private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
250251
{
252+
var ruleConfigurations = new Hashtable {
253+
{"PSPlaceOpenBrace", new Hashtable {
254+
{"Enable", true},
255+
{"OnSameLine", OpenBraceOnSameLine},
256+
{"NewLineAfter", NewLineAfterOpenBrace},
257+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
258+
}},
259+
{"PSPlaceCloseBrace", new Hashtable {
260+
{"Enable", true},
261+
{"NewLineAfter", NewLineAfterCloseBrace},
262+
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
263+
}},
264+
{"PSUseConsistentIndentation", new Hashtable {
265+
{"Enable", true},
266+
{"IndentationSize", tabSize},
267+
{"Kind", insertSpaces ? "space" : "tab"}
268+
}},
269+
{"PSUseConsistentWhitespace", new Hashtable {
270+
{"Enable", true},
271+
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
272+
{"CheckOpenParen", WhitespaceBeforeOpenParen},
273+
{"CheckOperator", WhitespaceAroundOperator},
274+
{"CheckSeparator", WhitespaceAfterSeparator}
275+
}},
276+
{"PSAlignAssignmentStatement", new Hashtable {
277+
{"Enable", true},
278+
{"CheckHashtable", AlignPropertyValuePairs}
279+
}},
280+
{"PSUseCorrectCasing", new Hashtable {
281+
{"Enable", UseCorrectCasing}
282+
}},
283+
};
284+
285+
if (AutoCorrectAliases)
286+
{
287+
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
288+
}
289+
251290
return new Hashtable
252291
{
253292
{"IncludeRules", new string[] {
254293
"PSPlaceCloseBrace",
255294
"PSPlaceOpenBrace",
256295
"PSUseConsistentWhitespace",
257296
"PSUseConsistentIndentation",
258-
"PSAlignAssignmentStatement"
297+
"PSAlignAssignmentStatement",
298+
"PSAvoidUsingCmdletAliases",
259299
}},
260-
{"Rules", new Hashtable {
261-
{"PSPlaceOpenBrace", new Hashtable {
262-
{"Enable", true},
263-
{"OnSameLine", OpenBraceOnSameLine},
264-
{"NewLineAfter", NewLineAfterOpenBrace},
265-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
266-
}},
267-
{"PSPlaceCloseBrace", new Hashtable {
268-
{"Enable", true},
269-
{"NewLineAfter", NewLineAfterCloseBrace},
270-
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
271-
}},
272-
{"PSUseConsistentIndentation", new Hashtable {
273-
{"Enable", true},
274-
{"IndentationSize", tabSize},
275-
{"PipelineIndentation", PipelineIndentationStyle },
276-
{"Kind", insertSpaces ? "space" : "tab"}
277-
}},
278-
{"PSUseConsistentWhitespace", new Hashtable {
279-
{"Enable", true},
280-
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
281-
{"CheckOpenParen", WhitespaceBeforeOpenParen},
282-
{"CheckOperator", WhitespaceAroundOperator},
283-
{"CheckSeparator", WhitespaceAfterSeparator},
284-
{"CheckInnerBrace", WhitespaceInsideBrace},
285-
{"CheckPipe", WhitespaceAroundPipe},
286-
}},
287-
{"PSAlignAssignmentStatement", new Hashtable {
288-
{"Enable", true},
289-
{"CheckHashtable", AlignPropertyValuePairs}
290-
}},
291-
{"PSUseCorrectCasing", new Hashtable {
292-
{"Enable", UseCorrectCasing}
293-
}},
294-
}}
300+
{
301+
"Rules", ruleConfigurations
302+
},
295303
};
296304
}
297305
}

0 commit comments

Comments
 (0)