This Pull Request is part of an academic research project. More preciously it is for my master's thesis, more background information here.
Definition: EditorConfig violations
The goal of this Pull Request is to address all EditorConfig violations in the project. With EditorConfig you have set for example trim_trailing_whitespace = true for most files, but there were files with trailing spaces. I call this an EditorConfig violation as a file content violates the respective EditorConfig property. They can have different kind of impacts. For example trailing spaces, which get remove with the next save, may make the next diff / Pull Request to this file less readable. Some other, like a mixture of tabs and spaces for indentation, can make code much harder to read. Like in this code block of your documentation
here (fixed with this PR).
How to address them?
To check for such violations and fix them I developed the CLI tool ecformat. However, there are different ways to address the violations:
- Adjust EditorConfig: The EditorConfig properties for a file can be wrong. For example, you have to use tab characters for indentations
in a Makefile for correct syntax. Therefore, replacing these tabs with spaces would break it. The correct way to address that is to set indent_style = tab for them, which ensure that that tabs are used for indentations.
- Fix file content: Another way is to fix the content of the file. Which means for example for
trim_trailing_whitespace = true to remove trailing spaces. To do so ecformat fix can be helpful.
- Ignore files: For some files it is not meaningful to consider the EditorConfig violations, which
ecformat check finds. I added a .ecformat_ignore file for this. It has the common ignore syntax such as a .gitignore. To use such ignore files, provide the name of them with an CLI switch, ecformat check --ignore-file .ecformat_ignore. (The .gitignore files are automatically considered inside a git repository.) There are different reasons to ignore files:
- As EditorConfig is only for text files, considering binary files does not make sense.
- EditorConfig supports to set the property on the file level. However, there can be files with intentional differences inside. Such files need to be ignored fully by
ecformat as it currently (version 0.2.0) has no support to ignore only a single property for some files. (There were no such cases in this project.)
Changes in this Pull Request
For this Pull Request, I addressed the violations in the project in the way, which looks the most correct one to me. (I focused on the Properties of the current EditorConfig specification 0.17.2.) If I fixed file contents, I manually reviewed all of them, making adjustments in the ecformat fix changes were necessary.
The only remaining violation is in the file contrib/openrc/mitra. It uses tab characters for indentation and not spaces as set for all files with EditorConfig. Do not know anything about this special file format. Therefore, I am not sure if it is safe to replace the tabs with spaces or if that can break anything. Please let me know if I should fix the file content or adjust the EditorConfig for this file.
If I picked the wrong way to address the violations for some other files, please let me know with a respective Review comment. Then I will address it in the correct way. I add Review comments myself for special parts, which are especially worthy of discussion. To support the Review of this Pull Request, I tried to group the changes in meaningful commits with respective commit messages. Therefore, may take a look at the commit history.
Avoid EditorConfig violations in the future
Such EditorConfig violations can creep in again. Possible reasons can be that the editor of some contributors has no EditorConfig support, or it would be required to install a respective plugin for the support.
If you want to avoid them in the future, I would suggest integrating a respective utility. For example as part of the CI. One possibility is to use ecformat with ecformat check --ignore-file .ecformat_ignore. Another one is editorconfig-checker, which is a more sophisticated tool without the possibility to fix violations. It provides more configuration options, such as ignoring violations in single lines with marker comments.
Let me know if you are interested using one of them. I could add one in this Pull Request or a follow-up Pull Request. If you not consider to use ecformat in your project, the .ecformat_ignore file is maybe not worth to merge into the master branch. I can remove it if desired.
This Pull Request is part of an academic research project. More preciously it is for my master's thesis, more background information [here](https://codeberg.org/BaumiCoder/Masterthesis).
### Definition: EditorConfig violations
The goal of this Pull Request is to address all [EditorConfig](https://editorconfig.org) violations in the project. With EditorConfig you have set for example `trim_trailing_whitespace = true` for most files, but there were files with trailing spaces. I call this an EditorConfig violation as a file content violates the respective EditorConfig property. They can have different kind of impacts. For example trailing spaces, which get remove with the next save, may make the next diff / Pull Request to this file less readable. Some other, like a mixture of tabs and spaces for indentation, can make code much harder to read. Like in this code block of your documentation
[here](https://codeberg.org/silverpill/mitra/src/commit/72d5b0b047da87a21af390264778310f30fbaec6/docs/reverse_proxy.md#etc-caddy-caddyfile) (fixed with this PR).
### How to address them?
To check for such violations and fix them I developed the CLI tool [ecformat](https://codeberg.org/BaumiCoder/ecformat). However, there are different ways to address the violations:
1. **Adjust EditorConfig:** The EditorConfig properties for a file can be wrong. For example, you have to use tab characters for indentations
in a Makefile for correct syntax. Therefore, replacing these tabs with spaces would break it. The correct way to address that is to set `indent_style = tab` for them, which ensure that that tabs are used for indentations.
2. **Fix file content:** Another way is to fix the content of the file. Which means for example for `trim_trailing_whitespace = true` to remove trailing spaces. To do so `ecformat fix` can be helpful.
3. **Ignore files:** For some files it is not meaningful to consider the EditorConfig violations, which `ecformat check` finds. I added a `.ecformat_ignore` file for this. It has the common ignore syntax such as a `.gitignore`. To use such ignore files, provide the name of them with an CLI switch, `ecformat check --ignore-file .ecformat_ignore`. (The `.gitignore` files are automatically considered inside a git repository.) There are different reasons to ignore files:
1. As EditorConfig is only for text files, considering binary files does not make sense.
2. EditorConfig supports to set the property on the file level. However, there can be files with intentional differences inside. Such files need to be ignored fully by `ecformat` as it currently (version 0.2.0) has no support to ignore only a single property for some files. (There were no such cases in this project.)
### Changes in this Pull Request
For this Pull Request, I addressed the violations in the project in the way, which looks the most correct one to me. (I focused on the Properties of the current [EditorConfig specification](https://spec.editorconfig.org/#supported-pairs) 0.17.2.) If I fixed file contents, I manually reviewed all of them, making adjustments in the `ecformat fix` changes were necessary.
The only remaining violation is in the file [contrib/openrc/mitra](https://codeberg.org/silverpill/mitra/src/commit/72d5b0b047da87a21af390264778310f30fbaec6/contrib/openrc/mitra). It uses tab characters for indentation and not spaces as set for all files with EditorConfig. Do not know anything about this special file format. Therefore, I am not sure if it is safe to replace the tabs with spaces or if that can break anything. Please let me know if I should fix the file content or adjust the EditorConfig for this file.
If I picked the wrong way to address the violations for some other files, please let me know with a respective Review comment. Then I will address it in the correct way. I add Review comments myself for special parts, which are especially worthy of discussion. To support the Review of this Pull Request, I tried to group the changes in meaningful commits with respective commit messages. Therefore, may take a look at the commit history.
### Avoid EditorConfig violations in the future
Such EditorConfig violations can creep in again. Possible reasons can be that the editor of some contributors has no EditorConfig support, or it would be required to install a respective plugin for the support.
If you want to avoid them in the future, I would suggest integrating a respective utility. For example as part of the CI. One possibility is to use `ecformat` with `ecformat check --ignore-file .ecformat_ignore`. Another one is [editorconfig-checker](https://editorconfig-checker.github.io), which is a more sophisticated tool without the possibility to fix violations. It provides more configuration options, such as ignoring violations in single lines with marker comments.
Let me know if you are interested using one of them. I could add one in this Pull Request or a follow-up Pull Request. If you not consider to use `ecformat` in your project, the `.ecformat_ignore` file is maybe not worth to merge into the master branch. I can remove it if desired.