Skip to content

Commit 7821670

Browse files
author
Kapil Borle
authored
Merge pull request #693 from PowerShell/kapilmb/format-align-assignment
Add formatting option to align property value pairs
2 parents 6698b8a + 8cc49e1 commit 7821670

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@
408408
"default": true,
409409
"description": "Does not reformat one-line code blocks, such as \"if (...) {...} else {...}\"."
410410
},
411+
"powershell.codeFormatting.alignPropertyValuePairs": {
412+
"type": "boolean",
413+
"default": true,
414+
"description": "Align assignment statements in a hashtable or a DSC Configuration."
415+
},
411416
"powershell.integratedConsole.showOnStartup": {
412417
"type": "boolean",
413418
"default": true,

src/features/DocumentFormatter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class PSDocumentFormattingEditProvider implements
174174
"PSPlaceCloseBrace",
175175
"PSPlaceOpenBrace",
176176
"PSUseConsistentWhitespace",
177-
"PSUseConsistentIndentation"];
177+
"PSUseConsistentIndentation",
178+
"PSAlignAssignmentStatement"]
178179

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

430+
case "PSAlignAssignmentStatement":
431+
ruleSettings["CheckHashtable"] = psSettings.codeFormatting.alignPropertyValuePairs;
432+
break;
433+
429434
default:
430435
break;
431436
}

src/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ICodeFormattingSettings {
1515
whitespaceAroundOperator: boolean;
1616
whitespaceAfterSeparator: boolean;
1717
ignoreOneLineBlock: boolean;
18+
alignPropertyValuePairs: boolean;
1819
}
1920

2021
export interface IScriptAnalysisSettings {
@@ -71,7 +72,8 @@ export function load(myPluginId: string): ISettings {
7172
whitespaceBeforeOpenParen: true,
7273
whitespaceAroundOperator: true,
7374
whitespaceAfterSeparator: true,
74-
ignoreOneLineBlock: true
75+
ignoreOneLineBlock: true,
76+
alignPropertyValuePairs: true
7577
};
7678

7779
let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {

0 commit comments

Comments
 (0)