 Hello everyone, to today's Bitesize talk, I'm Franziska Brunhardt, I'm the host today and with me is Matthias Herpenhuber and he is going to talk about pre-commit. Yes, hi and it will be a short one so let's get going with it. Fidel is pre-commit, hoped on a commit and it's basically trying how we solve the problem or how we're trying to solve this problem a lot of us run into. You commit your code then GitHub CI runs prettier and it finds a mistake and asks very passive aggressively if you maybe forgot to run prettier. So model a solution, first solution is of course you ask an off-core bot to please fix the linting and I did a quick search and actually 260 PRs have a comment, at least one comment where somebody asked the bot to fix the linting. So that's nice that people are using the bot but actually maybe we should try to save the icebergs and give an off-core bot sometimes a break because these things we can do differently because what if you don't need to run the bot because you already run prettier when you commit your code or actually before you commit to your code. So we use this tool called pre-commit which runs prettier before you, when you get committed, it runs prettier and checks if the code is fine and makes changes on it. So how do you set pre-commit up? Well the good news is it comes already pre-installed with the NFCoreTools as a dependency and then you need to have a pre-commit config YAML file for example this one here for prettier and also more good news in the next tools release this will be part of every pipeline template and also in the modules repository so all there we have that set up it doesn't change anything for you that we have it there but if you then also run in your repository pre-commit install they actually set up this kit hook and whenever you hit commit uh prettier is run beforehand and it doesn't allow you to commit until you fix these changes. So how does it look like? I made here a short example where I just added a line in the README file as you can see it's just below a heading so prettier will not like it so I run commit and actually Peter was run and fixed it but that's the important thing it didn't commit it that it's it's changed but not added so I actually need to run commit a second time that's something something I sometimes forget so you always need to run git commit twice if there's something wrong if nothing is wrong your prettier passes then the commit runs through so this is prettier for which we use for markdown files and similar files but you can use that's one of the nice things with pre-commit you can use basically every linter code linting tool you want and also it doesn't matter if it's in a different language they have like you see with prettier which is actually a npm tool you we don't need to have node installed to run this version of prettier with with pre-commit it just comes through the mirror there but other tools like python-based tools come directly from from the tools itself and if we set this config up like here like we have further tools repository for example it automatically checks the python files for with black and i-sword so in this example I added again to the rebiefile but I also switched the import statements in our main.py and if I then run commit it not only runs prettier but it also runs black and i-sword and black was satisfied i-swords found that there was an error there and fixed it for us and prettier fixed it fast as well with in the readme so and the only changes then were in the readme because we already had it nicely sorted before so had the second commit and now the code is is nice again so yeah that was pretty much it just quick shout out to person who actually brought this tool to us which was Fabian it was more than idea how to always have prettier available in tools without requiring people to install node and he found this tool and actually it's very nice with the having it also run in with pipelines and everything so hail Fabian and with that I'm open for any questions if there are thank you very much so if you have any questions then you can either write them in this in the chat or you can just ask them straight away everyone should be now able to unmute themselves do we have any questions it doesn't seem maxi maxi says hello or has a question yes I have a question you said that it's in tools is it already in the is it already released or is it in the coming release so in tools it's already in the release because actually we run prettier with pre-commit whenever we dump yaml files or chasing file in tools for example when we create the test for modules these files are now prettier files with prettier because before we had the problem that our function actually dumped code prettier didn't like so now we run pre-commit to run prettier on it and also itself the repository has black and iso so there it's already in but for the pipelines the next release will have it in the template so then all the pipelines also get it so you just need to run pre-commit install to activate it modules now has yesterday got the template got the config in so if you now are in modules and pull and then run pre-commit install all your models will automatically run prettier or like all changes and our modules will automatically be run through prettier before you can commit so yeah recommendation to do that if you write modules or sub-work flows thank you are there any more questions if not then I would like to thank our speaker and also the chance like a book initiative for funding the talks and as usual you can ask more questions if you have any in Slack and this will be uploaded to YouTube thank you very much bye everybody