Better handling of CRLF
As discussed in Styra community Slack there is an issue with the opa-fmt rule, Windows' line endings and IDEs like VS Code that automatically changes line endings.
Regal shows a warning when the file contains CRLF line endings. Running opa fmt through the IDE does not fix the warning because when opa fmt outputs LF line endings the IDE automatically changes the LF line endings to CRLF line endings.
Users can usually fix this quite easily by configuring their IDE to use LF endings, but the the problem of CRLF line endings is not obvious for users to begin with. It would be nice if Regal could somehow let the user know about the issue with CRLF line endings.
I have two ideas on how this could be improved:
- Update the current warning message to include a note about
CRLF. Maybe the message could be dynamic and only include a note aboutCRLFif such endings are found in the file? - or a new Regal rule to warn about
CRLFendings
Thanks @asleire!
Thinking more about this, I think we could interecept the "will save document" event in the language server, and send back a notice (modal) to the client about disabling CRLF (or what have you) line endings if encountered in the document. We should only do that if the opa-fmt rule is enabled though, as otherwise we shouldn't interfer with whatever choices the user has made. What do you think?
As a side note — one way to avoid having editors mess with this is to use an .editorconfig file at the project root, specifically for Rego. We do this in Regal, although we share the same config for both Rego and Go (as they follow the same conventions in this regard): https://github.com/StyraInc/regal/blob/main/.editorconfig
I'm not sure VS Code uses this file without custom extensions, but GitHub and IntellJ certainly do.
I think we could interecept the "will save document" event in the language server, and send back a notice (modal) to the client about disabling CRLF
That sounds great!
As a side note — one way to avoid having editors mess with this is to use an .editorconfig file at the project root, specifically for Rego
Yes, it shouldn't be difficult in most IDEs to use LF endings