Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Path and -LiteralPath parameters to Test-Json cmdlet #19042

Merged
merged 33 commits into from Feb 21, 2023

Conversation

ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Jan 27, 2023

PR Summary

Fixes #15544
Fixes #12882

Added -Path and -LiteralPath parameter to Test-Json cmdlet.

PR Context

Currently you can only pass a JSON string to Test-Json like so:

PS C:\> Test-Json -Json (Get-Content -Path data.json -Raw)

With this change you can now also pass a path:

PS C:\> Test-Json -Path data.json

Or with literal path:

PS C:\> Test-Json -LiteralPath '[data].json'

Which makes validating JSON from file paths much easier.

Current Syntax

Test-Json [-Json] <string> [<CommonParameters>]

Test-Json [-Json] <string> [[-Schema] <string>] [<CommonParameters>]

Test-Json [-Json] <string> [[-SchemaFile] <string>] [<CommonParameters>]

New Syntax

Test-Json [-Json] <string> [<CommonParameters>]

Test-Json [-Json] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-Json] <string> [-SchemaFile] <string> [<CommonParameters>]

Test-Json [-Path] <string> [<CommonParameters>]

Test-Json [-Path] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-Path] <string> [-SchemaFile] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [-SchemaFile] <string> [<CommonParameters>]

Which does introduce a Bucket 4 breaking change: https://github.com/PowerShell/PowerShell/blob/master/docs/dev-process/breaking-change-contract.md#bucket-4-clearly-non-public

But given changing parameter sets are not technically public API then it seemed fine to reorganize them to allow the new -Path parameter. If there is an easier way to do the parameter sets please let me know 馃槃.

PR Checklist

@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review January 27, 2023 13:46
@ArmaanMcleod ArmaanMcleod changed the title Add Path parameter to Test-Json Add -Path parameter to Test-Json cmdlet Jan 28, 2023
@ArmaanMcleod ArmaanMcleod changed the title Add -Path parameter to Test-Json cmdlet Add -Path and -LiteralPath parameters to Test-Json cmdlet Feb 2, 2023
@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review February 2, 2023 14:02
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Feb 2, 2023

@iSazonov Thanks for the feedback. I've included a -LiteralPath parameter and made both path parameters use ValueFromPipelineByPropertyName. Also cleaned up the extra whitspace and generate the test json files on the fly using TestDrive:/.

Let me know what you think, I think it looks much better already 馃槃.

@ArmaanMcleod
Copy link
Contributor Author

One strange thing I've noticed is if you do Get-ChildItem -Path '.markdownlint.json' -File | Test-Json, it will still set the path as a literal path from pipeline parameter binding.

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 4, 2023

One strange thing I've noticed is if you do Get-ChildItem -Path '.markdownlint.json' -File | Test-Json, it will still set the path as a literal path from pipeline parameter binding.

ValueFromPipelineByPropertyName and PSPath alias for LiteralPath work. It is expected behavior.

@iSazonov iSazonov added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Feb 4, 2023
@ArmaanMcleod ArmaanMcleod reopened this Feb 7, 2023
@ArmaanMcleod
Copy link
Contributor Author

Closed and Reopened to restart CI

@ArmaanMcleod ArmaanMcleod force-pushed the test-json-file-parameter branch 2 times, most recently from d2fbe31 to 707c135 Compare February 8, 2023 12:53
@pull-request-quantifier
Copy link

This PR has 155 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +144 -11
Percentile : 51%

Total files changed: 2

Change summary by file extension:
.cs : +59 -8
.ps1 : +85 -3

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 馃憤 馃憣 馃憥 (Email)
Customize PullRequestQuantifier for this repository.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@daxian-dbw daxian-dbw merged commit 0be3eea into PowerShell:master Feb 21, 2023
40 checks passed
@ArmaanMcleod ArmaanMcleod deleted the test-json-file-parameter branch February 21, 2023 19:55
@iSazonov
Copy link
Collaborator

@ArmaanMcleod Thanks for your contribution!

TravisEz13 pushed a commit to TravisEz13/PowerShell that referenced this pull request Feb 22, 2023
@msftbot
Copy link

msftbot bot commented Mar 14, 2023

馃帀v7.4.0-preview.2 has been released which incorporates this pull request.馃帀

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Medium WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test-Json : Add parameter for JSON data file Test-Json should have a -JsonFile parameter
3 participants