Skip to content

Commit

Permalink
Add AutoCorrectAliases setting (PR to be made in VS-Code repo as well…
Browse files Browse the repository at this point in the history
…) to add support for optionally correcting aliases as well (added in PSSA 1.18.2) (PowerShell#1021)
  • Loading branch information
bergmeister authored and rjmholt committed Sep 10, 2019
1 parent 161a3ed commit 501528b
Showing 1 changed file with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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; }
Expand Down Expand Up @@ -223,44 +224,57 @@ public Hashtable GetPSSASettingsHashtable(

private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
{
var ruleConfigurations = new Hashtable {
{"PSPlaceOpenBrace", new Hashtable {
{"Enable", true},
{"OnSameLine", OpenBraceOnSameLine},
{"NewLineAfter", NewLineAfterOpenBrace},
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
}},
{"PSPlaceCloseBrace", new Hashtable {
{"Enable", true},
{"NewLineAfter", NewLineAfterCloseBrace},
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
}},
{"PSUseConsistentIndentation", new Hashtable {
{"Enable", true},
{"IndentationSize", tabSize},
{"Kind", insertSpaces ? "space" : "tab"}
}},
{"PSUseConsistentWhitespace", new Hashtable {
{"Enable", true},
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
{"CheckOpenParen", WhitespaceBeforeOpenParen},
{"CheckOperator", WhitespaceAroundOperator},
{"CheckSeparator", WhitespaceAfterSeparator}
}},
{"PSAlignAssignmentStatement", new Hashtable {
{"Enable", true},
{"CheckHashtable", AlignPropertyValuePairs}
}},
{"PSUseCorrectCasing", new Hashtable {
{"Enable", UseCorrectCasing}
}},
};

if (AutoCorrectAliases)
{
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
}

return new Hashtable
{
{"IncludeRules", new string[] {
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement"
"PSAlignAssignmentStatement",
"PSAvoidUsingCmdletAliases",
}},
{"Rules", new Hashtable {
{"PSPlaceOpenBrace", new Hashtable {
{"Enable", true},
{"OnSameLine", OpenBraceOnSameLine},
{"NewLineAfter", NewLineAfterOpenBrace},
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
}},
{"PSPlaceCloseBrace", new Hashtable {
{"Enable", true},
{"NewLineAfter", NewLineAfterCloseBrace},
{"IgnoreOneLineBlock", IgnoreOneLineBlock}
}},
{"PSUseConsistentIndentation", new Hashtable {
{"Enable", true},
{"IndentationSize", tabSize},
{"Kind", insertSpaces ? "space" : "tab"}
}},
{"PSUseConsistentWhitespace", new Hashtable {
{"Enable", true},
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
{"CheckOpenParen", WhitespaceBeforeOpenParen},
{"CheckOperator", WhitespaceAroundOperator},
{"CheckSeparator", WhitespaceAfterSeparator}
}},
{"PSAlignAssignmentStatement", new Hashtable {
{"Enable", true},
{"CheckHashtable", AlignPropertyValuePairs}
}},
}}
{
"Rules", ruleConfigurations
},
};
}
}
Expand Down

0 comments on commit 501528b

Please sign in to comment.