fix naming consitency (case mostly)

This commit is contained in:
jhoneill
2019-11-25 01:01:55 +00:00
parent f6c66e21a7
commit feb493e397
56 changed files with 249 additions and 214 deletions

View File

@@ -0,0 +1,44 @@

Function Test-SingleFunction {
param (
[parameter(ValueFromPipeline=$true)]
$path )
begin {
Push-Location "C:\Users\mcp\Documents\GitHub\ImportExcel"
$exportedFunctions = (Import-LocalizedData -FileName "ImportExcel.psd1").functionsToExport
Pop-Location
$reg = [Regex]::new(@"
function\s*[-\w]+\s*{ # The function name and opening '{'
(?:
[^{}]+ # Match all non-braces
|
(?<open> { ) # Match '{', and capture into 'open'
|
(?<-open> } ) # Match '}', and delete the 'open' capture
)*
(?(open)(?!)) # Fails if 'open' stack isn't empty
} # Functions closing '}'
"@, 33) # 33 = ignore case and white space.
}#
process {
$item = Get-item $Path
$name = $item.Name -replace "\.\w+$",""
Write-Verbose $name
$file = Get-Content $item -Raw
$m = $reg.Matches($file)
#based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis
if ($m.Count -eq 0) {return "Could not find $name function in $($item.name)"}
elseif ($m.Count -ge 2) {return "Multiple functions in $($item.name)"}
elseif ($exportedFunctions -cnotcontains $name) {return "$name not exported (or in the wrong case)"}
elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"}
elseif ($m[0] -inotmatch "^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param") {return "No param block in $name"}
elseif ($m[0] -inotmatch "\[cmdletbinding\(" -and
$m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"}
elseif (-not (& $Name -?).synopsis) {return "$name has no help"}
else {return "$name OK"}
}
}