Skip to content

Enable alias corrections #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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 @@ -257,50 +258,62 @@ public Hashtable GetPSSASettingsHashtable(

private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
{
return new Hashtable
var ruleConfigurations = new Hashtable
{
{"IncludeRules", new string[] {
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement"
{ "PSPlaceOpenBrace", new Hashtable {
{ "Enable", true },
{ "OnSameLine", OpenBraceOnSameLine },
{ "NewLineAfter", NewLineAfterOpenBrace },
{ "IgnoreOneLineBlock", IgnoreOneLineBlock }
}},
{"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},
{"PipelineIndentation", PipelineIndentationStyle },
{"Kind", insertSpaces ? "space" : "tab"}
}},
{"PSUseConsistentWhitespace", new Hashtable {
{"Enable", true},
{"CheckOpenBrace", WhitespaceBeforeOpenBrace},
{"CheckOpenParen", WhitespaceBeforeOpenParen},
{"CheckOperator", WhitespaceAroundOperator},
{"CheckSeparator", WhitespaceAfterSeparator},
{"CheckInnerBrace", WhitespaceInsideBrace},
{"CheckPipe", WhitespaceAroundPipe},
}},
{"PSAlignAssignmentStatement", new Hashtable {
{"Enable", true},
{"CheckHashtable", AlignPropertyValuePairs}
}},
{"PSUseCorrectCasing", new Hashtable {
{"Enable", UseCorrectCasing}
}},
}}
{ "PSPlaceCloseBrace", new Hashtable {
{ "Enable", true },
{ "NewLineAfter", NewLineAfterCloseBrace },
{ "IgnoreOneLineBlock", IgnoreOneLineBlock }
}},
{ "PSUseConsistentIndentation", new Hashtable {
{ "Enable", true },
{ "IndentationSize", tabSize },
{ "PipelineIndentation", PipelineIndentationStyle },
{ "Kind", insertSpaces ? "space" : "tab" }
}},
{ "PSUseConsistentWhitespace", new Hashtable {
{ "Enable", true },
{ "CheckOpenBrace", WhitespaceBeforeOpenBrace },
{ "CheckOpenParen", WhitespaceBeforeOpenParen },
{ "CheckOperator", WhitespaceAroundOperator },
{ "CheckSeparator", WhitespaceAfterSeparator },
{ "CheckInnerBrace", WhitespaceInsideBrace },
{ "CheckPipe", WhitespaceAroundPipe },
}},
{ "PSAlignAssignmentStatement", new Hashtable {
{ "Enable", true },
{ "CheckHashtable", AlignPropertyValuePairs }
}},
{ "PSUseCorrectCasing", new Hashtable {
{ "Enable", UseCorrectCasing }
}},
};

if (AutoCorrectAliases)
{
// Empty hashtable required to activate the rule,
// since PSAvoidUsingCmdletAliases inherits from IScriptRule and not ConfigurableRule
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
}

return new Hashtable()
{
{ "IncludeRules", new string[] {
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement"
}},
{
"Rules", ruleConfigurations
}
};
}
}
Expand Down