简体   繁体   English

Eclipse Checkstyle和格式化程序

[英]Eclipse checkstyle and formatter

There is confusion . 有混乱。

For my project i created my own Formatter and checkstyle . 对于我的项目,我创建了自己的Formattercheckstyle

example:-Formatter 示例:格式化程序

there is a Brace tag in Formatter so i made two changes. 在Formatter中有一个Brace标签,所以我做了两个更改。

Brace Position:- 支撑位置:-

Class/interface ..NextLine 类/接口..NextLine

Constructor Declaration ..Next line 构造函数声明..下一行

after write some code i am not following formatted rules . 编写一些代码后,我没有遵循格式化的规则。

Then why my checkstyle not showing any message like "Brace should be next line" . 那为什么我的checkstyle不显示任何消息,如"Brace should be next line"

Currently i am using my own style and previous using Sun Checks(eclipse)-global 目前,我使用自己的样式,以前使用Sun Checks(eclipse)-global

Checkstyle and formatter are two different things. Checkstyle和Formatter是两回事。 Your formatter can help in respecting the rules you've defined in your checkstyle configuration, but your checkstyle configuration does not use the formatter to define its rules. 格式化程序可以帮助您遵循在checkstyle配置中定义的规则,但是checkstyle配置不使用格式化程序来定义其规则。

I do not remember what the "Sun Checks(eclipse)-global" set of rules defines in terms of white spaces around the left curly brace, but whatever the case you might want to define your own rules. 我不记得“ Sun Checks(eclipse)-global”规则集是根据左花括号周围的空白来定义的,但是无论如何,您可能想要定义自己的规则。

  • Right-click on your project, select "Properties" 右键单击您的项目,选择“属性”
  • Got to "Checkstyle" then open the "Local Check Configurations" tab 转到“检查样式”,然后打开“本地检查配置”选项卡
  • Hit "New...", leave the combo on "Internal Configuration" and type a name (say "Sample"), hit "OK" 点击“新建...”,在“内部配置”上保留组合,然后键入一个名称(例如“ Sample”),点击“确定”
  • Go back to the "Main" tab, and select "Sample - (Local)" in the combo, hit "configure..." 返回到“主要”选项卡,然后在组合中选择“样本-(本地)”,点击“配置...”

This is where you configure your own customized set of checkstyle rules. 在这里,您可以配置自己的自定义Checkstyle规则集。 For example in order to make a rule that will mark an error in your editor if the "left curly brace" is on the same line as its block's signature instead of being on a new line : 例如,为了制定一条规则,如果“左花括号”与其块的签名在同一行而不是在新行,则将在编辑器中标记错误:

  • expand "Blocks" 展开“块”
  • double-click "Left curly brace placement" 双击“左花括号放置”
  • select "eol" to force the curly brace to be at the end of the line and hit "OK" 选择“ eol”以强制花括号位于行尾,然后单击“确定”
  • hit "OK" again to go back to the main window of your project's properties 再次单击“确定”以返回到项目属性的主窗口
  • make sure that the "checkstyle active for this project" checkbox is ticked 确保选中“此项目的checkstyle有效”复选框

You can configure a lot of custom rules for your project, see checkstyle's documentation for help. 您可以为项目配置许多自定义规则,请参阅checkstyle的文档以获取帮助。

[edit : a thought after I wrote this ... maybe the fact that you do not see a warning with the "Sun checks(eclipse)" basic configuration comes from the last point I outlined above : make sure that the "checkstyle active for this project" checkbox is ticked in your project's properties ] [编辑 :我写完这篇文章后的一个想法……也许您没有在基本配置中看到“ Sun check(eclipse)”警告的事实来自我在上面概述的最后一点:请确保“此项目”复选框在项目的属性中打勾]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM