|
12 | 12 | ) |
13 | 13 |
|
14 | 14 | BeforeAll { |
15 | | - $scriptFiles = Get-ChildItem -Path $Path -Filter '*.ps1' -Recurse -File |
| 15 | + $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File |
16 | 16 | $functionFiles = Get-ChildItem -Directory -Path $Path | |
17 | 17 | Where-Object { $_.Name -in 'public', 'private' } | |
18 | 18 | Get-ChildItem -Filter '*.ps1' -File |
@@ -128,6 +128,28 @@ Describe 'PSModule - SourceCode tests' { |
128 | 128 | Should -BeNullOrEmpty -Because 'the script should not use ternary operations for compatability with PS 5.1 and below' |
129 | 129 | } |
130 | 130 |
|
| 131 | + It 'all powershell keywords are lowercase' { |
| 132 | + $issues = @('') |
| 133 | + $scriptFiles | ForEach-Object { |
| 134 | + $filePath = $_.FullName |
| 135 | + $relativePath = $filePath.Replace($Path, '').Trim('\').Trim('/') |
| 136 | + |
| 137 | + $errors = $null |
| 138 | + $tokens = $null |
| 139 | + [System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$tokens, [ref]$errors) |
| 140 | + |
| 141 | + foreach ($token in $tokens) { |
| 142 | + $keyword = $token.Text |
| 143 | + $lineNumber = $token.Extent.StartLineNumber |
| 144 | + $columnNumber = $token.Extent.StartColumnNumber |
| 145 | + if (($token.TokenFlags -match 'Keyword') -and ($keyword -cne $keyword.ToLower())) { |
| 146 | + $issues += " - $relativePath`:L$lineNumber`:C$columnNumber - $keyword" |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + $issues -join [Environment]::NewLine | Should -BeNullOrEmpty -Because 'all powershell keywords should be lowercase' |
| 151 | + } |
| 152 | + |
131 | 153 | # It 'comment based doc block start is indented with 4 spaces' {} |
132 | 154 | # It 'comment based doc is indented with 8 spaces' {} |
133 | 155 | # It 'has synopsis for all functions' {} |
|
0 commit comments