tasking-manager icon indicating copy to clipboard operation
tasking-manager copied to clipboard

Set up pre-commit hook for code quality assurance

Open Aadesh-Baral opened this issue 1 year ago • 7 comments

I would like to request the implementation of a pre-commit hook in our project's codebase. A pre-commit hook is a script that runs before a developer's changes are committed to version control, allowing us to catch potential issues early and ensure that all commits meet certain quality standards.

By setting up a pre-commit hook, we can ensure that our codebase follows consistent formatting, passes automated tests, and meets other code quality requirements. This will not only make our codebase more readable and maintainable, but also make code reviews more efficient by catching issues before they're even committed.

I propose that we use pre-commit to set up our pre-commit hook. I believe this will be a valuable addition to our development process and help us improve the overall quality of our codebase.

Sample pre-commit config using pre-commit

Aadesh-Baral avatar Apr 18 '23 04:04 Aadesh-Baral

What hooks do you want added to begin with ? @Aadesh-Baral

eternaltyro avatar Apr 18 '23 07:04 eternaltyro

Pre-commit hooks for formatting, running unit tests, code linting, and security checks would be helpful. For generating texts for translations, we must also execute yarn build-locale on the frontend, which might also be helpful.

Aadesh-Baral avatar Apr 18 '23 07:04 Aadesh-Baral

I understand. Can you list out the available plugins to begin with?

eternaltyro avatar Apr 18 '23 11:04 eternaltyro

I'm not sure about plugins, but I've seen pre-commit used in frameworks like FastAPI.

Aadesh-Baral avatar Apr 19 '23 05:04 Aadesh-Baral

I think we can use some predefined hooks from pre-commit. (https://pre-commit.com/hooks.html)

  • prettier (for frontend),
  • python-import-sorter,
  • python-safety-dependencies-check,
  • check-swagger,
  • sign-commit(optional if we don't want to enforce external contributors to sign commit),
  • flake8,
  • black We might also need to create custom hooks to prepare translation files i.e. done with yarn build-locales.

Aadesh-Baral avatar Apr 19 '23 09:04 Aadesh-Baral

A lot of this is bundled with ruff via pre-commit now.

We have it configured for FMTM, but it isn't enforced yet.

I think a good approach could be via pre-commit.ci (free to use in our case) to run on each PR automatically. We should discuss at the Tech Team Meeting!

spwoodcock avatar Sep 10 '23 16:09 spwoodcock

@mahesh-naxa this has been given highest priority for next release

dakotabenjamin avatar May 02 '24 14:05 dakotabenjamin

Looks like this is done!

Can it be closed?

spwoodcock avatar Aug 20 '24 08:08 spwoodcock

Can close this.

mahesh-naxa avatar Aug 21 '24 08:08 mahesh-naxa