Skip to content

Commit

Permalink
tip: Add tip about defining array items on new lines without commas
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlydog committed Sep 23, 2023
1 parent d4ffa50 commit f91b076
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$tip = [tiPS.PowerShellTip]::new()
$tip.CreatedDate = [DateTime]::Parse('2023-09-23')
$tip.Title = 'Define hardcoded array items on new lines without commas'
$tip.TipText = @'
When defining hardcoded arrays with many values in PowerShell, you can define each item on a new line without commas. This makes it easier to read and maintain the array items, and you don't have to worry about commas when adding or rearranging items.
If you choose to define multiple array values on a single line, then you will need a comma between each item on the line.
'@
$tip.Example = @'
[string[]] $stringArray = @(
'Notice that each item is on a new line without commas.'
'This is much easier to read and maintain.'
'And you can add comments to explain each item if needed.' # Like this.
)
[int[]] $intArray = @(1, 2, 3)
'@
$tip.Urls = @(
'https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.3#create-an-array'
)
$tip.MinPowerShellVersion = '0.0'
$tip.Category = [tiPS.TipCategory]::Syntax # Community, Editor, Module, NativeCmdlet, Performance, Syntax, Terminal, or Other.
11 changes: 11 additions & 0 deletions src/tiPS/PowerShellTips.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@
"MinPowerShellVersion": "0.0",
"Category": 4
},
{
"CreatedDate": "2023-09-23T00:00:00",
"Title": "Define hardcoded array items on new lines without commas",
"TipText": "When defining hardcoded arrays with many values in PowerShell, you can define each item on a new line without commas. This makes it easier to read and maintain the array items, and you don't have to worry about commas when adding or rearranging items.\r\n\r\nIf you choose to define multiple array values on a single line, then you will need a comma between each item on the line.",
"Example": "[string[]] $stringArray = @(\r\n 'Notice that each item is on a new line without commas.'\r\n 'This is much easier to read and maintain.'\r\n 'And you can add comments to explain each item if needed.' # Like this.\r\n)\r\n\r\n[int[]] $intArray = @(1, 2, 3)",
"Urls": [
"https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.3#create-an-array"
],
"MinPowerShellVersion": "0.0",
"Category": 5
},
{
"CreatedDate": "2023-09-23T00:00:00",
"Title": "Use $PSVersionTable to get PowerShell session info",
Expand Down

0 comments on commit f91b076

Please sign in to comment.