-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
Fix Powershell Formatter appending new line #2239
Conversation
Isn't it a good practice to finish a code file with a new line ? |
@nvuillam You didn't understand me, if I don't do this PR, EVERY TIME the linter is executed, it adds a new line, that is, if I execute it 3 times, it adds 3 lines at the end. Look at the documentation I posted for |
Oh that's awful |
Codecov Report
@@ Coverage Diff @@
## main #2239 +/- ##
==========================================
+ Coverage 82.60% 83.11% +0.51%
==========================================
Files 170 170
Lines 4484 4484
==========================================
+ Hits 3704 3727 +23
+ Misses 780 757 -23
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@nvuillam so what do we do? We leave the value of
Edit: In fact, this PR is more than important because I see that if for whatever reason the command fails, it pipes anyway and replaces the file content with empty content, but with this PR, it does not continue executing the code. |
powrshell version in MegaLinter is currently 7.3.1 -> https://megalinter.io/beta/descriptors/powershell_powershell_formatter/ Of there is an awful bug adding a new lint at each formatting, indeed it's better to never add it :) |
And everybody probably uses UTF8, but you could add a new variable POWERSHELL_OUTPUT_ENCODING with default utf8, that users could override (and you can get the value of this var in PowershellLinter.py ) |
…megalinter into fix/powershell-formatter
@nvuillam done |
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.
Great <3
Right now every time the formatter is run, it adds a new line break.
This PR fixes it:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-5.1#-nonewline
I have the doubt @nvuillam @Kurt-von-Laven @echoix of the file encoding....
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-5.1#-encoding
The Out-File command does not preserve the encoding and you have to pass one... Right now I'm passing it in this PR utf8 but I don't know if it's something that should be at least configurable....
Edit: I have not put "default" to the value of encoding because in more recent versions, it does not exist: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.3#-encoding
Which in fact, now I don't know what version of powershell is used in Megalinter, so that's the first thing to find out.