Skip to content

Commit 9eead58

Browse files
author
Kapil Borle
authored
Merge pull request PowerShell#493 from PowerShell/kapilmb/ignore-format-one-line
Add option to ignore formatting of one line constructs
2 parents 1d4cd4c + 66f75cc commit 9eead58

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

package.json

+5
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

+5
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

+3-1
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)