前言
- 在实际的程序开发中,程序员应该遵循某种约定,这样的好处不言而喻,因此这里记录一下根据Kotlin官方风格指南及阿里出品的java编码规范约定
Kotlin应用风格指南
- Go to Settings/Preferences | Editor | Code Style | Kotlin.
- Click Set from….
- Select Kotlin style guide
Verify that your code follows the style guide
- Go to Settings/Preferences | Editor | Inspections | Kotlin.
- Open Kotlin | Style issues.
- Switch on File is not formatted according to project settings inspection. Additional inspections that verify other issues described in the style guide (such as naming conventions) are enabled by default.
- 完整版请参考Kotlin编码规约
配置Alibaba Java Coding Guidelines plugin
- 打开IDE的插件管理器搜索"Alibaba Java Coding Guidelines"安装之后重启即可

- 鼠标右键会出现手动扫描代码的选项

- 插件也提供了实时监测的功能,此功能默认开启,一旦开启则会在你编写代码时就会实时监测,一旦有不符合规范的语句就会出现错误提示

- 扫描代码后,不符合规约的代码会按Blocker/Critical/Major三个等级显示在下方面板中,如图所示,点击右边的修复,可以改正代码,但不是所有的代码问题都有此按钮,有些代码还是需要手动修改

|