Skip to content

Add formatting option to align property value pairs #693

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 4 commits into from
Apr 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@
"default": true,
"description": "Does not reformat one-line code blocks, such as \"if (...) {...} else {...}\"."
},
"powershell.codeFormatting.alignPropertyValuePairs": {
"type": "boolean",
"default": true,
"description": "Align assignment statements in a hashtable."
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expand this description to include "or a DSC configuration"

Copy link
Author

Choose a reason for hiding this comment

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

fixed!

},
"powershell.integratedConsole.showOnStartup": {
"type": "boolean",
"default": true,
Expand Down
7 changes: 6 additions & 1 deletion src/features/DocumentFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class PSDocumentFormattingEditProvider implements
"PSPlaceCloseBrace",
"PSPlaceOpenBrace",
"PSUseConsistentWhitespace",
"PSUseConsistentIndentation"];
"PSUseConsistentIndentation",
"PSAlignAssignmentStatement"]

// Allows edits to be undone and redone is a single step.
// It is usefuld to have undo stops after every edit while debugging
Expand Down Expand Up @@ -426,6 +427,10 @@ class PSDocumentFormattingEditProvider implements
ruleSettings["CheckSeparator"] = psSettings.codeFormatting.whitespaceAfterSeparator;
break;

case "PSAlignAssignmentStatement":
ruleSettings["CheckHashtable"] = psSettings.codeFormatting.alignPropertyValuePairs;
break;

default:
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ICodeFormattingSettings {
whitespaceAroundOperator: boolean;
whitespaceAfterSeparator: boolean;
ignoreOneLineBlock: boolean;
alignPropertyValuePairs: boolean;
}

export interface IScriptAnalysisSettings {
Expand Down Expand Up @@ -71,7 +72,8 @@ export function load(myPluginId: string): ISettings {
whitespaceBeforeOpenParen: true,
whitespaceAroundOperator: true,
whitespaceAfterSeparator: true,
ignoreOneLineBlock: true
ignoreOneLineBlock: true,
alignPropertyValuePairs: true
};

let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
Expand Down