sancarn / stdVBA

VBA Standard Library - A Collection of libraries to form a common standard layer for modern VBA applications.
MIT License
293 stars 58 forks source link

Enforce line ending conversions + Renormalization #77

Closed DecimalTurn closed 1 year ago

DecimalTurn commented 1 year ago

Currently, the README states that contributors should "Ensure lines end in \r\n and not \n only". However, there are currently some inconsistencies in the repo with certain files using \n (LF) only.

With this PR, I'm adding a Git filter for .bas, .frm and .cls files, so that the conversion to \r\n (CRLF) is automatic. This filter is applied to files via the .gitattributes. I'm using -text which tells Git to stop its usual behavior for text file (converting to LF) and we add the filter crlf.

For the filter to be enabled on your machine, simply run git config include.path ../.gitconfig (while insde the repo). This will add the common .gitconfig to your local CONFIG file and give it access to the crlf filter definition. The definition is quite simple: it's using the command unix2dos to make the conversion. That command comes with Git-for-Windows and is usually available by default on the main Linux distributions.

I've also taken the opportunity to put in place a default normalization to LF for other files in the repo with an exception for .ahk files. This is optional, but it's generally good practice for GitHub projects. If you deem this approach unsuitable for this repo, I can always revert the commits related to that change.

Note that most of the changes in this PR are line renormalizations. You can confirm that by adding ?w=1 to the url of the Files changed tab. The real changes that would need review are located in these files:

sancarn commented 1 year ago

Hi @DecimalTurn, This is very cool! Was actually looking initially to see if this could be done with github actions, but never knew about these git filters. Do you know if it also works with github desktop etc?

DecimalTurn commented 1 year ago

Do you know if it also works with github desktop etc?

I just tested with GitHub Desktop to commit a .bas file with LF line endings and it did perform the conversion during the staging process.

Was actually looking initially to see if this could be done with github actions

It might still be good to use GitHub Actions to be sure no LF-only files sneaks in when a contributor forgets to add the .gitconfig file to their local configs.

DecimalTurn commented 3 months ago

@sancarn - Even if the git filter works, it creates a bit of overhead when committing which starts to be perceptible with large VBA repos. For that reason, I've decided to make a GitHub Action (Enforce-CRLF) and ran it successfully on my fork (logs).

If you are interested in using it, let me know and I can make a PR to add it and remove the mentions of git filter.

sancarn commented 3 months ago

@DecimalTurn That would be great thanks, I was thinking an action would be a good idea also when I initially came across this issue, thanks for developing 👍 Would love a PR