From 921bcb668c1014c9826525014d2b2cd83a7e0a9e Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Thu, 20 Apr 2017 19:14:00 -0700 Subject: [PATCH 1/4] Add option to align assignment statements in hashtable --- package.json | 5 +++++ src/settings.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ab805873be..ee4f11fb23 100644 --- a/package.json +++ b/package.json @@ -408,6 +408,11 @@ "default": true, "description": "Does not reformat one-line code blocks, such as \"if (...) {...} else {...}\"." }, + "powershell.codeFormatting.alignAssignmentsInHashtable": { + "type": "boolean", + "default": true, + "description": "Align assignment statements in a hashtable." + }, "powershell.integratedConsole.showOnStartup": { "type": "boolean", "default": true, diff --git a/src/settings.ts b/src/settings.ts index 68501c5317..891c1cfef9 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,6 +15,7 @@ export interface ICodeFormattingSettings { whitespaceAroundOperator: boolean; whitespaceAfterSeparator: boolean; ignoreOneLineBlock: boolean; + alignAssignmentsInHashtable: boolean; } export interface IScriptAnalysisSettings { @@ -71,7 +72,8 @@ export function load(myPluginId: string): ISettings { whitespaceBeforeOpenParen: true, whitespaceAroundOperator: true, whitespaceAfterSeparator: true, - ignoreOneLineBlock: true + ignoreOneLineBlock: true, + alignAssignmentsInHashtable: true }; let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = { From d1145d3e891986e984159b72fb3c662cc85b0c22 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Thu, 20 Apr 2017 19:14:46 -0700 Subject: [PATCH 2/4] Add AlignAssignmentStatement rule to code formatter --- src/features/DocumentFormatter.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/features/DocumentFormatter.ts b/src/features/DocumentFormatter.ts index 17e4628796..d9e239a386 100644 --- a/src/features/DocumentFormatter.ts +++ b/src/features/DocumentFormatter.ts @@ -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 @@ -426,6 +427,10 @@ class PSDocumentFormattingEditProvider implements ruleSettings["CheckSeparator"] = psSettings.codeFormatting.whitespaceAfterSeparator; break; + case "PSAlignAssignmentStatement": + ruleSettings["CheckHashtable"] = psSettings.codeFormatting.alignAssignmentsInHashtable; + break; + default: break; } From 37eb4a828e0305f059aafce6ec05eaf9e5b6835e Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Fri, 21 Apr 2017 11:48:42 -0700 Subject: [PATCH 3/4] Change alignAssignmentsInHashtable to alignPropertyValuePairs The property value pairs defined in a DSC configuration are in fact key value pairs of a hashtable. This can be easily verified by parsing a DSC configuration and examining the AST nodes. However, while naming they are referred to as part of DSC configuration and not a hashtable. Therefore the option name "alignAssignmentsInHashtable" would sound somewhat misleading to users, if enabling the option would format even the property value pairs in a DSC configuration. --- package.json | 2 +- src/features/DocumentFormatter.ts | 2 +- src/settings.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ee4f11fb23..86c9a326f5 100644 --- a/package.json +++ b/package.json @@ -408,7 +408,7 @@ "default": true, "description": "Does not reformat one-line code blocks, such as \"if (...) {...} else {...}\"." }, - "powershell.codeFormatting.alignAssignmentsInHashtable": { + "powershell.codeFormatting.alignPropertyValuePairs": { "type": "boolean", "default": true, "description": "Align assignment statements in a hashtable." diff --git a/src/features/DocumentFormatter.ts b/src/features/DocumentFormatter.ts index d9e239a386..18855ceb95 100644 --- a/src/features/DocumentFormatter.ts +++ b/src/features/DocumentFormatter.ts @@ -428,7 +428,7 @@ class PSDocumentFormattingEditProvider implements break; case "PSAlignAssignmentStatement": - ruleSettings["CheckHashtable"] = psSettings.codeFormatting.alignAssignmentsInHashtable; + ruleSettings["CheckHashtable"] = psSettings.codeFormatting.alignPropertyValuePairs; break; default: diff --git a/src/settings.ts b/src/settings.ts index 891c1cfef9..091cedc794 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -15,7 +15,7 @@ export interface ICodeFormattingSettings { whitespaceAroundOperator: boolean; whitespaceAfterSeparator: boolean; ignoreOneLineBlock: boolean; - alignAssignmentsInHashtable: boolean; + alignPropertyValuePairs: boolean; } export interface IScriptAnalysisSettings { @@ -73,7 +73,7 @@ export function load(myPluginId: string): ISettings { whitespaceAroundOperator: true, whitespaceAfterSeparator: true, ignoreOneLineBlock: true, - alignAssignmentsInHashtable: true + alignPropertyValuePairs: true }; let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = { From 8cc49e1c25c31aa219ebcb9c125c0914287d8cd9 Mon Sep 17 00:00:00 2001 From: Kapil Borle Date: Fri, 21 Apr 2017 17:14:10 -0700 Subject: [PATCH 4/4] Update alignPropertyValuePairs description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 86c9a326f5..c29dbb81dc 100644 --- a/package.json +++ b/package.json @@ -411,7 +411,7 @@ "powershell.codeFormatting.alignPropertyValuePairs": { "type": "boolean", "default": true, - "description": "Align assignment statements in a hashtable." + "description": "Align assignment statements in a hashtable or a DSC Configuration." }, "powershell.integratedConsole.showOnStartup": { "type": "boolean",