Skip to content

Commit ca7e67a

Browse files
author
Kapil Borle
committed
Add code formatting switch to ignore one line blocks
The user can set powershell.codeFormatting.ignoreOneLineBlock to true to ignore formatting of one line constructs, e.g., * if ($true) {...} else {...} * white(Test-Something) {...}
1 parent 10fa9d0 commit ca7e67a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@
366366
"type": "boolean",
367367
"default": true,
368368
"description": "There must be a whitespaces after a separator (',' and ';')."
369+
},
370+
"powershell.codeFormatting.ignoreOneLineBlock": {
371+
"type": "boolean",
372+
"default": true,
373+
"description": "Ignore blocks of code on one line. For example, if true, the braces in \"if (...) {...} else {...}\", will not be formatted."
369374
}
370375
}
371376
}

src/features/DocumentFormatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
328328
case "PSPlaceOpenBrace":
329329
ruleSettings["OnSameLine"] = psSettings.codeFormatting.openBraceOnSameLine;
330330
ruleSettings["NewLineAfter"] = psSettings.codeFormatting.newLineAfterOpenBrace;
331+
ruleSettings["ignoreOneLineBlock"] = psSettings.codeFormatting.ignoreOneLineBlock;
332+
break;
333+
334+
case "PSPlaceCloseBrace":
335+
ruleSettings["ignoreOneLineBlock"] = psSettings.codeFormatting.ignoreOneLineBlock;
331336
break;
332337

333338
case "PSUseConsistentIndentation":

src/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ICodeFormattingSettings {
1313
whitespaceBeforeOpenParen: boolean;
1414
whitespaceAroundOperator: boolean;
1515
whitespaceAfterSeparator: boolean;
16+
ignoreOneLineBlock: boolean;
1617
}
1718

1819
export interface IScriptAnalysisSettings {
@@ -58,7 +59,8 @@ export function load(myPluginId: string): ISettings {
5859
whitespaceBeforeOpenBrace: true,
5960
whitespaceBeforeOpenParen: true,
6061
whitespaceAroundOperator: true,
61-
whitespaceAfterSeparator: true
62+
whitespaceAfterSeparator: true,
63+
ignoreOneLineBlock: true
6264
};
6365

6466
return {

0 commit comments

Comments
 (0)