diff --git a/CHANGELOG.md b/CHANGELOG.md index f02f60b..911779c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,13 @@ and [#9](https://github.com/dsccommunity/DscResource.AnalyzerRules/issues/9). - `DscResource.AnalyzerRules.psd1` - `CONTRIBUTING.md` - `Get-LocalizedData.Tests.ps1` +- `Measure-Keyword.ps1` + - Update regex in to match word boundaries. Fixes [#11](https://github.com/dsccommunity/DscResource.AnalyzerRules/issues/11). + - Fix formatting. +- Localization Strings + - Correct url for OneSpaceBetweenKeywordAndParenthesis. +- `Get-TokensFromDefinition.ps1` + - Remove unused variable. ## [0.2.0] - 2019-11-21 diff --git a/Source/Public/Measure-Keyword.ps1 b/Source/Public/Measure-Keyword.ps1 index 5b80d22..a21f381 100644 --- a/Source/Public/Measure-Keyword.ps1 +++ b/Source/Public/Measure-Keyword.ps1 @@ -14,9 +14,10 @@ .OUTPUTS [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]] - .NOTES + .NOTES None #> + function Measure-Keyword { [CmdletBinding()] @@ -41,7 +42,7 @@ function Measure-Keyword } $upperCaseTokens = $keywords.Where{ $_.Text -cMatch '[A-Z]+' } - $tokenWithNoSpace = $keywords.Where{ $_.Extent.StartScriptPosition.Line -match "$($_.Extent.Text)\(.*" } + $tokenWithNoSpace = $keywords.Where{ $_.Extent.StartScriptPosition.Line -match "\b$($_.Extent.Text)\(.*" } foreach ($item in $upperCaseTokens) { diff --git a/Source/en-US/DscResource.AnalyzerRules.psd1 b/Source/en-US/DscResource.AnalyzerRules.psd1 index 584d821..72f794d 100644 --- a/Source/en-US/DscResource.AnalyzerRules.psd1 +++ b/Source/en-US/DscResource.AnalyzerRules.psd1 @@ -42,6 +42,6 @@ EnumOpeningBraceShouldBeFollowedByOnlyOneNewLine = Opening brace on Enum should ClassOpeningBraceNotOnSameLine = Class should not have the open brace on the same line as the declaration. See https://dsccommunity.org/styleguidelines/whitespace/#one-newline-before-braces ClassOpeningBraceShouldBeFollowedByNewLine = Opening brace on Class should be followed by a new line. See https://dsccommunity.org/styleguidelines/whitespace/#one-newline-after-opening-brace ClassOpeningBraceShouldBeFollowedByOnlyOneNewLine = Opening brace on Class should only be followed by one new line. See https://dsccommunity.org/styleguidelines/whitespace/#one-newline-after-opening-brace -OneSpaceBetweenKeywordAndParenthesis = If a keyword is followed by a parenthesis, there should be single space between the keyword and the parenthesis. See https://dsccommunity.org/styleguidelines/whitespace/#one-newline-after-opening-brace +OneSpaceBetweenKeywordAndParenthesis = If a keyword is followed by a parenthesis, there should be single space between the keyword and the parenthesis. See https://dsccommunity.org/styleguidelines/whitespace/#one-space-between-keyword-and-parenthesis HashtableShouldHaveCorrectFormat = Hashtable is not correctly formatted. See https://dsccommunity.org/styleguidelines/general/#correct-format-for-hashtables-or-objects '@ diff --git a/tests/Unit/Public/Get-TokensFromDefinition.ps1 b/tests/Unit/Public/Get-TokensFromDefinition.ps1 index a99148f..d0ece60 100644 --- a/tests/Unit/Public/Get-TokensFromDefinition.ps1 +++ b/tests/Unit/Public/Get-TokensFromDefinition.ps1 @@ -18,7 +18,7 @@ function Get-TokensFromDefinition ) $parseErrors = $token = $null - $definitionAst = [System.Management.Automation.Language.Parser]::ParseInput($ScriptDefinition, [ref] $token, [ref] $parseErrors) + $null = [System.Management.Automation.Language.Parser]::ParseInput($ScriptDefinition, [ref] $token, [ref] $parseErrors) if ($parseErrors) { diff --git a/tests/Unit/Public/Measure-Keyword.Tests.ps1 b/tests/Unit/Public/Measure-Keyword.Tests.ps1 index e51fb53..2096210 100644 --- a/tests/Unit/Public/Measure-Keyword.Tests.ps1 +++ b/tests/Unit/Public/Measure-Keyword.Tests.ps1 @@ -101,6 +101,24 @@ Describe 'Measure-Keyword' { ($record | Measure-Object).Count | Should -Be 0 } } + + Context 'When another word contains ''base'' but has other characters preceeding it' { + It 'Should not return an error record' { + $definition = ' + class SqlSetupBase + { + SqlSetupBase() : base () + { + Write-Verbose -Message "Example found." + } + } + ' + + $token = Get-TokensFromDefinition -ScriptDefinition $definition + $record = Measure-Keyword -Token $token + ($record | Measure-Object).Count | Should -Be 0 + } + } } Context 'When calling PSScriptAnalyzer' { @@ -190,6 +208,22 @@ Describe 'Measure-Keyword' { ($record | Measure-Object).Count | Should -Be 0 } } + + Context 'When another word contains ''base'' but has other characters preceeding it' { + It 'Should not return an error record' { + $invokeScriptAnalyzerParameters['ScriptDefinition'] = ' + class SqlSetupBase + { + SqlSetupBase() : base () + { + Write-Verbose -Message "Example found." + } + } + ' + $record = Invoke-ScriptAnalyzer @invokeScriptAnalyzerParameters + ($record | Measure-Object).Count | Should -Be 0 + } + } } } }