Open mkaze opened 3 years ago
I agree with you @mkaze it would really lead to a clean codebase. May i suggest adding this linters to github actions if in future we go with set up a CI. This would actually automate and contributor need not to worry about formatting the code before pushing.
May i suggest adding this linters to github actions if in future we go with set up a CI.
Yeah, I also meant it to be automated, i.e. use it as an step of CI in Github PRs. I only mentioned the pre-commit hooks as an (optional and) additional tool for the contributors so that they can check and fix the related errors before pushing their commits.
Hi, @therealansh and @mkaze do you have any ideas what style-check/linting should be added? Share best practices here in the thread
@zaleslaw Well, I am relatively new to Kotlin in particular, but what I have in mind is a set of simple and standard checks as part of CI process (hopefully, triggered automatically on PR) which is a common practice in various projects written in different languages. These checks may include all the tests a standard linter or style-checker tool would do, e.g. checking unused imports/variables/functions, small optimizations/improvements, formatting issues according to a fixed style convention, redundant whitespaces/linebreaks, etc. Note that I am not necessarily have the more complex checks in my mind (things like function complexity checks or code smell); actually, I am more inclined towards standard style-checking and basic linting instead of a full-suit of static code analysis.
For example, I have used black
in Python projects; it's very opinionated and cannot be customized very much, however it makes the codebase to follow a fixed set of rules for formatting which in turn keeps it more readable and consistent. A quick search led me to ktlint
(from Pinterest), ktfmt
(from Facebook) and detekt
for Kotlin. Surely, you have a better idea which one might be a good choice (from the description it seems to me that ktlint
is a good option, especially because it's opinionated and therefore we don't need to spend time on configuring it or defining rules). Anyways, whatever we choose at the end, we can simply set it up in Github Actions to be run on each PR to make sure the formatting is correct and consistent (here is an example).
My colleagues advised me ktlint and detekt (both together), so I'll try to set up them for the project in the nearest future.
I was wondering if there is a plan to have automated style check and linting for contributions. This would be really useful to keep the codebase clean and consistent. Additionally, some pre-commit hooks for running style checks and linting could be set up to address this locally before pushing commits.