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 ;
2
14
using System . Collections . Generic ;
3
15
using System . Linq ;
4
16
using System . Management . Automation ;
@@ -32,12 +44,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
32
44
string funcName = funcDefAst . Name ;
33
45
bool hasShouldProcessAttribute = false ;
34
46
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 ) )
41
53
{
42
54
IEnumerable < Ast > attributeAsts = funcDefAst . FindAll ( testAst => testAst is NamedAttributeArgumentAst , true ) ;
43
55
if ( funcDefAst . Body != null && funcDefAst . Body . ParamBlock != null
@@ -51,9 +63,13 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
51
63
52
64
foreach ( NamedAttributeArgumentAst attributeAst in attributeAsts )
53
65
{
54
- if ( attributeAst . ArgumentName . Equals ( supportsShouldProcess , StringComparison . OrdinalIgnoreCase ) && attributeAst . Argument . Extent . Text . Equals ( trueString , StringComparison . OrdinalIgnoreCase ) )
66
+ if ( attributeAst . ArgumentName . Equals ( supportsShouldProcess , StringComparison . OrdinalIgnoreCase ) )
55
67
{
56
- hasShouldProcessAttribute = true ;
68
+ if ( ( attributeAst . Argument . Extent . Text . Equals ( trueString , StringComparison . OrdinalIgnoreCase ) ) && ! attributeAst . ExpressionOmitted ||
69
+ attributeAst . ExpressionOmitted )
70
+ {
71
+ hasShouldProcessAttribute = true ;
72
+ }
57
73
}
58
74
}
59
75
0 commit comments