kotlin 格式化_使用ktlint格式化您的kotlin代码

kotlin 格式化

When reviewing merge requests I always find it hard to bring up issues with code style.

在审查合并请求时,我总是发现很难提出代码样式问题。

Code style is subjective. I have my own opinion of what clean code looks like, and that opinion may be very different from the opinion of the rest of my team.

代码风格是主观的。 我对干净代码的外观有自己的看法,这种看法可能与我团队其他成员的看法截然不同。

There are also different levels of code style. On one end of the spectrum we have best practices that directly affect the maintainability of the code going forward:

也有不同级别的代码样式。 一方面,我们拥有直接影响以后代码可维护性的最佳实践:

  • Small methods

    小方法
  • Descriptive method names

    描述性方法名称

On the other end we have issues that do not necessarily make the code harder to maintain, but often make the codebase more consistent and easier to read:

另一方面,我们遇到的问题并不一定会使代码更难维护,但通常会使代码库更一致且更易于阅读:

  • Consistent indentation

    一致的缩进
  • Wrapping long lines

    包装长行
  • Avoiding walls of code

    避开代码墙

While I find it easy to comment on code that does not follow the best practices in the first group, I find it harder to send a merge request back to the author because of issues from the second group.

虽然我发现对不遵循第一组最佳实践的代码进行评论很容易,但是由于第二组的问题,我发现很难将合并请求发送回作者。

If the code works and the tests pass, is it worth delaying that feature because the author used tabs instead of spaces?

如果代码有效且测试通过,那么值得延迟该功能,因为作者使用制表符而不是空格吗?

This is where automation comes in. While it isn’t possible to automate everything, there are tools that can automatically detect code style violations and flag them during the coding process or during the build pipeline.

这是实现自动化的地方。虽然不可能实现全部自动化,但是有些工具可以自动检测代码样式违规并在编码过程中或在构建管道中对其进行标记。

Some tools can even automatically fix some code style violations.

有些工具甚至可以自动修复某些违反代码风格的问题。

In my opinion, the first step to implement these kinds of check

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值