Skip to content

Commit 4b63e5c

Browse files
authored
prettier
1 parent f633147 commit 4b63e5c

19 files changed

+726
-516
lines changed

vscode-extension/PSA_custom_Rules/Alias/Get-AliasSpec.psm1

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ function Get-AliasSpec {
99
[ValidateNotNullOrEmpty()]
1010
$AliasPath
1111
)
12-
12+
1313
$aliasTocmdlets = Get-Content $AliasPath | ConvertFrom-Json
14-
14+
1515
return $aliasTocmdlets
1616
}
17-
Export-ModuleMember -Function Get-AliasSpec
17+
18+
Export-ModuleMember -Function Get-AliasSpec

vscode-extension/PSA_custom_Rules/Alias/avoidAlias.psm1

+10-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Measure-AvoidAlias {
2424
[System.Management.Automation.Language.ScriptBlockAst]
2525
$scriptAst
2626
)
27-
27+
2828
Process {
2929
$results = @()
3030
# import functions
@@ -39,7 +39,7 @@ function Measure-AvoidAlias {
3939

4040
# get the commandAst in the file
4141
$cmdletUsingAlias = Find-CmdletsInFile -RootAstNode $scriptAst
42-
42+
4343
#list of CorrectionExtents
4444
$corrections = (New-Object System.Collections.ObjectModel.Collection["Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent"])
4545

@@ -53,19 +53,18 @@ function Measure-AvoidAlias {
5353
[string]$CommandName = $cmdletReference.CommandName
5454
[string]$correction = $AliasSpec.cmdlet.($CommandName)
5555
[string]$filePath = $cmdletReference.FullPath
56-
[string]$optionalDescription =
56+
[string]$optionalDescription =
5757
"'$CommandName' is an alias of '$correction'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content."
5858

5959
$c = (New-Object Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent $startLineNumber, $endLineNumber, $startColumnNumber, $endColumnNumber, $correction, $filePath, $optionalDescription)
6060
$corrections.Add($c)
61-
6261
}
6362

6463
# If the cmdlet has one or more parameters having alias
65-
if ($AliasSpec.para_cmdlet.Psobject.Properties.Match($cmdletReference.CommandName).Count){
66-
foreach ($para in $cmdletReference.parameters){
64+
if ($AliasSpec.para_cmdlet.Psobject.Properties.Match($cmdletReference.CommandName).Count) {
65+
foreach ($para in $cmdletReference.parameters) {
6766
# If the cmdlet parameters list in alias spec contains the parameter
68-
if ($AliasSpec.para_cmdlet.($cmdletReference.CommandName).psobject.properties.match($para.Name).Count){
67+
if ($AliasSpec.para_cmdlet.($cmdletReference.CommandName).psobject.properties.match($para.Name).Count) {
6968
[int]$startLineNumber = $para.StartLine
7069
[int]$endLineNumber = $para.EndLine
7170
[int]$startColumnNumber = $para.StartColumn
@@ -74,7 +73,7 @@ function Measure-AvoidAlias {
7473
[string]$ParameterName = $para.Name
7574
[string]$correction = $AliasSpec.para_cmdlet.($CommandName).($ParameterName)
7675
[string]$filePath = $para.FullPath
77-
[string]$optionalDescription =
76+
[string]$optionalDescription =
7877
"'$ParameterName' is an alias of '$correction' in the cmdlet '$CommandName'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content."
7978

8079
$c = (New-Object Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent $startLineNumber, $endLineNumber, $startColumnNumber, $endColumnNumber, $correction, $filePath, $optionalDescription)
@@ -83,18 +82,16 @@ function Measure-AvoidAlias {
8382
}
8483
}
8584
}
86-
87-
8885

8986
$extent = $null
90-
87+
9188
#returned anaylse results
92-
$diagRecord = New-Object `
89+
$diagRecord = New-Object `
9390
-Typename "Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord" `
9491
-ArgumentList "This arugment is not used.", $extent, $PSCmdlet.MyInvocation.InvocationName, Warning, "MyRuleSuppressionID", $corrections
9592
$diagRecord.SuggestedCorrections = $corrections
9693
$results += $diagRecord
9794
return $results
9895
}
9996
}
100-
Export-ModuleMember -Function Measure*
97+
Export-ModuleMember -Function Measure*
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#generate the json file includes alias information
22

3-
$az_modules = Get-Module az.* -ListAvailable | Where-object {$_.Name -ne "Az.Tools.Migration"}
4-
for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
3+
$az_modules = Get-Module az.* -ListAvailable | Where-object { $_.Name -ne "Az.Tools.Migration" }
4+
for ([int]$i = 0; $i -lt $az_modules.Count; $i++) {
55
import-module $az_modules[$i].name
66
}
77

@@ -11,46 +11,41 @@ $matchPattern = "(\b[a-zA-z]+-?[a-zA-z]+\b)" # matches any alias
1111
$matchPatternFormalName = "(\b[a-zA-z]+-?[Az][a-zA-z]+\b)" # matches formal names of Az cmdlets
1212
$cmdletRegex = New-Object System.Text.RegularExpressions.Regex($matchPattern)
1313
$cmdletRegexFormal = New-Object System.Text.RegularExpressions.Regex($matchPatternFormalName)
14-
$aliasCmdlets = get-alias | where-object {$cmdletRegex.IsMatch($_.Name) -and $cmdletRegexFormal.IsMatch($_.ReferencedCommand.Name)}
14+
$aliasCmdlets = get-alias | where-object { $cmdletRegex.IsMatch($_.Name) -and $cmdletRegexFormal.IsMatch($_.ReferencedCommand.Name) }
1515

16-
for ([int]$i = 0; $i -lt $aliasCmdlets.Count; $i++){
16+
for ([int]$i = 0; $i -lt $aliasCmdlets.Count; $i++) {
1717
$aliasCmdlet = $aliasCmdlets[$i]
1818
$aliasResults[$aliasCmdlet.Name] = $aliasCmdlet.ReferencedCommand.Name
1919
}
2020

21-
class getBreakingchangeResult_paraCmdlet{
21+
class getBreakingchangeResult_paraCmdlet {
2222
[System.String] $Name
2323
[System.String] $TypeBreakingChange
2424
}
2525

26-
$results = @{
27-
}
26+
$results = @{}
2827

2928
$results["updateTime"] = Get-Date
3029
$results["cmdlet"] = $aliasResults
3130
$results["para_cmdlet"] = @{}
32-
3331
$results["updateTime"] = $results["updateTime"].ToString()
3432

35-
36-
37-
for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
38-
33+
for ([int]$i = 0; $i -lt $az_modules.Count; $i++) {
3934
# import-module $az_modules[$i].name
4035
$module = get-module $az_modules[$i].name
4136

4237
$exportedCmdlets = $module.ExportedCmdlets
4338

44-
foreach ($key in $exportedCmdlets.Keys){
39+
foreach ($key in $exportedCmdlets.Keys) {
4540
$Cmdlet = $exportedCmdlets[$key]
4641

4742
#attributes of parameters in cmdlet
4843
$results["para_cmdlet"][$Cmdlet.Name] = @{}
49-
50-
foreach ($parameter_key in $Cmdlet.Parameters.keys){
44+
45+
foreach ($parameter_key in $Cmdlet.Parameters.keys) {
5146
$parameter = $Cmdlet.Parameters[$parameter_key]
52-
53-
for ([int]$j = 0; $j -lt $parameter.Aliases.Count; $j++){
47+
48+
for ([int]$j = 0; $j -lt $parameter.Aliases.Count; $j++) {
5449
$paraAlias = $parameter.Aliases[$j]
5550
$paraFormal = $parameter_key
5651
$results["para_cmdlet"][$Cmdlet.Name][$paraAlias] = $paraFormal
@@ -60,5 +55,3 @@ for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
6055
}
6156
$json = $results | ConvertTo-Json -depth 10
6257
$json > AliasSpec.json
63-
64-

vscode-extension/PSA_custom_Rules/BreakingChange/Get-BreakingChangeSpec.psm1

+10-12
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,32 @@ function Get-BreakingChangeSpec {
99
[ValidateNotNullOrEmpty()]
1010
$BreakingChangePath
1111
)
12-
12+
1313
$breakingchange = Get-Content $BreakingChangePath | ConvertFrom-Json
1414

1515
$cmdletSet = @{}
16-
for ([int]$i = 0; $i -lt $breakingchange.cmdlet.Count; $i++){
16+
for ([int]$i = 0; $i -lt $breakingchange.cmdlet.Count; $i++) {
1717
$cmdlet = $breakingchange.cmdlet.Name[$i]
1818
$cmdletSet[$cmdlet] = $breakingchange.cmdlet.TypeBreakingChange[$i]
1919
}
20-
20+
2121
$cmdlet_para_set = @{}
22-
for ([int]$i = 0; $i -lt $breakingchange.para_cmdlet.Count; $i++){
23-
22+
for ([int]$i = 0; $i -lt $breakingchange.para_cmdlet.Count; $i++) {
23+
2424
$cmdlet = $breakingchange.para_cmdlet.CmdletName[$i]
25-
if ($cmdlet_para_set.Keys -notcontains $cmdlet){
25+
if ($cmdlet_para_set.Keys -notcontains $cmdlet) {
2626
$cmdlet_para_set[$cmdlet] = @()
2727
}
2828
$cmdlet_para_set[$cmdlet] += $breakingchange.para_cmdlet.Name[$i]
29-
3029
}
31-
32-
30+
3331
$breakingchanges = @{
34-
cmdlets = $cmdletSet;
32+
cmdlets = $cmdletSet;
3533
paraCmdlets = $cmdlet_para_set
3634
}
3735
$breakingchanges.paraCmdlets
3836

39-
4037
return $breakingchanges
4138
}
42-
Export-ModuleMember -Function Get-BreakingChangeSpec
39+
40+
Export-ModuleMember -Function Get-BreakingChangeSpec
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
#generate the json includes breaking change information
22

3-
#install-module azpreview
4-
5-
class breakingchangeResult{
3+
class breakingchangeResult {
64
[System.String] $Name
75
[System.String] $TypeBreakingChange
86
}
97

10-
class breakingchangeParaFunc{
8+
class breakingchangeParaFunc {
119
[System.String] $Name
1210
[System.String] $TypeBreakingChange
1311
[System.String] $FuncName
1412
}
1513

16-
class breakingchangeParaCmdlet{
14+
class breakingchangeParaCmdlet {
1715
[System.String] $Name
1816
[System.String] $TypeBreakingChange
1917
[System.String] $CmdletName
2018
}
2119

22-
$results = @{
23-
}
20+
$results = @{}
2421

2522
$results["updateTime"] = Get-Date
2623
$results["func"] = @()
2724
$results["cmdlet"] = @()
2825
$results["para_func"] = @()
2926
$results["para_cmdlet"] = @()
3027

31-
$results["updateTime"] = $results["updateTime"].ToString()
28+
$results["updateTime"] = $results["updateTime"].ToString()
3229

33-
$az_modules = Get-Module az.* -ListAvailable | Where-object {$_.Name -ne "Az.Tools.Migration"}
30+
$az_modules = Get-Module az.* -ListAvailable | Where-object { $_.Name -ne "Az.Tools.Migration" }
3431

35-
for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
32+
for ([int]$i = 0; $i -lt $az_modules.Count; $i++) {
3633

37-
3834
import-module $az_modules[$i].name
3935
$module = get-module $az_modules[$i].name
4036

4137
$exportedFunctions = $module.ExportedFunctions
4238
$exportedCmdlets = $module.ExportedCmdlets
4339

44-
45-
foreach ($key in $exportedFunctions.Keys){
40+
foreach ($key in $exportedFunctions.Keys) {
4641
$func = $exportedFunctions[$key]
47-
42+
4843
#attributes of functions
49-
foreach ($Attribute in $func.ScriptBlock.Attributes){
50-
51-
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute"){
44+
foreach ($Attribute in $func.ScriptBlock.Attributes) {
45+
46+
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute") {
5247
#$Attribute.TypeId.Name
5348
$result = New-Object -TypeName breakingchangeResult
5449
$result.Name = $func.name
@@ -58,11 +53,11 @@ for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
5853
}
5954

6055
#attributes of parameters in function
61-
foreach ($parameter_key in $func.Parameters.keys){
56+
foreach ($parameter_key in $func.Parameters.keys) {
6257
$parameter = $func.Parameters[$parameter_key]
63-
for ([int]$k = 0; $k -lt $parameter.Attributes.Count; $k++){
58+
for ([int]$k = 0; $k -lt $parameter.Attributes.Count; $k++) {
6459
$Attribute = $parameter.Attributes[$k]
65-
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute"){
60+
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute") {
6661
#$Attribute.TypeId.Name
6762
$result = New-Object -TypeName breakingchangeParaFunc
6863
$result.Name = $parameter_key
@@ -74,12 +69,12 @@ for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
7469
}
7570
}
7671

77-
foreach ($key in $exportedCmdlets.Keys){
72+
foreach ($key in $exportedCmdlets.Keys) {
7873
$Cmdlet = $exportedCmdlets[$key]
7974

8075
#attributes of cmdlets
81-
foreach ($Attribute in $Cmdlet.ImplementingType.CustomAttributes){
82-
if ($Attribute.AttributeType.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.AttributeType.Name -eq "GenericBreakingChangeAttribute"){
76+
foreach ($Attribute in $Cmdlet.ImplementingType.CustomAttributes) {
77+
if ($Attribute.AttributeType.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.AttributeType.Name -eq "GenericBreakingChangeAttribute") {
8378
#$Attribute.AttributeType.Name
8479
$result = New-Object -TypeName breakingchangeResult
8580
$result.Name = $Cmdlet.Name
@@ -89,11 +84,11 @@ for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
8984
}
9085

9186
#attributes of parameters in cmdlet
92-
foreach ($parameter_key in $Cmdlet.Parameters.keys){
87+
foreach ($parameter_key in $Cmdlet.Parameters.keys) {
9388
$parameter = $Cmdlet.Parameters[$parameter_key]
94-
for ([int]$k = 0; $k -lt $parameter.Attributes.Count; $k++){
89+
for ([int]$k = 0; $k -lt $parameter.Attributes.Count; $k++) {
9590
$Attribute = $parameter.Attributes[$k]
96-
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute"){
91+
if ($Attribute.TypeId.BaseType.Name -eq "GenericBreakingChangeAttribute" -or $Attribute.TypeId.Name -eq "GenericBreakingChangeAttribute") {
9792
# $Attribute.TypeId.Name
9893
$result = New-Object -TypeName breakingchangeParaCmdlet
9994
$result.Name = $parameter_key
@@ -103,14 +98,7 @@ for ([int]$i = 0; $i -lt $az_modules.Count; $i++){
10398
}
10499
}
105100
}
106-
107-
108101
}
109-
110-
111-
112102
}
113103
$json = $results | ConvertTo-Json
114104
$json > BreakingchangeSpec.json
115-
116-

vscode-extension/PSA_custom_Rules/BreakingChange/upcomingBreakingChange.psm1

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.SYNOPSI
55
Give the tips in the upcoming breaking change places that there will be changes in the upcoming feature.
66
.DESCRIPTION
7-
Find all breaking change cmdlets or parameters that appear in the powershell script.
7+
Find all breaking change cmdlets or parameters that appear in the powershell script.
88
And give the tips that there will be changes in the feature and which breaking change there will be.
99
.EXAMPLE
1010
Measure-UpcomingBreakingChange -ScriptBlockAst $ScriptBlockAst
@@ -25,7 +25,7 @@ function Measure-UpcomingBreakingChange {
2525
[System.Management.Automation.Language.ScriptBlockAst]
2626
$scriptAst
2727
)
28-
28+
2929
Process {
3030
$results = @()
3131
# import functions
@@ -49,7 +49,6 @@ function Measure-UpcomingBreakingChange {
4949

5050
$corrections = (new-object System.Collections.ObjectModel.Collection["Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent"])
5151

52-
5352
foreach ($cmdletReference in $cmdletBreakingchange) {
5453
if ($breakingchanges.cmdlets.Keys -contains $cmdletReference.CommandName) {
5554
$type = $breakingchanges.cmdlets[$cmdletReference.CommandName]
@@ -110,11 +109,9 @@ function Measure-UpcomingBreakingChange {
110109
}
111110
}
112111
}
113-
114-
115112

116113
$extent = $null
117-
114+
118115
$diagRecord = New-Object `
119116
-Typename "Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord" `
120117
-ArgumentList "This arugment is not used.", $extent, $PSCmdlet.MyInvocation.InvocationName, Warning, "MyRuleSuppressionID", $corrections
@@ -123,4 +120,4 @@ function Measure-UpcomingBreakingChange {
123120
return $results
124121
}
125122
}
126-
Export-ModuleMember -Function Measure*
123+
Export-ModuleMember -Function Measure*

0 commit comments

Comments
 (0)