Automatically generated code fails CheckStyle standards (jHipster)

和自甴很熟 提交于 2019-12-11 02:58:30

问题


I've started working with jHipster on a recent project which is a tool you can use to autogenerate the full stack of a REST api application using a Spring Boot back end. Which should save a great deal of time writing boilerplate code...

Unfortunately, at my work we have coding standards to adhere to in the form of a set of CheckStyle rules. Any code that does not adhere to these rules causes the build to fail. What I am experiencing at the moment is that this autogenerated code is failing the CheckStyle rules in a large number of places. Currently I am handling this by manually trawling through the code fixing each of the issues.

I can't help feeling in the back of my mind there must be a better way of doing this e.g.:

  • Configuring the IDE (intelliJ) to ensure the generated code matches the CheckStyle rules. This is certainly possible when coding directly into the IDE.
  • Configuring jHipster to be aware of the CheckStyle rules before autogenerating the code.
  • Running a script afterwards which can automatically fix any CheckStyle failures. (I'm sure this must be doable!)

It would be good to hear if anyone knows what the best way to address this issue might be and if anyone has done something similar in the past.


回答1:


Suppress violations on all auto-generated files as it is out of your control.
http://checkstyle.sourceforge.net/config_filters.html#SuppressionFilter

If you have auto-generated code inside a file with non-generated code that you maintain manually, use comment suppressions.
http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter

You shouldn't be styling code you don't write for this exact purpose, you aren't writing it and some utility is and it wasn't built to your style specifications. If you generate the files again, it will undo any manual changes you made.



来源:https://stackoverflow.com/questions/45298601/automatically-generated-code-fails-checkstyle-standards-jhipster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!