Open VaiTon opened 5 years ago
I would like to hear your opinion @openfoodfacts/openfoodfacts-server
We use .editor config file. Isn't it ok? Did you read: https://en.wiki.openfoodfacts.org/Software_Development ?
Yeah .editorconfig is ok. The problem is that for perl it doesn't enforce any coding style and so any consistency. In a lot of files you will see formatting inconsistencies like these.
Here the method is called without leaving space inside the parenthesis. https://github.com/openfoodfacts/openfoodfacts-server/blob/855a82868da529290f7947358b0da70a801c91fe/t/food_normalize_serving_size.t#L24
Here we left a space right before the parenthesis. Also the method call is closed on next line. https://github.com/openfoodfacts/openfoodfacts-server/blob/855a82868da529290f7947358b0da70a801c91fe/t/additives_tags.t#L37-L38
I think it could be a good idea to decide on a code style and to enforce it with Test::PerlTidy
during CI.
Unsure about the "best" style to choose. Have you tested which options cause the fewest changes to the current source code? It might also be good to not report code style variations as errors right away, because re-formatting a complete codebase in one go isn't a good idea and will break most open PRs.
Maybe the GNU style would cause the fewest changes but it indeed they are a lot.
Is there a way to "convert" files only if they are modified?
Would the first step be to validate all PRs?
Would the first step be to validate all PRs?
I like the idea! With GitHub Actions this could be possible, as demonstrated by https://github.com/lots0logs/gh-action-get-changed-files/blob/master/entrypoint.js One only potential problem could be the size of ProductOpener modules. If we changed a line in Display.pm, the other thousands of lines of code would also be run by perltidy.
Introduction
It's important to use a tool to auto-format the code not only because it improves readability by a lot but also because it makes bug fix easier and once devs are used to that style also modifying code becomes easier.
Proposal
That's why I propose we use perltidy with the gnu style configuration to auto-format the code and test it with TravisCI.
Any suggestion are welcome expecially about deciding the style config the formatter should follow :-)