CheckStyle 使用

插件安装
IntelliJ IDEA -> Preferences -> Plugins,搜索 CheckStyle

配置 Checkstyle
IntelliJ IDEA -> Preferences, 搜索 checkstyle ,选择版本(我这用的 8.36.2 版本,太高会报错),添加,然后自定义一个名称,选择本地 checkstlye,可以放在公共项目,统一管理

一直下一步,如果有报错试试用其他版本,出现如下画面则表示配置成功。

使用 checkstyle 检查
在当前文件右键或使用快捷键呼出,点击 check current fie,出现下图所示

格式化:
如下方式,选择上面配置的 checkstlye.xml 即可

使用快捷键 option+command+l 即可按照文件约束格式化代码。
如果 import 没有自动格式化,使用 shift+option+command+l 即可将 import * 改为单个类导入形式。
评论