From 5691c9a612f016e7fbeb347a636bc7effd9aa257 Mon Sep 17 00:00:00 2001 From: Yuting Chen Date: Wed, 6 May 2015 15:56:55 -0700 Subject: [PATCH 1/2] Added markdown for AvoidUsingWriteHost rule --- RuleDocumentation/AvoidUsingWriteHost.md | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 RuleDocumentation/AvoidUsingWriteHost.md diff --git a/RuleDocumentation/AvoidUsingWriteHost.md b/RuleDocumentation/AvoidUsingWriteHost.md new file mode 100644 index 000000000..7c8e46d74 --- /dev/null +++ b/RuleDocumentation/AvoidUsingWriteHost.md @@ -0,0 +1,37 @@ +#AvoidUsingWriteHost +**Severity Level: Warning** + + +##Description + +It is generally accepted that you should never use Write-Host to create any script output whatsoever, unless your script (or function, or whatever) uses the Show verb (as in, Show-Performance). That verb explicitly means “show on the screen, with no other possibilities.” Like Show-Command. + +##How to Fix + +PTo fix a violation of this rule, please replace Write-Host with Write-Output. + +##Example + +Wrong: + +''' +function Test +{ + ... + Write-Host "Executing.." +} +''' +Correct: +''' +function Test +{ + ... + Write-Output "Executing.." +} + +function Show-Something +{ + Write-Host "show something on screen"; +} + +''' From 9ef7d48ad8589a2c7dc6db67a958ee05f046d4e4 Mon Sep 17 00:00:00 2001 From: Yuting Chen Date: Wed, 6 May 2015 15:58:49 -0700 Subject: [PATCH 2/2] updated examples --- RuleDocumentation/AvoidUsingWriteHost.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/RuleDocumentation/AvoidUsingWriteHost.md b/RuleDocumentation/AvoidUsingWriteHost.md index 7c8e46d74..890e16779 100644 --- a/RuleDocumentation/AvoidUsingWriteHost.md +++ b/RuleDocumentation/AvoidUsingWriteHost.md @@ -14,15 +14,17 @@ PTo fix a violation of this rule, please replace Write-Host with Write-Output. Wrong: -''' +``` function Test { ... Write-Host "Executing.." } -''' +``` + Correct: -''' + +``` function Test { ... @@ -33,5 +35,4 @@ function Show-Something { Write-Host "show something on screen"; } - -''' +```