Skip to content

Commit 9dd4df0

Browse files
committed
Configured Linter and fixed detected errors
1 parent a8ef9f0 commit 9dd4df0

10 files changed

+68
-35
lines changed

PSScriptAnalyzerSettings.psd1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@{
2+
# Use Severity when you want to limit the generated diagnostic records to a
3+
# subset of: Error, Warning and Information.
4+
# Uncomment the following line if you only want Errors and Warnings but
5+
# not Information diagnostic records.
6+
Severity = @('Error', 'Warning')
7+
8+
# Use IncludeRules when you want to run only a subset of the default rule set.
9+
#IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
10+
# 'PSMissingModuleManifestField',
11+
# 'PSReservedCmdletChar',
12+
# 'PSReservedParams',
13+
# 'PSShouldProcess',
14+
# 'PSUseApprovedVerbs',
15+
# 'PSUseDeclaredVarsMoreThanAssigments')
16+
17+
# Use ExcludeRules when you want to run most of the default set of rules except
18+
# for a few rules you wish to "exclude". Note: if a rule is in both IncludeRules
19+
# and ExcludeRules, the rule will be excluded.
20+
ExcludeRules = @(
21+
'PSAvoidUsingWriteHost',
22+
'PSMissingModuleManifestField'
23+
)
24+
25+
# You can use the following entry to supply parameters to rules that take parameters.
26+
# For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you
27+
# want to allow.
28+
#Rules = @{
29+
# Do not flag 'cd' alias.
30+
# PSAvoidUsingCmdletAliases = @{Whitelist = @('cd')}
31+
32+
# Check if your script uses cmdlets that are compatible on PowerShell Core,
33+
# version 6.0.0-alpha, on Linux.
34+
# PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")}
35+
#}
36+
}

src/jenv-add.psm1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Invoke-Add {
88

99
if ($help) {
1010
Write-Host '"jenv add" <name> <path>'
11-
Write-Host With this command you can tell JEnv which java versions you have installed
11+
Write-Host "With this command you can tell JEnv which java versions you have installed"
1212
Write-Host '<name> is an alias you have to give the java version for easier referencing. It cannot be remove'
1313
Write-Host '<path> is the path to the parent of your bin folder. For example: "C:\Program Files\Java\jdk-17"'
1414
Write-Host 'You have to register your JEnvs first before you can use "jenv change", "jenv use" or "jenv local"'
@@ -30,7 +30,6 @@ function Invoke-Add {
3030
return
3131
}
3232
}
33-
3433
# Check if the path is a valid java home
3534
if (!(Test-Path -Path $path/bin/java.exe -PathType Leaf)) {
3635
Write-Output ($path + "/bin/java.exe not found. Your Path is not a valid JAVA_HOME")

src/jenv-change.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ function Invoke-Change {
88

99
if ($help) {
1010
Write-Host '"jenv change <name>"'
11-
Write-Host 'With this command you set your JAVA_HOME and the version of java to be used globally. This is overwriten by both "jenv local" and "jenv use"'
12-
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
11+
Write-Host 'With this command you set your JAVA_HOME and the version of java to be used globally. This is overwriten by both "jenv local" and "jenv use"'
12+
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
1313
}
1414
else {
1515

1616
# Check if specified JEnv is avaible
1717
$jenv = $config.jenvs | Where-Object { $_.name -eq $name }
1818
if ($null -eq $jenv) {
19-
Write-Host Theres no JEnv with name $name Consider using "jenv list"
19+
Write-Host 'Theres no JEnv with name {0} Consider using "jenv list"' -f $name
2020
return
2121
}
2222
else {
23-
Write-Host Setting JAVA_HOME globally. This could take some time
23+
Write-Host "Setting JAVA_HOME globally. This could take some time"
2424
$config.global = $jenv.path
2525
$Env:JAVA_HOME = $jenv.path # Set for powershell users
2626
if ($output) {
2727
Set-Content -path "jenv.home.tmp" -value $jenv.path # Create temp file so no restart of the active shell is required
2828
}
2929
[System.Environment]::SetEnvironmentVariable("JAVA_HOME", $jenv.path, [System.EnvironmentVariableTarget]::User) # Set globally}
30-
Write-Host JEnv changed globally
30+
Write-Host "JEnv changed globally"
3131
}
3232
}
3333
}

src/jenv-getjava.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function Get-Java {
33
param (
44
[object]$config
55
)
6-
6+
77
$global = $config.global
88
$localname = ($config.locals | Where-Object { $_.path -eq (Get-Location) }).name
99
$local = ($config.jenvs | Where-Object { $_.name -eq $localname }).path

src/jenv-link.psm1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
function Invoke-Link {
22
param (
3-
[Parameter(Mandatory = $true)][object]$config,
43
[Parameter(Mandatory = $true)][boolean]$help,
54
[Parameter(Mandatory = $true)][string]$executable
65
)
76

87
if ($help) {
98
Write-Host '"jenv link" <executable>'
10-
Write-Host With this command you can create shortcuts for executables inside JAVA_HOME
9+
Write-Host "With this command you can create shortcuts for executables inside JAVA_HOME"
1110
Write-Host '<executable> is the name of the binary file for example "javac" or "javaw"'
1211
Write-Host 'For example enable javac with: "jenv link javac"'
1312
Write-Host 'List all registered java versions with "jenv list"'
@@ -17,7 +16,7 @@ function Invoke-Link {
1716
$payload = @'
1817
@echo off
1918
for /f "delims=" %%i in ('jenv getjava') do set "var=%%i"
20-
19+
2120
if exist "%var%/bin/{0}.exe" (
2221
"%var%/bin/{0}.exe" %*
2322
) else (
@@ -26,7 +25,7 @@ function Invoke-Link {
2625
)
2726
'@ -f $executable
2827

29-
Set-Content ((get-item $PSScriptRoot).parent.fullname + "/$executable.bat") $payload
28+
Set-Content ((get-item $PSScriptRoot).parent.fullname + "/$executable.bat") $payload
3029

3130
}
3231
}

src/jenv-list.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ function Invoke-List {
66

77
if ($help) {
88
Write-Host '"jenv list"'
9-
Write-Host This command will display every added java version as well as its name
9+
Write-Host "This command will display every added java version as well as its name"
1010
Write-Host 'You have to add java versions with "jenv add"'
1111
Write-Host 'Then you can set them with various commands like "jenv use" or "jenv change"'
12-
Write-Host This command will also tell you every local JEnv that you specified
12+
Write-Host "This command will also tell you every local JEnv that you specified"
1313
Write-Host 'You can tell JEnv that it should always use jdk8 on the desktop with "jenv local"'
1414
}
1515
else {
1616

17-
Write-Host All avaible versions of java
17+
Write-Host "All avaible versions of java"
1818
Write-Host ($config.jenvs | Format-Table | Out-String)
19-
Write-Host All locally specified versions
19+
Write-Host "All locally specified versions"
2020
Write-Host ($config.locals | Format-Table | Out-String)
2121
}
2222

src/jenv-local.psm1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ function Invoke-Local {
22
param(
33
[Parameter(Mandatory = $true)][object]$config,
44
[Parameter(Mandatory = $true)][boolean]$help,
5-
[Parameter(Mandatory = $true)][boolean]$output,
65
[Parameter(Mandatory = $true)][string]$name
76
)
87

@@ -11,7 +10,7 @@ function Invoke-Local {
1110
Write-Host 'This command allows you to specify a java version that will always be used in this folder and all subfolders'
1211
Write-Host 'This is overwriten by "jenv use"'
1312
Write-Host '<name> is the alias of the JEnv you want to specify'
14-
Write-Host Attention! You might have to call jenv first before it changes your JAVA_HOME to the local environment. The java command will work out of the box
13+
Write-Host "Attention! You might have to call jenv first before it changes your JAVA_HOME to the local environment. The java command will work out of the box"
1514
}
1615
else {
1716

@@ -34,7 +33,7 @@ function Invoke-Local {
3433
if ($jenv.path -eq (Get-Location)) {
3534
# if path is used replace with new version
3635
$jenv.name = $name
37-
Write-Output "Your replaced your java version for" (Get-Location) with $name
36+
Write-Output "Your replaced your java version for {0} {1}" -f (Get-Location), $name
3837
return
3938
}
4039
}
@@ -45,6 +44,6 @@ function Invoke-Local {
4544
name = $name
4645
}
4746

48-
Write-Output $name "is now your local java version for" (Get-Location)
47+
Write-Output "{0} is now your local java version for {1}" -f (Get-Location), $name
4948
}
5049
}

src/jenv-remove.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ function Invoke-Remove {
77

88
if ($help) {
99
Write-Host '"jenv remove" <name>'
10-
Write-Host 'With this command you can remove any java version you registered with "jenv add"'
11-
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
10+
Write-Host 'With this command you can remove any java version you registered with "jenv add"'
11+
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
1212
}
1313
else {
14-
# Remove the JEnv
14+
# Remove the JEnv
1515
$config.jenvs = @($config.jenvs | Where-Object { $_.name -ne $name })
1616
# Remove any jenv local with that name
1717
$config.locals = @($config.locals | Where-Object { $_.name -ne $name })

src/jenv-use.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function Invoke-Use {
88

99
if ($help) {
1010
Write-Host '"jenv use <name>"'
11-
Write-Host 'With this command you set your JAVA_HOME and the version of java to be used by your current shell session.'
12-
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
13-
Write-Host Careful this overwrites "jenv local"
11+
Write-Host 'With this command you set your JAVA_HOME and the version of java to be used by your current shell session.'
12+
Write-Host '<name> is the alias you asigned to the path with "jenv add <name> <path>"'
13+
Write-Host 'Careful this overwrites "jenv local"'
1414
}
1515
else {
1616

@@ -20,15 +20,15 @@ function Invoke-Use {
2020
if ($output) {
2121
Set-Content -path "jenv.use.tmp" -value "remove" # Create temp file so no restart of the active shell is required
2222
}
23-
Write-Host Your session JEnv was unset
23+
Write-Host "Your session JEnv was unset"
2424
return
2525
}
2626

2727

2828
# Check if specified JEnv is avaible
2929
$jenv = $config.jenvs | Where-Object { $_.name -eq $name }
3030
if ($null -eq $jenv) {
31-
Write-Host Theres no JEnv with name $name Consider using "jenv list"
31+
Write-Host 'Theres no JEnv with name {0} Consider using "jenv list"' -f $name
3232
return
3333
}
3434
else {
@@ -38,7 +38,7 @@ function Invoke-Use {
3838
Set-Content -path "jenv.home.tmp" -value $jenv.path # Create temp file so no restart of the active shell is required
3939
Set-Content -path "jenv.use.tmp" -value $jenv.path # Create temp file so no restart of the active shell is required
4040
}
41-
Write-Host JEnv changed for the current shell session. Careful this overwrites "jenv local"
41+
Write-Host 'JEnv changed for the current shell session. Careful this overwrites "jenv local"'
4242
}
4343
}
4444
}

src/jenv.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ param (
1919
"jenv local <name>" Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well
2020
#>
2121
[Parameter(Position = 0)][validateset("list", "add", "change", "use", "remove", "local", "getjava", "link")] [string]$action,
22-
22+
2323
# Displays this helpful message
2424
[Alias("h")]
2525
[Switch]$help,
@@ -63,7 +63,7 @@ if ($javaPaths.Length -gt 0) {
6363
[System.Environment]::SetEnvironmentVariable("PATH", $systemPath, [System.EnvironmentVariableTarget]::Machine) # Set globally
6464
}
6565
catch [System.Management.Automation.MethodInvocationException] {
66-
Write-Host JEnv wants to change your system environment vars. Therefore you need to restart it with administration rights. This should only once be required. If you dont want to, you have to call JEnv on every terminal opening to change your session vars
66+
Write-Host "JEnv wants to change your system environment vars. Therefore you need to restart it with administration rights. This should only once be required. If you dont want to, you have to call JEnv on every terminal opening to change your session vars"
6767
}
6868
$path = $userPath + ";" + $systemPath
6969

@@ -109,7 +109,7 @@ if (!($config | Get-Member global)) {
109109
$localname = ($config.locals | Where-Object { $_.path -eq (Get-Location) }).name
110110
$javahome = ($config.jenvs | Where-Object { $_.name -eq $localname }).path
111111
if ($null -eq $local) {
112-
$javahome = $config.global
112+
$javahome = $config.global
113113
}
114114
$Env:JAVA_HOME = $javahome # Set for powershell users
115115
if ($output) {
@@ -137,9 +137,9 @@ else {
137137
remove { Invoke-Remove $config $help @arguments }
138138
use { Invoke-Use $config $help $output @arguments }
139139
change { Invoke-Change $config $help $output @arguments }
140-
local { Invoke-Local $config $help $output @arguments }
141-
getjava { Get-Java $config }
142-
link { Invoke-Link $config $help @arguments }
140+
local { Invoke-Local $config $help @arguments }
141+
getjava { Get-Java $config }
142+
link { Invoke-Link $help @arguments }
143143
}
144144

145145
#region Save the config

0 commit comments

Comments
 (0)