Skip to content

Commit 4aa3022

Browse files
author
Kapil Borle
committed
Add formatting options for whitespace style
1 parent 62c4b75 commit 4aa3022

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

package.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,29 @@
346346
"type": "boolean",
347347
"default": true,
348348
"description": "A new line must follow an open brace."
349+
},
350+
"powershell.codeFormatting.whitespaceBeforeOpenBrace": {
351+
"type": "boolean",
352+
"default": true,
353+
"description": "There must be a whitespace between a keyword and its associated scriptblock expression."
354+
},
355+
"powershell.codeFormatting.whitespaceBeforeOpenParen": {
356+
"type": "boolean",
357+
"default": true,
358+
"description": "There must be whitespace between an keyword (if, elseif, while, switch, etc) and its associated conditional expression."
359+
},
360+
"powershell.codeFormatting.whitespaceAroundOperator": {
361+
"type": "boolean",
362+
"default": true,
363+
"description": "There must be whitespaces around both sides of a binary or assignment operator ('=', '+', '-', etc.)."
364+
},
365+
"powershell.codeFormatting.whitespaceAfterSeparator": {
366+
"type": "boolean",
367+
"default": true,
368+
"description": "There must be a whitespaces after a separator (',' and ';')."
349369
}
350370
}
351371
}
352372
},
353373
"private": true
354-
}
374+
}

src/features/DocumentFormatter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,11 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
335335
break;
336336

337337
case "PSUseWhitespace":
338-
ruleSettings["CheckOpenBrace"] = true;
339-
ruleSettings["CheckOpenParen"] = true;
340-
ruleSettings["CheckOperator"] = true;
338+
ruleSettings["CheckOpenBrace"] = psSettings.codeFormatting.whitespaceBeforeOpenBrace;
339+
ruleSettings["CheckOpenParen"] = psSettings.codeFormatting.whitespaceBeforeOpenParen;
340+
ruleSettings["CheckOperator"] = psSettings.codeFormatting.whitespaceAroundOperator;
341+
ruleSettings["CheckSeparator"] = psSettings.codeFormatting.whitespaceAfterSeparator;
342+
break;
341343

342344
default:
343345
break;

src/settings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import vscode = require('vscode');
99
export interface ICodeFormattingSettings {
1010
openBraceOnSameLine: boolean;
1111
newLineAfterOpenBrace: boolean;
12+
whitespaceBeforeOpenBrace: boolean;
13+
whitespaceBeforeOpenParen: boolean;
14+
whitespaceAroundOperator: boolean;
15+
whitespaceAfterSeparator: boolean;
1216
}
1317

1418
export interface IScriptAnalysisSettings {
@@ -50,7 +54,11 @@ export function load(myPluginId: string): ISettings {
5054

5155
let defaultCodeFormattingSettings: ICodeFormattingSettings = {
5256
openBraceOnSameLine: true,
53-
newLineAfterOpenBrace: true
57+
newLineAfterOpenBrace: true,
58+
whitespaceBeforeOpenBrace: true,
59+
whitespaceBeforeOpenParen: true,
60+
whitespaceAroundOperator: true,
61+
whitespaceAfterSeparator: true
5462
};
5563

5664
return {

0 commit comments

Comments
 (0)