Skip to content

Commit de4f5bd

Browse files
committed
More cleanup and Sort
1 parent 1455128 commit de4f5bd

File tree

1 file changed

+149
-137
lines changed

1 file changed

+149
-137
lines changed

snippets/PowerShell.json

+149-137
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,74 @@
4949
"}"
5050
]
5151
},
52+
"Class Method": {
53+
"prefix": "class-method",
54+
"description": "Defines the actions that a class can perform. Methods may take parameters that provide input data. Methods can return output. Data returned by a method can be any defined data type. More: Get-Help about_Classes",
55+
"body": [
56+
"[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {",
57+
"\t${0:${TM_SELECTED_TEXT:<# Action to perform. You can use $$this to reference the current instance of this class #>}}",
58+
"}"
59+
]
60+
},
61+
// Pester is no longer bundled with PowerShell Core, but is available as a NuGet package.
62+
// "PesterContext": {
63+
// "prefix": "Context-Pester",
64+
// "description": "Pester - Context block",
65+
// "body": [
66+
// "Context \"${1:ContextName}\" {",
67+
// "\t${0:$TM_SELECTED_TEXT}",
68+
// "}"
69+
// ]
70+
// },
71+
// "PesterContextIt": {
72+
// "prefix": "Context-It-Pester",
73+
// "description": "Pester - Context block with nested It block",
74+
// "body": [
75+
// "Context \"${1:ContextName}\" {",
76+
// "\tIt \"${2:ItName}\" {",
77+
// "\t\t${3:${TM_SELECTED_TEXT:Assertion}}",
78+
// "\t}$0",
79+
// "}"
80+
// ]
81+
// },
82+
// "PesterDescribeBlock": {
83+
// "prefix": "Describe-Pester",
84+
// "description": "Pester Describe block",
85+
// "body": [
86+
// "Describe \"${1:DescribeName}\" {",
87+
// "\t${0:TM_SELECTED_TEXT}",
88+
// "}"
89+
// ]
90+
// },
91+
// "PesterDescribeContextIt": {
92+
// "prefix": "Describe-Context-It-Pester",
93+
// "description": "Pester Describe block with nested Context & It blocks",
94+
// "body": [
95+
// "Describe \"${1:DescribeName}\" {",
96+
// "\tContext \"${2:ContextName}\" {",
97+
// "\t\tIt \"${3:ItName}\" {",
98+
// "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}",
99+
// "\t\t}$0",
100+
// "\t}",
101+
// "}"
102+
// ]
103+
// },
104+
// "PesterIt": {
105+
// "prefix": "It-Pester",
106+
// "description": "Pester - It block",
107+
// "body": [
108+
// "It \"${1:ItName}\" {",
109+
// "\t${2:${TM_SELECTED_TEXT:Assertion}}",
110+
// "}$0"
111+
// ]
112+
// },
113+
"Class Property": {
114+
"prefix": "class-property",
115+
"description": "Properties are variables declared at class scope. A property may be of any built-in type or an instance of another class. Classes have no restriction in the number of properties they have. More: Get-Help about_Classes",
116+
"body": [
117+
"[${1:propertyType}] $${0:PropertyName}"
118+
]
119+
},
52120
"Comment Block": {
53121
"prefix": [
54122
"block-comment"
@@ -610,6 +678,19 @@
610678
"}"
611679
]
612680
},
681+
"Function: Suppress PSScriptAnalyzer Rule": {
682+
"prefix": [
683+
"suppress-message-rule-function",
684+
"[SuppressMessageAttribute]"
685+
],
686+
"description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
687+
"body": [
688+
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(",
689+
"\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',",
690+
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
691+
")]"
692+
]
693+
},
613694
"Hashtable": {
614695
"prefix": "Hashtable",
615696
"description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables",
@@ -619,9 +700,35 @@
619700
"}"
620701
]
621702
},
703+
"Here-String": {
704+
"prefix": [
705+
"hs",
706+
"here-string"
707+
],
708+
"description": "Escape all text but evaluate variables. More: Get-Help about_Quoting_Rules",
709+
"body": [
710+
"@\"",
711+
"${0:TM_SELECTED_TEXT}",
712+
"\"@",
713+
""
714+
]
715+
},
716+
"Here-String (Literal)": {
717+
"prefix": [
718+
"hsl",
719+
"literal-here-string"
720+
],
721+
"description": "Escape all text regardless. More: Get-Help about_Quoting_Rules",
722+
"body": [
723+
"@'",
724+
"${0:TM_SELECTED_TEXT}",
725+
"'@",
726+
""
727+
]
728+
},
622729
"Hidden Property": {
623730
"prefix": "class-proph-hidden",
624-
"description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: about_Hidden",
731+
"description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: Get-Help about_Hidden",
625732
"body": [
626733
"hidden [${1:string}] $${0:PropertyName}"
627734
]
@@ -665,15 +772,6 @@
665772
"}"
666773
]
667774
},
668-
"Method": {
669-
"prefix": "method",
670-
"description": "Class method definition snippet",
671-
"body": [
672-
"[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {",
673-
"\t${0:$TM_SELECTED_TEXT}",
674-
"}"
675-
]
676-
},
677775
"ModuleManifest": {
678776
"prefix": "manifest",
679777
"description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.",
@@ -835,9 +933,22 @@
835933
"$${3:ParameterName}$0"
836934
]
837935
},
936+
"Parameter: Suppress PSScriptAnalyzer Rule": {
937+
"prefix": [
938+
"suppress-message-rule-parameter",
939+
"[SuppressMessageAttribute]"
940+
],
941+
"description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
942+
"body": [
943+
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',",
944+
"\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}",
945+
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
946+
")]"
947+
]
948+
},
838949
"Pipeline Function": {
839950
"prefix": "function-pipeline",
840-
"description": "Basic function that accepts pipeline input \nReference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2",
951+
"description": "Basic function that accepts pipeline input. More: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2",
841952
"body": [
842953
"function $1 {",
843954
" [CmdletBinding()]",
@@ -851,68 +962,12 @@
851962
"}"
852963
]
853964
},
854-
// Pester is no longer bundled with PowerShell Core, but is available as a NuGet package.
855-
// "PesterContext": {
856-
// "prefix": "Context-Pester",
857-
// "description": "Pester - Context block",
858-
// "body": [
859-
// "Context \"${1:ContextName}\" {",
860-
// "\t${0:$TM_SELECTED_TEXT}",
861-
// "}"
862-
// ]
863-
// },
864-
// "PesterContextIt": {
865-
// "prefix": "Context-It-Pester",
866-
// "description": "Pester - Context block with nested It block",
867-
// "body": [
868-
// "Context \"${1:ContextName}\" {",
869-
// "\tIt \"${2:ItName}\" {",
870-
// "\t\t${3:${TM_SELECTED_TEXT:Assertion}}",
871-
// "\t}$0",
872-
// "}"
873-
// ]
874-
// },
875-
// "PesterDescribeBlock": {
876-
// "prefix": "Describe-Pester",
877-
// "description": "Pester Describe block",
878-
// "body": [
879-
// "Describe \"${1:DescribeName}\" {",
880-
// "\t${0:TM_SELECTED_TEXT}",
881-
// "}"
882-
// ]
883-
// },
884-
// "PesterDescribeContextIt": {
885-
// "prefix": "Describe-Context-It-Pester",
886-
// "description": "Pester Describe block with nested Context & It blocks",
887-
// "body": [
888-
// "Describe \"${1:DescribeName}\" {",
889-
// "\tContext \"${2:ContextName}\" {",
890-
// "\t\tIt \"${3:ItName}\" {",
891-
// "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}",
892-
// "\t\t}$0",
893-
// "\t}",
894-
// "}"
895-
// ]
896-
// },
897-
// "PesterIt": {
898-
// "prefix": "It-Pester",
899-
// "description": "Pester - It block",
900-
// "body": [
901-
// "It \"${1:ItName}\" {",
902-
// "\t${2:${TM_SELECTED_TEXT:Assertion}}",
903-
// "}$0"
904-
// ]
905-
// },
906-
"Property": {
907-
"prefix": "prop",
908-
"description": "Class property definition snippet",
909-
"body": [
910-
"[${1:string}] $${0:PropertyName}"
911-
]
912-
},
913965
"PSCustomObject": {
914-
"prefix": "[PSCustomObject]",
915-
"description": "Creates a PSCustomObject",
966+
"prefix": [
967+
"pscustomobject",
968+
"[PSCustomObject]"
969+
],
970+
"description": "Create a custom object from a hashtable of properties. More: Get-Help about_PSCustomObject",
916971
"body": [
917972
"[PSCustomObject]@{",
918973
"\t${1:Name} = ${2:Value}",
@@ -928,44 +983,37 @@
928983
"#endregion"
929984
]
930985
},
931-
"Suppress PSScriptAnalyzer Rule": {
932-
"prefix": "suppress-message-rule",
933-
"description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
934-
"body": [
935-
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(",
936-
"\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,",
937-
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
938-
")]"
939-
]
940-
},
941-
"Suppress PSScriptAnalyzer Rule in Function": {
942-
"prefix": "suppress-message-rule-function",
943-
"description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
986+
"Scope: Suppress PSScriptAnalyzer Rule": {
987+
"prefix": "suppress-message-rule-scope",
988+
"description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
944989
"body": [
945990
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(",
946-
"\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',",
947-
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
991+
"\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',",
992+
"\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'",
993+
"\tJustification = '${0:Reason for suppressing}}'",
948994
")]"
949995
]
950996
},
951-
"Suppress PSScriptAnalyzer Rule on Parameter": {
952-
"prefix": "suppress-message-rule-parameter",
953-
"description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
997+
"splat": {
998+
"prefix": "splat",
999+
"description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting",
9541000
"body": [
955-
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',",
956-
"\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}",
957-
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
958-
")]"
1001+
"$${1/[^\\w]/_/}Params = @{",
1002+
"\t${2:Parameter} = ${0:Value}",
1003+
"}",
1004+
"${1:${TM_SELECTED_TEXT}} @${1/[^\\w]/_/}Params"
9591005
]
9601006
},
961-
"Suppress PSScriptAnalyzer Rule on a specific Scope": {
962-
"prefix": "suppress-message-rule-scope",
963-
"description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
1007+
"Suppress PSScriptAnalyzer Rule": {
1008+
"prefix": [
1009+
"suppress-message-rule",
1010+
"[SuppressMessageAttribute]"
1011+
],
1012+
"description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules",
9641013
"body": [
9651014
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(",
966-
"\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',",
967-
"\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'",
968-
"\tJustification = '${0:Reason for suppressing}}'",
1015+
"\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,",
1016+
"\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'",
9691017
")]"
9701018
]
9711019
},
@@ -1027,47 +1075,11 @@
10271075
},
10281076
"while": {
10291077
"prefix": "while",
1030-
"description": "Repeatedly perform an action after verifying a condition is true first.",
1078+
"description": "Repeatedly perform an action after verifying a condition is true first. More: Get-Help about_While",
10311079
"body": [
10321080
"while (${1:condition}) {",
10331081
"\t${0:$TM_SELECTED_TEXT}",
10341082
"}"
10351083
]
1036-
},
1037-
"splat": {
1038-
"prefix": "splat",
1039-
"description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting",
1040-
"body": [
1041-
"$${1/[^\\w]/_/}Params = @{",
1042-
"\t${2:Parameter} = ${0:Value}",
1043-
"}",
1044-
"${1:${TM_SELECTED_TEXT}} @${1/[^\\w]/_/}Params"
1045-
]
1046-
},
1047-
"Here-String": {
1048-
"prefix": [
1049-
"hs",
1050-
"here-string"
1051-
],
1052-
"body": [
1053-
"@\"",
1054-
"${0:TM_SELECTED_TEXT}",
1055-
"\"@",
1056-
""
1057-
],
1058-
"description": "Escape all text but evaluate variables. More: Get-Help about_Quoting_Rules"
1059-
},
1060-
"Here-String (Literal)": {
1061-
"prefix": [
1062-
"hsl",
1063-
"literal-here-string"
1064-
],
1065-
"body": [
1066-
"@'",
1067-
"${0:TM_SELECTED_TEXT}",
1068-
"'@",
1069-
""
1070-
],
1071-
"description": "Escape all text regardless. More: Get-Help about_Quoting_Rules"
10721084
}
10731085
}

0 commit comments

Comments
 (0)