-
Notifications
You must be signed in to change notification settings - Fork 389
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 -Path
parameter to Invoke-Formatter
#775
Comments
I had even no luck with Get-Content :-( |
@Kriegel You need to use the Invoke-Formatter -ScriptDefinition (Get-Content -Path 'C:\MyFile.ps1' -Raw) |
@bergmeister This works even fine fo me:
testing with VSCode ....... |
@Kriegel You're welcome. I had many cases in the past where |
I see that this issue has quite a few upvotes. Can anyone please provide details of a use case? Because VSCode has already integrated Invoke-Formatter, I do not understand why people want to use it this way, especially since using |
I can now live with Get-Content -Raw but it is ugly and was not intuitively to find out. I work often with code found on the Internet even with Modules which have more then one .ps1 file. Or you handover scripts from one Team to another ... without a -Path Parameter Invoke-Formatter seems to be intended to be used interactive in a Editor only and not made for automating (batch runs). Invoke-ScriptAnalyzer has a -Path Parameter as the main parameter so lets make the interfaces consistent. because we can.... |
@Kriegel Thanks for the feedback. This sounds more like we could at least document an automation snippet because gluing stuff together is what PowerShell is for. The reason why implementing this is hard is because the requirements (preservation of encoding, tabs/spaces) are quite difficult to achieve, I already struggled to preserve the encoding in all cases for the |
see: Default Encoding for PowerShell 6.0 is UTF-8 without a BOM except for New-ModuleManifest So i think to Support the UTF-8 without a BOM is enough, if the file is not of this encoding throw an Error and all is done. without batchfile Support Invoke-Formatter is in my Point of view a poor automating tool ... PRs ? Sorry I am IT-Pro no C-sharpy ... Offtopic: the support to create custom rules with PowerShell script code in this module project, is well hidden and bad documented. |
It's important to have a way to check if all files in a folder are formatted in CI, and fail the build if some are not. Every formatter I've used had this feature. Something like: Get-ChildItem -Recurse '*.ps*' |
Get-Content -Raw |
ForEach-Object { Compare-Object $_ (Invoke-Formatter -ScriptDefinition $_) } |
@felixfbecker You can, |
Hi. Regarding support for
Thank you :) |
@bergmeister I'm also upvoting on this issue, and here is the reason why current implementation of
I don't understand why anyone would like to want to retain anything as suggested in previous posts here, ie. indentation or encoding, these things should be configurable in Yes there is default formatter in VSCode but but it's not recursive, This issue is about -Path parameter, but if this is implemented then -Recurse should be implemented as well. both do the same thing anyway. |
@metablaster Invoke-Formatter has a Get-ChildItem -Recurse '*.ps*' |
ForEach-Object { Set-Content -Path $_.FullName -Value (Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path $_.FullName) ) } If you had the option: Would you prefer a |
I'll try out the option with I believe it's the same (depends on context) whether the recursive formatting is built into extension or into module, what matters is that there is a default way to actually do it when you need it. Maybe I'm wrong but |
The vs-code extension basically has individual settings for (most) settings of the formatting rules that you can specify in the psd1, therefore I consider them equivalent. People use the settings file usually for code analysis rules (same for the settingsPath setting in the extension), hence why having a |
I just want to input my discovery that might help some people. In VSCode use search function and search for word that is located inside ALL files, examples such as: Then simply use "replace all" to replace all occurrences of that word, and repeat it once again to revert of course. What will happen is that formatter will be invoked on your entry repository formatting all your scripts. Of course to minimize errors while doing so, add new comment into every script in your repository such as:
Now use search function and replace all occurrences with:
I find this so cool. |
Not everyone uses vscode, and I think people are used to having a formatter that can fix the files for you in other languages (eg: I think there is somewhat easy way to handle that: provide a new cmdlet named
Just a QoL wrapper that woudn't require any change to Invoke-Formatter, and people could use if they want. |
Invoke-Formatter
takes only aScriptDefinition
parameter. The user should be able to point the cmdlet to a file for formatting. However, the following things need to be preserved when formatting a file:{tab, space}
The text was updated successfully, but these errors were encountered: