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 ;
214using System . Collections . Generic ;
315using System . Linq ;
416using 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