Skip to content

Commit

Permalink
de-lint code base
Browse files Browse the repository at this point in the history
* reverse $null comparisons to avoid inadvertent array slicing
* ref: PowerShell/PSScriptAnalyzer#200
       @@ https://archive.is/Qxkc0 @@ https://webcitation.org/6du3Cd5TY
* NOTE: using PSScriptAnalyzer as the lint analyzer
  • Loading branch information
rivy committed Dec 20, 2015
1 parent 54dc137 commit 105374e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function hashtable($obj) {
}

function hashtable_val($obj) {
if($obj -eq $null) { return $null }
if($null -eq $obj) { return $null }
if($obj -is [array]) {
$arr = @()
$obj | foreach-object {
Expand Down Expand Up @@ -49,7 +49,7 @@ function set_config($name, $val) {
$cfg.$name = $val
}

if($val -eq $null) {
if($null -eq $val) {
$cfg.remove($name)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function versiondir($app, $version, $global) { "$(appdir $app $global)\$version"
# apps
function sanitary_path($path) { return [regex]::replace($path, "[/\\?:*<>|]", "") }
function installed($app, $global=$null) {
if($global -eq $null) { return (installed $app $true) -or (installed $app $false) }
if($null -eq $global) { return (installed $app $true) -or (installed $app $false) }
return test-path (appdir $app $global)
}
function installed_apps($global) {
Expand Down Expand Up @@ -68,7 +68,7 @@ function dl($url,$to) {
function env { param($name,$value,$targetEnvironment)
if ( $PSBoundParameters.ContainsKey('targetEnvironment') ) {
# $targetEnvironment is expected to be $null, [bool], [string], or [System.EnvironmentVariableTarget]
if ($targetEnvironment -eq $null) { $targetEnvironment = [System.EnvironmentVariableTarget]::Process }
if ($null -eq $targetEnvironment) { $targetEnvironment = [System.EnvironmentVariableTarget]::Process }
elseif ($targetEnvironment -is [bool]) {
# from initial usage pattern
if ($targetEnvironment) { $targetEnvironment = [System.EnvironmentVariableTarget]::Machine }
Expand All @@ -86,7 +86,7 @@ function env { param($name,$value,$targetEnvironment)

if($PSBoundParameters.ContainsKey('value')) {
[environment]::setEnvironmentVariable($name,$value,$targetEnvironment)
if (($targetEnvironment -eq [System.EnvironmentVariableTarget]::Process) -and ($CMDenvpipe -ne $null)) {
if (($targetEnvironment -eq [System.EnvironmentVariableTarget]::Process) -and ($null -ne $CMDenvpipe)) {
"set " + ( CMD_SET_encode_arg("$name=$value") ) | out-file $CMDenvpipe -encoding OEM -append
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function installed_manifest($app, $version, $global) {
}

function save_install_info($info, $dir) {
$nulls = $info.keys | where-object { $info[$_] -eq $null }
$nulls = $info.keys | where-object { $null -eq $info[$_] }
$nulls | foreach-object { $info.remove($_) } # strip null-valued

$info | convertto-json | out-file "$dir\install.json"
Expand Down
2 changes: 1 addition & 1 deletion lib/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function compare_versions($a, $b) {
}

function qsort($ary, $fn) {
if($ary -eq $null) { return @() }
if($null -eq $ary) { return @() }
if(!($ary -is [array])) { return @($ary) }

$pivot = $ary[0]
Expand Down
2 changes: 1 addition & 1 deletion test/Scoop-TestLib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function script_fail($msg) {
}

function script_fmt($var) {
if($var -eq $null) { return "`$null" }
if($null -eq $var) { return "`$null" }
if($var -is [string]) { return "'$var'" }
return $var
}
Expand Down

0 comments on commit 105374e

Please sign in to comment.