Skip to content
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

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

Merged
merged 1 commit into from
Sep 10, 2019
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 @@ -190,6 +190,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 @@ -249,16 +250,7 @@ public Hashtable GetPSSASettingsHashtable(

private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
{
return new Hashtable
{
{"IncludeRules", new string[] {
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement"
}},
{"Rules", new Hashtable {
var ruleConfigurations = new Hashtable {
{"PSPlaceOpenBrace", new Hashtable {
{"Enable", true},
{"OnSameLine", OpenBraceOnSameLine},
Expand Down Expand Up @@ -292,7 +284,25 @@ private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
{"PSUseCorrectCasing", new Hashtable {
{"Enable", UseCorrectCasing}
}},
}}
};
if (AutoCorrectAliases)
{
ruleConfigurations.Add("PSAvoidUsingCmdletAliases", new Hashtable());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current pattern seems to always include the rule entry and set Enable to the boolean given. Is there a reason that shouldn't be done here?

Also, does this need to set Enable = true in the hashtable body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PSAvoidUsingCmdletAliases is a script analysis rule that inherits only from IScriptRule (see here). Formatting rules typically inherit from ConfigurableRule, which is what makes them have the Enable property. This is just the API of this specific rule, therefore although it would be nice to have them all consistent, I don't think we could even change that in PSSA without breaking people that use the PSAvoidUsingCmdletAliases for code analysis in their setting files.

}

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