This is a very helpful tool for developers!

In IoTDB we have not only code formatter, the spotless, but also the code 
linter, checkstyle. In maven we can run ‘mvn validate‘ to run checks of both 
the linter and formatter, or 'mvn validate -pl <module_name>' to check one or 
more particular modules. However, unlike 'mvn spotless:apply', there's no way 
to automatically fix the linter error, as it needs more semantic information. 
E.g. we forbid to use wildcard import in Java codes, but the linter doesn’t 
know which class we really want to import, so I have some suggestions for this 
tool.

1. If we want to let pre-commit hook reformat the code automatically, could we 
also report whether there're any violations of the linter rules?
2. Running a maven command is a heavy operation as it will launch a JVM. I have 
tested in my desktop running 'mvn validate' and 'mvn spotless:apply'. They cost 
90 and 55 seconds, it's too long to wait for a commit. Can the hook be wisely 
to choose the modules whose codes are updated to run only? For example I just 
change the codes in confignode module, so it's not necessary to run the check 
in the module server, jdbc, session...
3. It's necessary to give some docs to explain how to enable/disable this tool 
easily. It means that developers can change this through their local git 
config, not forcefully restricted by the git-hook script. For some developer 
who has followed the ContributeGuide [1] to config his IDE well, the formatter 
will be automatically run after file saving. This tool is less helpful for them.

[1] https://iotdb.apache.org/Development/ContributeGuide.html#code-formatting

-----邮件原件-----
发件人: 林地宁宁 <[email protected]> 
发送时间: 2022年6月20日 19:21
收件人: [email protected]
主题: Add `pre-commit-hooks` for pre-commit checks

Hi guys!

AFAIK, we have some style checks in CI/CD. As a novice here, I find it quite 
annoying to remember the checks before I commit.

So how about adding some pre-commit hooks to do these checks for us, such as 
`mvn spotless:apply`.

Though there are some small questions here:
1. Which checks or operations should be done by pre-commit hooks?
2. If a pre-commit check failed, should it throw the error and stop the commit? 
Or just apply the modifications to finish the commit?

Any suggestions?


--
Kind regards,
Ke Lin

Reply via email to