Open jessehouwing opened 1 year ago
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.
@SydneyhSmith which existing rule would be a good basis to use to build this from?
@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: https://github.com/PowerShell/PSScriptAnalyzer/pull/1857
Summary of the new feature
When you call
get-content file.json | convertfrom-json
, funny things happen whenfile.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 toconvertfrom-*
, PSScriptAnalyzer should suggest adding-raw
toget-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