Enforcing code style throughout the project

This commit is contained in:
Alexander Kostikov 2020-05-05 16:58:52 -07:00
Родитель 0097ba08d1
Коммит ce5e761430
11 изменённых файлов: 130 добавлений и 124 удалений

3
.vscode/settings.json поставляемый
Просмотреть файл

@ -39,5 +39,6 @@
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBeforeOpenBrace": false,
"powershell.codeFormatting.whitespaceBeforeOpenParen": false,
"powershell.codeFormatting.whitespaceInsideBrace": false
"powershell.codeFormatting.whitespaceInsideBrace": false,
"powershell.codeFormatting.alignPropertyValuePairs": false
}

Просмотреть файл

@ -111,11 +111,11 @@ function Show-Highlight
param
(
[string] $Regex = "^\s*PS\s+.*>.+",
[ConsoleColor] $Color = "Blue",
[switch] $DropUnmatched,
[switch] $Interactive,
[switch] $JSON
[string] $Regex = "^\s*PS\s+.*>.+",
[ConsoleColor] $Color = "Blue",
[switch] $DropUnmatched,
[switch] $Interactive,
[switch] $JSON
)
begin
@ -359,7 +359,7 @@ function Show-ColorizedContent
# Read the text of the file, and parse it
$content = $content | Out-String
$parsed = [Management.Automation.PsParser]::Tokenize($content, [ref] $null) | Sort StartLine, StartColumn
$parsed = [Management.Automation.PsParser]::Tokenize($content, [ref] $null) | sort StartLine, StartColumn
function WriteFormattedLine($formatString, [int] $line)
{
@ -404,7 +404,7 @@ function Show-ColorizedContent
# Handle the line numbering for multi-line strings
$lineCounter = $token.StartLine
$stringLines = $(-join $content[$token.Start..$tokenEnd] -split "`r`n")
$stringLines = $( -join $content[$token.Start..$tokenEnd] -split "`r`n")
foreach($stringLine in $stringLines)
{
if($lineCounter -gt $token.StartLine)

Просмотреть файл

@ -125,12 +125,13 @@ function Get-Parameter
}
# Get properties that match the pattern
$result = @($accumulator |
foreach{ $psitem.PsObject.Members } |
where Name -match $pattern |
where MemberType -match "Property" |
foreach Name |
Get-UniqueUnsorted)
$result = @(
$accumulator |
foreach{ $psitem.PsObject.Members } |
where Name -match $pattern |
where MemberType -match "Property" |
foreach Name |
Get-UniqueUnsorted)
# Need to return all entries
if( -not $single ) { return $result }
@ -369,7 +370,7 @@ function Get-Ini
}
"^([^=]+)\s*=\s*(.*)?\s*$"
{
$name,$value = $matches[1..2]
$name, $value = $matches[1..2]
$ini[$section][$name.Trim()] = $value
}
default
@ -457,7 +458,7 @@ function ConvertFrom-Ini
}
"^([^=]+)\s*=\s*(.*)?\s*$"
{
$name,$value = $matches[1..2]
$name, $value = $matches[1..2]
$ini[$section][$name.Trim()] = $value
}
default

Просмотреть файл

@ -77,7 +77,7 @@ function Get-FileEncoding
param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Path
)
@ -101,12 +101,13 @@ function Get-FileEncoding
return $true
}
$knownEncodings =
$knownEncodings = @(
[Text.Encoding]::BigEndianUnicode,
[Text.Encoding]::UTF32,
[Text.Encoding]::UTF8,
[Text.Encoding]::Unicode, # that's UTF16
[Text.Encoding]::Default # must come last
)
[byte[]] $byte = Get-Content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path

Просмотреть файл

@ -33,12 +33,12 @@ function Get-Randomized
$array = [Collections.ArrayList]::New(@($input))
while( $array )
{
$index = Get-Random $array.Count
$array[$index]
$array.RemoveAt($index)
}
while( $array )
{
$index = Get-Random $array.Count
$array[$index]
$array.RemoveAt($index)
}
}
function Get-Median

Просмотреть файл

@ -26,7 +26,7 @@ function Initialize-GitConfig
if( $env:USERDOMAIN -eq "Redmond" )
{
# Figure out name of the current user from Active Directory
$ntAccount = new-object Security.Principal.NTAccount($env:USERDOMAIN, $env:USERNAME)
$ntAccount = New-Object Security.Principal.NTAccount($env:USERDOMAIN, $env:USERNAME)
$sid = $ntAccount.Translate([Security.Principal.SecurityIdentifier])
$ldap = [adsi] "LDAP://<SID=$sid>"

Просмотреть файл

@ -3,92 +3,92 @@
@{
# Script module or binary module file associated with this manifest
RootModule = 'PSToolset.psm1'
# Script module or binary module file associated with this manifest
RootModule = 'PSToolset.psm1'
# Version number of this module.
ModuleVersion = '0.9.0'
# Version number of this module.
ModuleVersion = '0.9.5'
# ID used to uniquely identify this module
GUID = 'c2b885a6-dafe-4aff-9045-414874b9db36'
# ID used to uniquely identify this module
GUID = 'c2b885a6-dafe-4aff-9045-414874b9db36'
# Author of this module
Author = 'Aleksandr Kostikov, alexko@microsoft.com'
# Author of this module
Author = 'Aleksandr Kostikov, alexko@microsoft.com'
# Copyright statement for this module
Copyright = '(c) Microsoft Corporation'
# Copyright statement for this module
Copyright = '(c) Microsoft Corporation'
# Description of the functionality provided by this module
Description = 'Toolset for Powershell environment'
# Description of the functionality provided by this module
Description = 'Toolset for Powershell environment'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '7.0'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '7.0'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = @(
'all',
'any',
'call',
'construct',
'default',
'f', # filter
'first',
'gite',
'hl', # highlight
'jn', # jupyter notebook
'last',
'lock',
'p', # project
'parse',
'separate',
'source',
'xattr',
'xcomm',
'xelem',
'xmlns',
'xname'
)
# Aliases to export from this module
AliasesToExport = @(
'all',
'any',
'call',
'construct',
'default',
'f', # filter
'first',
'gite',
'hl', # highlight
'jn', # jupyter notebook
'last',
'lock',
'p', # project
'parse',
'separate',
'source',
'xattr',
'xcomm',
'xelem',
'xmlns',
'xname'
)
# Functions to export from this module
FunctionsToExport = @(
# Colors
"Write-Colorized", "Show-Highlight", "Get-Colors", "Get-Source",
# Data
"ConvertTo-PsObject", "ConvertTo-Hash",
"Get-Parameter", "Use-Project", "Use-Filter",
"Get-Ini", "Show-Ini", "ConvertFrom-Ini", "Import-Ini",
# Files
"Resolve-ScriptPath", "Get-FileEncoding",
# Functional
"Test-Any", "Test-All", "Get-First", "Get-Last", "Get-Separation",
"Get-Median", "Get-Reverse", "Get-UniqueUnsorted", "Get-Randomized",
# Git
"Initialize-GitConfig", "Open-GitExtensions",
"Get-CommitAuthorName", "Get-CommitAuthorEmail",
"Get-CommitAuthorDate", "Get-CommitMessage",
# Python
"Start-JupyterNotebook", "Stop-JupyterNotebook",
# Security
"Invoke-Elevated", "Test-Interactive", "Test-Elevated", "Set-DelayLock",
# Text
"Use-Parse", "Use-Default", "Format-Template", "Get-UnresolvedTemplateItem",
# Utils
"Use-Retries", "Set-CmdEnvironment",
# Xml
"New-XName", "New-XAttribute", "New-Xmlns", "New-XComment", "New-XElement"
)
# Functions to export from this module
FunctionsToExport = @(
# Colors
"Write-Colorized", "Show-Highlight", "Get-Colors", "Get-Source",
# Data
"ConvertTo-PsObject", "ConvertTo-Hash",
"Get-Parameter", "Use-Project", "Use-Filter",
"Get-Ini", "Show-Ini", "ConvertFrom-Ini", "Import-Ini",
# Files
"Resolve-ScriptPath", "Get-FileEncoding",
# Functional
"Test-Any", "Test-All", "Get-First", "Get-Last", "Get-Separation",
"Get-Median", "Get-Reverse", "Get-UniqueUnsorted", "Get-Randomized",
# Git
"Initialize-GitConfig", "Open-GitExtensions",
"Get-CommitAuthorName", "Get-CommitAuthorEmail",
"Get-CommitAuthorDate", "Get-CommitMessage",
# Python
"Start-JupyterNotebook", "Stop-JupyterNotebook",
# Security
"Invoke-Elevated", "Test-Interactive", "Test-Elevated", "Set-DelayLock",
# Text
"Use-Parse", "Use-Default", "Format-Template", "Get-UnresolvedTemplateItem",
# Utils
"Use-Retries", "Set-CmdEnvironment",
# Xml
"New-XName", "New-XAttribute", "New-Xmlns", "New-XComment", "New-XElement"
)
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()
# List of all files packaged with this module
FileList =
# List of all files packaged with this module
FileList =
'Colors.ps1',
'Data.ps1',
'Files.ps1',

Просмотреть файл

@ -20,7 +20,7 @@ function Start-JupyterNotebook
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[switch] $Force
@ -90,7 +90,7 @@ function Stop-JupyterNotebook
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param()
# Test if jupyter is installed

Просмотреть файл

@ -3,7 +3,7 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
"PSAvoidGlobalVars", "",
Justification="We need global PSToolsetAutoCompleteOptions here")]
Justification = "We need global PSToolsetAutoCompleteOptions here")]
param()
# Test if we did that override already, PSToolset can be

Просмотреть файл

@ -3,7 +3,7 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
"PSAvoidGlobalVars", "",
Justification="We need global PSToolsetLastRetryError here")]
Justification = "We need global PSToolsetLastRetryError here")]
param()
function Use-Retries
@ -110,7 +110,7 @@ function Set-CmdEnvironment
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[Parameter( Mandatory = $true )]
@ -135,15 +135,17 @@ function Set-CmdEnvironment
$lineQueue = $GLOBAL:shared.lineQueue
# Initialize process object
$process = [Diagnostics.Process] @{ StartInfo = [Diagnostics.ProcessStartInfo] @{
FileName = (Get-Command 'cmd').Definition
Arguments = "/c `"$script`" $parameters & echo $($GLOBAL:shared.marker) & set"
WorkingDirectory = (Get-Location).Path
UseShellExecute = $false
RedirectStandardError = $true
RedirectStandardOutput = $true
RedirectStandardInput = $false
} }
$process = [Diagnostics.Process] @{
StartInfo = [Diagnostics.ProcessStartInfo] @{
FileName = (Get-Command 'cmd').Definition
Arguments = "/c `"$script`" $parameters & echo $($GLOBAL:shared.marker) & set"
WorkingDirectory = (Get-Location).Path
UseShellExecute = $false
RedirectStandardError = $true
RedirectStandardOutput = $true
RedirectStandardInput = $false
}
}
# Check if we need to reinitialize PSModulePath
if( -not $inheritPSModulePath )
@ -153,9 +155,10 @@ function Set-CmdEnvironment
$process.StartInfo.EnvironmentVariables.Remove("PSModulePath") | Out-Null
}
$value =
$value = @(
[Environment]::GetEnvironmentVariable("PSModulePath", "Machine") + ";" +
[Environment]::GetEnvironmentVariable("PSModulePath", "User")
)
$process.StartInfo.EnvironmentVariables.Add("PSModulePath", $value) | Out-Null
}

20
Xml.ps1
Просмотреть файл

@ -13,10 +13,10 @@ function New-XName
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Name
)
@ -37,10 +37,10 @@ function New-XAttribute
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Name,
[string] $Value
)
@ -62,12 +62,12 @@ function New-Xmlns
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Namespace,
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Value
)
@ -88,10 +88,10 @@ function New-XComment
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Value
)
@ -129,7 +129,7 @@ filter New-XElement
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '',
Justification='Intended to be this way')]
Justification = 'Intended to be this way')]
param
(
[string] $Name,