-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IgnoreComments
and AllowTrailingCommas
options to Test-Json
cmdlet
#23817
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why WG suggest Option
as array for new parameter.
The cmdlet uses JsonNode.Parse with default JsonDocumentOption for parsing.
The JsonDocumentOption
has only 3 fields and it's unbelievable that this number of parameters will be increased significantly in the future. So it would be more convenient for us to just add new individual parameters to this cmdlet as AllowTrailingCommas
, CommentHandling
and maybe MaxDepth
.
[Parameter] | ||
[ValidateNotNullOrEmpty] | ||
[ValidateSet("IgnoreComments", "AllowTrailingCommas")] | ||
public string[] Option { get; set; } = Array.Empty<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ValidateSet
really work for array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is an array should it be Options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make parameter names plural though? E.g. in other cmdlets we have -ComputerName
which is singular but can accept an array. I thought powershell recommendation for consistency is to have all array parameters use singular names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion but:
gcm -ParameterName Option
Get-Command: No matching commands include a parameter named 'Option'. Check the spelling of the parameter name, and then try again. (Parameter 'Option')
gcm -ParameterName Options
CommandType Name Version Source
----------- ---- ------- ------
Function TabExpansion2
Cmdlet Enter-PSSession 7.5.0.0 Microsoft.PowerShell.Core
Cmdlet Invoke-Command 7.5.0.0 Microsoft.PowerShell.Core
Cmdlet New-PSSession 7.5.0.0 Microsoft.PowerShell.Core
Cmdlet Start-Job 7.5.0.0 Microsoft.PowerShell.Core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking @iSazonov. In that case I will make the change as it will be consistent with existing powershell cmdlets.
@iSazonov Yeah that was my thought as well. Given number of existing options is not much maybe converting all above options to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[Parameter] | ||
[ValidateNotNullOrEmpty] | ||
[ValidateSet("IgnoreComments", "AllowTrailingCommas")] | ||
public string[] Option { get; set; } = Array.Empty<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PowerShell/wg-powershell-cmdlets discussed this. The proposal for an array is that if newer options appear in the future, we don't end up with lots of different switches and having an array groups them making it clear these are options for non-standard JSON. |
PR Summary
Fixes #20782
Added
IgnoreComments
andAllowTrailingCommas
options toTest-Json -Option
.PR Context
Currently with `Test-Json it does not allow comments and trailing commas.
Given the cmdlet uses
System.Text.Json
we can useJsonDocumentOptions
to includeCommentHandling
andAllowTrailingCommas
.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).