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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule request: Get-Content x | ConvertFrom-Json should suggest adding -raw for Get-content #1951

Open
jessehouwing opened this issue Nov 23, 2023 · 3 comments

Comments

@jessehouwing
Copy link

Summary of the new feature

When you call get-content file.json | convertfrom-json, funny things happen when file.json contains a comment at the top of the file.

Multiple places suggest that it's better to use get-content -raw for performance and predictability.

See:

Proposed technical implementation details (optional)

When get-content is piped to convertfrom-*, PSScriptAnalyzer should suggest adding -raw to get-content.

The same could apply to [xml] get-content file.xml.

What is the latest version of PSScriptAnalyzer at the point of writing

1.21

@SydneyhSmith
Copy link
Collaborator

Thanks for the suggestion @jessehouwing this would make a good custom rule, or this seems like the kind of thing that could be good for a feedback provider. Typically we don't add things into script analyzer that are code optimizers or work arounds. I will mark this as up for grabs if you want to try opening a PR for it.

@jessehouwing
Copy link
Author

@SydneyhSmith which existing rule would be a good basis to use to build this from?

@bergmeister
Copy link
Collaborator

@jessehouwing See here for docs around custom rules: https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/create-custom-rule?view=ps-modules
I kind of agree that we shouldn't add too many cmdlet specific rules but if this one is common, we could consider it, Here is a good, similar example: #1857

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants