Skip to content

Commit

Permalink
get alias just from main function, check alias name isnt same as func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ztrhgf committed Oct 12, 2021
1 parent 07edcc8 commit 2acc029
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions repo_content_set_up/.githooks/pre-commit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -605,6 +604,7 @@ try {
}



#
# check commited script files encoding
"- check encoding ..."
Expand All @@ -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,..."
Expand Down Expand Up @@ -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"
}
}
}

Expand Down

0 comments on commit 2acc029

Please sign in to comment.