diff --git a/repo_content_set_up/.githooks/pre-commit.ps1 b/repo_content_set_up/.githooks/pre-commit.ps1 index 1d1af3d..c706117 100644 --- a/repo_content_set_up/.githooks/pre-commit.ps1 +++ b/repo_content_set_up/.githooks/pre-commit.ps1 @@ -67,6 +67,8 @@ function _WarningAndExit { } function _GetFileEncoding { + # returns UTF-8 for UTF-8 with Bom and ASCII for UTF-8 encoded files! + [CmdletBinding()] param ( [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] @@ -158,13 +160,9 @@ function _getAliasAST { } # aliases defined by [Alias("Some-Alias")] - $AST.FindAll( { - param([System.Management.Automation.Language.Ast] $AST) + $AST.FindAll( { $args[0] -is [System.Management.Automation.Language.AttributeAst] }, $true) | ? { $_.parent.parent.parent.name -eq $functionName -and $_.parent.extent.text -match '^param' } | Select-Object -ExpandProperty PositionalArguments | Select-Object -ExpandProperty Value -ErrorAction SilentlyContinue | % { $alias += $_ } - $AST -is [System.Management.Automation.Language.AttributeAst] - }, $true) | ? { $_.parent.extent.text -match '^param' } | Select-Object -ExpandProperty PositionalArguments | Select-Object -ExpandProperty Value -ErrorAction SilentlyContinue | % { $alias += $_ } - - return $alias + return ($alias | Select-Object -Unique) } function _getParameterAST { @@ -595,6 +593,7 @@ try { } + # # check that commit doesn't contain any files in root of scripts2module folder # such files won't be processed anyway @@ -605,6 +604,7 @@ try { } + # # check commited script files encoding "- check encoding ..." @@ -614,13 +614,13 @@ try { $textFilesToCommit | ForEach-Object { $fileEnc = (_GetFileEncoding $_).bodyName if ($fileEnc -notin "US-ASCII", "ASCII", "UTF-8" ) { - _WarningAndExit "File $_ is encoded in '$fileEnc', so git diff wont work.`nIdeal is to save it using UTF-8 with BOM, or UTF-8." + _WarningAndExit "File $_ is encoded as '$fileEnc', so git diff wont work.`nIdeal is to save it using UTF-8 with BOM, or UTF-8." } } } - + # # various checks of ps1 and psm1 files "- check syntax, problematic characters, FIXME, best practices, format, name , changes in function parameters,..." @@ -762,6 +762,12 @@ try { } } } + + # + # error if function defines same named alias + if ($actAlias -and ($actAlias | ? { $_ -eq $functionName })) { + _ErrorAndExit "Function $functionName defines same named alias which is nonsense" + } } }