Skip to content

Commit

Permalink
Backport #1023 and #1021 (#1024)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rjmholt authored and TylerLeonhardt committed Sep 17, 2019
1 parent fbecd3f commit 4710355
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"PSScriptAnalyzer":{
"MinimumVersion":"1.6",
"MinimumVersion":"1.18.2",
"MaximumVersion":"1.99",
"AllowPrerelease":false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,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 @@ -248,50 +249,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},
{"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}
}},
}}
{
"Rules", ruleConfigurations
},
};
}
}
Expand Down

0 comments on commit 4710355

Please sign in to comment.