gpt4 book ai didi

eclipse - 如何使用 CheckStyle 要求制表符缩进?

转载 作者:行者123 更新时间:2023-12-02 09:48:34 29 4
gpt4 key购买 nike

在 CheckStyle 中,有一个模块(文件制表符)用于检查源代码中是否存在制表符。他们的理由是:

  • Developers should not need to configure the tab width of their text editors in order to be able to read source code.
  • From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.

为了确保空格数量正确,有一个附加模块(缩进)。

我更喜欢使用制表符进行缩进,并希望将此要求添加到我的 CheckStyle 文件中。我的理由:

  • Developers should have the opportunity to configure the space used for indentation
  • Tabs are a logical and configurable unit for indentation, n spaces is just an arbitrary number of spaces.

不幸的是,我找不到使用 CheckStyle 执行此操作的方法。

最佳答案

没有现成的检查可以执行此操作,但您可以配置 RegexpSinglelineJava进行相应检查。以下配置将写入 TreeWalker 下的 checkstyle.xml:

<module name="RegexpSinglelineJava">
<property name="format" value="^\t* "/>
<property name="message" value="Indent must use tab characters"/>
<property name="ignoreComments" value="true"/>
</module>

它检查缩进中是否有空格。设置 ignoreComments 可以消除 Javadoc 注释在星号前至少有一个空格的问题。

关于eclipse - 如何使用 CheckStyle 要求制表符缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28458846/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com