Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 9c3c406

Browse files
authored
Merge pull request #346 from SSvilen/KeywordsCheck
Added function for checking lower case format for all keywords
2 parents 2277d46 + 4593289 commit 9c3c406

File tree

4 files changed

+222
-33
lines changed

4 files changed

+222
-33
lines changed

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"powershell.codeFormatting.openBraceOnSameLine": false,
3+
"powershell.codeFormatting.newLineAfterOpenBrace": false,
4+
"powershell.codeFormatting.newLineAfterCloseBrace": true,
5+
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
6+
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
7+
"powershell.codeFormatting.whitespaceAroundOperator": true,
8+
"powershell.codeFormatting.whitespaceAfterSeparator": true,
9+
"powershell.codeFormatting.ignoreOneLineBlock": false,
10+
"powershell.codeFormatting.preset": "Custom",
11+
"files.trimTrailingWhitespace": true,
12+
"files.insertFinalNewline": true,
13+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
- Moved `Publish Wiki Content` section in the `README.md` to the correct location.
7878
- Removed the legacy `CHANGELOG` link in the `README.md` table of contents.
7979
- Fixed broken links and formatting in the `README.md` file.
80+
- Added Measure-Keyword function to check if all keywords are in lower case.
8081

8182
## 0.3.0.0
8283

DscResource.AnalyzerRules/DscResource.AnalyzerRules.psm1

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function Measure-IfStatement
284284
and the first rows ends with a correct open brace. See example in
285285
regression test for #238.
286286
#>
287-
$extentTextWithClauseRemoved = $IfStatementAst.Extent.Text.Replace($IfStatementAst.Clauses[0].Item1.Extent.Text,'')
287+
$extentTextWithClauseRemoved = $IfStatementAst.Extent.Text.Replace($IfStatementAst.Clauses[0].Item1.Extent.Text, '')
288288

289289
$testParameters = @{
290290
StatementBlock = $extentTextWithClauseRemoved
@@ -1000,4 +1000,55 @@ function Measure-TypeDefinition
10001000
}
10011001
}
10021002

1003+
<#
1004+
.SYNOPSIS
1005+
Validates all keywords.
1006+
1007+
.DESCRIPTION
1008+
Each keyword should be in all lower case.
1009+
1010+
.EXAMPLE
1011+
Measure-Keyword -Token $Token
1012+
1013+
.INPUTS
1014+
[System.Management.Automation.Language.Token[]]
1015+
1016+
.OUTPUTS
1017+
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
1018+
1019+
.NOTES
1020+
None
1021+
#>
1022+
function Measure-Keyword
1023+
{
1024+
[CmdletBinding()]
1025+
[OutputType([Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]])]
1026+
Param
1027+
(
1028+
[Parameter(Mandatory = $true)]
1029+
[ValidateNotNullOrEmpty()]
1030+
[System.Management.Automation.Language.Token[]]
1031+
$Token
1032+
)
1033+
1034+
try
1035+
{
1036+
$script:diagnosticRecord['RuleName'] = $PSCmdlet.MyInvocation.InvocationName
1037+
1038+
$keywordFlag = [System.Management.Automation.Language.TokenFlags]::Keyword
1039+
$upperCaseTokens = $Token.Where( { $_.TokenFlags.HasFlag($keywordFlag) -and $_.Text -cmatch '[A-Z]+' })
1040+
1041+
foreach ($item in $upperCaseTokens)
1042+
{
1043+
$script:diagnosticRecord['Extent'] = $item.Extent
1044+
$script:diagnosticRecord['Message'] = $localizedData.StatementsContainsUpperCaseLetter -f $item.Text
1045+
$script:diagnosticRecord -as $diagnosticRecordType
1046+
} #if
1047+
}
1048+
catch
1049+
{
1050+
$PSCmdlet.ThrowTerminatingError($PSItem)
1051+
}
1052+
}
1053+
10031054
Export-ModuleMember -Function Measure-*

0 commit comments

Comments
 (0)