Skip to content

Commit adbeff0

Browse files
Jos KoelewijnJos Koelewijn
Jos Koelewijn
authored and
Jos Koelewijn
committed
Add sensible warning message
1 parent 068b1fc commit adbeff0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Rules/AvoidUnInitializedVarsInNewRunspaces.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using System;
@@ -160,8 +160,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeScriptBlockAst(ScriptBlockAst scrip
160160

161161
yield return new DiagnosticRecord(
162162
message: string.Format(CultureInfo.CurrentCulture,
163-
Strings.UseDeclaredVarsMoreThanAssignmentsError, _temp?.ToString()),
164-
extent: _temp?.Extent,
163+
Strings.AvoidUnInitializedVarsInNewRunspacesError, variableExpression.ToString()),
164+
extent: variableExpression.Extent,
165165
ruleName: GetName(),
166166
severity: DiagnosticSeverity.Warning,
167167
scriptPath: fileName,

Rules/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,12 @@
11261126
<value>Use $Using: directive in runspace scriptblocks</value>
11271127
</data>
11281128
<data name="AvoidUnInitializedVarsInNewRunspacesDescription" xml:space="preserve">
1129-
<value>If a scriptblock is intended to be run as a new runspace, variables inside it should use $using: directive, or be initialized within the scriptblock.</value>
1129+
<value>If a ScriptBlock is intended to be run as a new runspace, variables inside it should use $using: directive, or be initialized within the ScriptBlock.</value>
11301130
</data>
11311131
<data name="AvoidUnInitializedVarsInNewRunspacesName" xml:space="preserve">
11321132
<value>AvoidUnInitializedVarsInNewRunspaces</value>
11331133
</data>
1134+
<data name="AvoidUnInitializedVarsInNewRunspacesError" xml:space="preserve">
1135+
<value>The variable '{0}' is not declared within this ScriptBlock, and is missing the '$using:' directive.</value>
1136+
</data>
11341137
</root>

0 commit comments

Comments
 (0)