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

Add Custom PSScriptAnalyzer Test for validating Parameter and Variable naming format #86

Closed
PlagueHO opened this issue Feb 3, 2017 · 1 comment

Comments

@PlagueHO
Copy link
Collaborator

PlagueHO commented Feb 3, 2017

I've recently been doing some work into creating custom PSSA rules. It should be fairly easy to create some rules that validate the Variable naming conventions (e.g. local variables start with lower case, parameter vars start with upper case).

The basis for the custom rule would be code like this:

process
{
    try
    {
        $Fucntions = $ScriptBlockAst.Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true )
        foreach ($function in $functions)
        {
            $ParamNames = $Function.FindAll( { $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true ).Parameters.Name.VariablePath.UserPath
            $Variables = $Function.FindAll( { $args[0] -is [System.Management.Automation.Language.VariableExpressionAst] }, $true )
        }
    }
    catch
    {
        $PSCmdlet.ThrowTerminatingError( $_ )
    }
}

Needs a bit more work but it should be easy enough. If it is worth implementing, then I'm happy to submit a PR.

@PlagueHO
Copy link
Collaborator Author

I've put together a first cut of this feature. It has been submitted here: #162

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant