apache / singa

a distributed deep learning platform
Apache License 2.0
3.35k stars 1.24k forks source link

feat: auto formatting & linting using pre-commit #1161

Open tinyAdapter opened 5 months ago

tinyAdapter commented 5 months ago

As documented in the repo, many formatters & linters are used, which can be annoying to manage and execute.

To tackle this, I recommend using pre-commit to combine all formatting, lining, and checking tools into a single run.

Specifically, I added .pre-commit-config.yaml to configure all tools listed in the repo. One can then use

pre-commit run --all-files

in the repo root folder to execute all of them.

I ran the command locally and auto-fixed 402 files. Other linting problems have to be addressed manually, e.g., reinterpret_cast instead of C-style cast. The full log is available here.

Considering whether this automatic process would break the code correctness or not, at least it has passed all written tests (by running the test GitHub action here).

In the future, the pre-commit trigger can be added to GitHub action for checking & auto-fixing.