File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -764,7 +764,7 @@ public IScriptExtent GetScriptExtentForFunctionName(FunctionDefinitionAst functi
764764
765765 // If the functions name is 'function' then the first token in the
766766 // list is the function keyword itself, so we need to skip it
767- if ( functionDefinitionAst . Name . Equals ( "function" ) )
767+ if ( functionDefinitionAst . Name . Equals ( "function" , StringComparison . OrdinalIgnoreCase ) )
768768 {
769769 var funcNameToken = funcNameTokens . Skip ( 1 ) . FirstOrDefault ( ) ?? funcNameTokens . FirstOrDefault ( ) ;
770770 return funcNameToken ? . Extent ;
Original file line number Diff line number Diff line change @@ -78,6 +78,24 @@ Describe 'AvoidReservedWordsAsFunctionNames' {
7878 $violations [0 ].Extent.Text | Should - Be $_
7979 }
8080
81+ It ' flags the correct extent for a function named Function' {
82+
83+ $scriptDefinition = " Function Function { 'test' }"
84+ $violations = Invoke-ScriptAnalyzer - ScriptDefinition $scriptDefinition - IncludeRule @ ($ruleName )
85+
86+ $violations.Count | Should - Be 1
87+ $violations [0 ].Severity | Should - Be ' Warning'
88+ $violations [0 ].RuleName | Should - Be $ruleName
89+ # Message text should include the function name as used
90+ $violations [0 ].Message | Should - Be " The reserved word 'Function' was used as a function name. This should be avoided."
91+ # Extent should ideally capture only the function name
92+ $violations [0 ].Extent.Text | Should - Be ' Function'
93+
94+ # Make sure the extent is the correct `Function` (not the one at the
95+ # very start)
96+ $violations [0 ].Extent.StartOffset | Should -not - Be 0
97+ }
98+
8199 # Functions can have scopes. So function global:function {} should still
82100 # alert.
83101 It ' flags reserved word "<Name>" with scope "<Scope>" as a violation' - TestCases $scopedReservedWordCases {
You can’t perform that action at this time.
0 commit comments