本文介绍了自动生成的代码不符合CheckStyle标准(jHipster)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在最近的项目中使用jHipster,该工具可用于使用Spring Boot后端自动生成REST api应用程序的整个堆栈。

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...

不幸的是,在我的工作中,我们以一组CheckStyle规则的形式遵守编码标准。任何不遵守这些规则的代码都会导致构建失败。我目前遇到的是,此自动生成的代码在很多地方都未通过CheckStyle规则。目前,我正在通过手动拖拉修复每个问题的代码来处理此问题。

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.:


  • 配置IDE(intelliJ)以确保生成的代码与CheckStyle规则匹配。直接在IDE中进行编码时肯定可以实现。

  • 配置jHipster在自动生成代码之前了解CheckStyle规则。

  • 运行脚本之后可以自动修复任何CheckStyle故障。 (我确定这一定是可行的!)

很高兴听到有人知道解决此问题的最佳方法问题可能是,如果有人在过去做过类似的事情。

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.

推荐答案

按原样抑制所有自动生成文件的违规行为

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

如果文件中包含自动生成的代码,而手动生成的非生成代码则由人工维护。 br />

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.

这篇关于自动生成的代码不符合CheckStyle标准(jHipster)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 09:42