<commit_before>﻿function Sort-AzureRMTemplate
{
    <#
    .Synopsis
        Sorts a resource manager template
    .Description
        Sorts the content in a resource manager template.        
    .Link
        https://github.com/Azure/azure-quickstart-templates/blob/master/1-CONTRIBUTION-GUIDE/best-practices.md
        !Reclarify this (sort order of resource properties)
    #>
    param(
    # The path to a file
    [Parameter(Mandatory=$true,ParameterSetName='FilePath',ValueFromPipelineByPropertyName=$true)]
    [string]$FilePath,

    # The path to a file
    [Parameter(Mandatory=$true,ParameterSetName='TemplateObject',ValueFromPipelineByPropertyName=$true)]
    [PSObject]$TemplateObject)

    begin {
        $topLevelPropertyOrder = 
            '$schema','contentVersion', 'apiProfile', 
            'parameters','functions','variables',
            'resources', 'outputs'
    }

    process {
        if ($PSCmdlet.ParameterSetName -eq 'FilePath') {
            $resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($FilePath)
        
            if (-not $resolvedPath) { return } 
        
            $templateText = [IO.File]::ReadAllText("$resolvedPath")
            $templateObject = $templateText | ConvertFrom-Json
            if (-not $templateObject) { return } 

            Sort-AzureRMTemplate -TemplateObject $TemplateObject
            return
        }

        if ($PSCmdlet.ParameterSetName -eq 'TemplateObject') {
            $newObject = [PSObject]::new()
            foreach ($propName in $topLevelPropertyOrder) {
                if ($templateObject.$propName) {
                    $newProp = 
                        [Management.Automation.PSNoteProperty]::new($propName, $TemplateObject.$propName)                    
                    $TemplateObject.psobject.properties.remove($propName)                    
                    $newObject.psobject.properties.add($newProp)
                }
            }
            if (@($templateObject.psobject.properties).Count) {
                foreach ($prop in $templateObject.psobject.properties) {
                    $newProp = 
                        [Management.Automation.PSNoteProperty]::new($prop.Name, $TemplateObject.$prop.Name)                    
                    $newObject.psobject.properties.add($newProp)
                } 
            }
            return $newObject
        }
    }
}<commit_msg>Fixing function name<commit_after>﻿function Format-AzureRMTemplate
{
    <#
    .Synopsis
        Formats a resource manager template in the desired order.
    .Description
        Sorts the content in a resource manager template.        
    .Link
        https://github.com/Azure/azure-quickstart-templates/blob/master/1-CONTRIBUTION-GUIDE/best-practices.md
    #>
    param(
    # The path to a file
    [Parameter(Mandatory=$true,ParameterSetName='FilePath',ValueFromPipelineByPropertyName=$true)]
    [string]$FilePath,

    # The path to a file
    [Parameter(Mandatory=$true,ParameterSetName='TemplateObject',ValueFromPipelineByPropertyName=$true)]
    [PSObject]$TemplateObject)

    begin {
        $topLevelPropertyOrder = 
            '$schema','contentVersion', 'apiProfile', 
            'parameters','functions','variables',
            'resources', 'outputs'
    }

    process {
        if ($PSCmdlet.ParameterSetName -eq 'FilePath') {
            $resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($FilePath)
        
            if (-not $resolvedPath) { return } 
        
            $templateText = [IO.File]::ReadAllText("$resolvedPath")
            $templateObject = $templateText | ConvertFrom-Json
            if (-not $templateObject) { return } 

            Format-AzureRMTemplate -TemplateObject $TemplateObject
            return
        }

        if ($PSCmdlet.ParameterSetName -eq 'TemplateObject') {
            $newObject = [PSObject]::new()
            foreach ($propName in $topLevelPropertyOrder) {
                if ($templateObject.$propName) {
                    $newProp = 
                        [Management.Automation.PSNoteProperty]::new($propName, $TemplateObject.$propName)                    
                    $TemplateObject.psobject.properties.remove($propName)                    
                    $newObject.psobject.properties.add($newProp)
                }
            }
            if (@($templateObject.psobject.properties).Count) {
                foreach ($prop in $templateObject.psobject.properties) {
                    $newProp = 
                        [Management.Automation.PSNoteProperty]::new($prop.Name, $TemplateObject.$prop.Name)                    
                    $newObject.psobject.properties.add($newProp)
                } 
            }
            return $newObject
        }
    }
}
{'fraction_non_alphanumeric': 0.10461029563779202, 'fraction_numerical': 0.0004134794293983874, 'mean_word_length': 1.933899332929048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6337290', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1212, 'n_words': 201}