Skip to content

Commit ac7fd00

Browse files
committed
Merge branch 'NewRule' into BugFixes
2 parents 034780e + 731f456 commit ac7fd00

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

Rules/Strings.Designer.cs

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

Rules/Strings.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,10 @@
658658
<value>Use ShouldProcess For State Changing Functions</value>
659659
</data>
660660
<data name="UseShouldProcessForStateChangingFunctionsDescrption" xml:space="preserve">
661-
<value>Functions that have verbs like New, Start, Stop, Set, Reset that change systme state should support 'ShouldProcess'</value>
661+
<value>Functions that have verbs like New, Start, Stop, Set, Reset that change system state should support 'ShouldProcess'.</value>
662662
</data>
663663
<data name="UseShouldProcessForStateChangingFunctionsError" xml:space="preserve">
664-
<value>Function ’{0}’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'</value>
664+
<value>Function ’{0}’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.</value>
665665
</data>
666666
<data name="UseShouldProcessForStateChangingFunctionsName" xml:space="preserve">
667667
<value>UseShouldProcessForStateChangingFunctions</value>

Rules/UseShouldProcessForStateChangingFunctions.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
using System;
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10+
// THE SOFTWARE.
11+
//
12+
13+
using System;
214
using System.Collections.Generic;
315
using System.Linq;
416
using System.Management.Automation;
@@ -32,12 +44,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
3244
string funcName = funcDefAst.Name;
3345
bool hasShouldProcessAttribute = false;
3446

35-
if (funcName.IndexOf("Get", StringComparison.OrdinalIgnoreCase) >= 0 ||
36-
funcName.IndexOf("Stop", StringComparison.OrdinalIgnoreCase) >= 0 ||
37-
funcName.IndexOf("New", StringComparison.OrdinalIgnoreCase) >= 0 ||
38-
funcName.IndexOf("Set", StringComparison.OrdinalIgnoreCase) >= 0 ||
39-
funcName.IndexOf("Update", StringComparison.OrdinalIgnoreCase) >= 0 ||
40-
funcName.IndexOf("Reset", StringComparison.OrdinalIgnoreCase) >= 0)
47+
if (funcName.StartsWith("Get-", StringComparison.OrdinalIgnoreCase) ||
48+
funcName.StartsWith("Stop-", StringComparison.OrdinalIgnoreCase)||
49+
funcName.StartsWith("New-", StringComparison.OrdinalIgnoreCase) ||
50+
funcName.StartsWith("Set-", StringComparison.OrdinalIgnoreCase) ||
51+
funcName.StartsWith("Update-", StringComparison.OrdinalIgnoreCase) ||
52+
funcName.StartsWith("Reset-", StringComparison.OrdinalIgnoreCase))
4153
{
4254
IEnumerable<Ast> attributeAsts = funcDefAst.FindAll(testAst => testAst is NamedAttributeArgumentAst, true);
4355
if (funcDefAst.Body != null && funcDefAst.Body.ParamBlock != null
@@ -51,9 +63,13 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
5163

5264
foreach (NamedAttributeArgumentAst attributeAst in attributeAsts)
5365
{
54-
if (attributeAst.ArgumentName.Equals(supportsShouldProcess, StringComparison.OrdinalIgnoreCase) && attributeAst.Argument.Extent.Text.Equals(trueString, StringComparison.OrdinalIgnoreCase))
66+
if (attributeAst.ArgumentName.Equals(supportsShouldProcess, StringComparison.OrdinalIgnoreCase))
5567
{
56-
hasShouldProcessAttribute = true;
68+
if((attributeAst.Argument.Extent.Text.Equals(trueString, StringComparison.OrdinalIgnoreCase)) && !attributeAst.ExpressionOmitted ||
69+
attributeAst.ExpressionOmitted)
70+
{
71+
hasShouldProcessAttribute = true;
72+
}
5773
}
5874
}
5975

0 commit comments

Comments
 (0)