# Recommended Code Style Tool?

**URL:** <https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012>\
**Category:** Support\
**Created:** [May 31, 2017, 1:41am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012 "2017-05-31T01:41:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![napperley](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@napperley](https://discuss.kotlinlang.org/u/napperley)\
**Post date:** [May 31, 2017, 1:41am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/1 "2017-05-31T01:41:18Z")

</div>

Interested to know what code style tool people recommend for Kotlin? Having difficulty deciding whether to use [detekt](https://github.com/arturbosch/detekt) or [ktlint](https://github.com/shyiko/ktlint) for applying a code style to Kotlin code.

---

<div class="post-metadata">

**Author:** ![napperley](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@napperley](https://discuss.kotlinlang.org/u/napperley)\
**Post date:** [May 31, 2017, 11:59pm UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/2 "2017-05-31T23:59:06Z")

</div>

Gradle Inc seem to be recommending **ktlint**.

- @mikehearn - Does Corda use a code style tool for Kotlin?
- @yole - What code style tool are JetBrains using for Kotlin?
- @JakeWharton - Does Square Inc use a code style tool for Kotlin?
- @sdeleuze - Does Pivotal use a code style tool for Kotlin?

Would be interesting to know what code style tool Google are using for Kotlin.

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [June 1, 2017, 11:21am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/3 "2017-06-01T11:21:19Z")

</div>

Actually this question doesn’t make sense without clarifying what you need a static analysis tool for. Are you looking to avoid unnecessarily verbose code, enforce consistent code formatting, avoid security defects, check your code metrics, or what? All these tasks are solved with static analysis tools, and each of these tasks is handled by a different tool in the Java world.

At JetBrains, we don’t use any tools other than IntelliJ IDEA’s built-in inspections.

---

<div class="post-metadata">

**Author:** ![napperley](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@napperley](https://discuss.kotlinlang.org/u/napperley)\
**Post date:** [June 1, 2017, 9:26pm UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/4 "2017-06-01T21:26:26Z")

</div>

Really meant a code style tool. One where the user sets up some code style rules/guidelines, or uses the defaults which are applied to a Kotlin project. IntelliJ has a similar facility for Kotlin however it is **very limited** compared to the Java version.

**Kotlin Code Style Settings**

 ![](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/9/93c2cf741f08fe4a28a505cb47e9c87c33d31842.png)

**Java Code Style Settings**

 ![](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/4/4201556ebe305001bed79467736d58a7291a15a4.png)

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [June 2, 2017, 11:31am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/5 "2017-06-02T11:31:50Z")

</div>

The difference in code style settings is intentional to a degree. We prefer to see Kotlin code using consistent coding styles (similar to how it happens in the Go community, or in Python with PEP8), and not to support infinite configuration possibilities.

---

<div class="post-metadata">

**Author:** ![abosch](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@abosch](https://discuss.kotlinlang.org/u/abosch)\
**Post date:** [June 2, 2017, 9:42pm UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/6 "2017-06-02T21:42:16Z")

</div>

If your using intellij as an IDE then maybe you want to check out the format.sh script inside the bin file which runs intellij headless and formats your code. Additionally you can run detekt to check if your methods are not too complex. (Note: I’m the maintainer of detekt.)

---

<div class="post-metadata">

**Author:** ![shyiko](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/shyiko/32/2690_2.png) [@shyiko](https://discuss.kotlinlang.org/u/shyiko)\
**Post date:** [June 2, 2017, 11:14pm UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/7 "2017-06-02T23:14:13Z")

</div>

@napperley you might also want to take a look at [Linting your Kotlin Builds - IntelliJ IDEA Inspections](http://hadihariri.com/2017/07/01/linting-your-kotlin-builds-intellij-idea/) by Hadi Hariri from JetBrains team.

---

<div class="post-metadata">

**Author:** ![napperley](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@napperley](https://discuss.kotlinlang.org/u/napperley)\
**Post date:** [June 3, 2017, 2:57am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/8 "2017-06-03T02:57:06Z")

</div>

Some very good suggestions made by @abosch and @shyiko 👍. Also of note is that IntelliJ can apply a code style to Kotlin code which is useful when you are dealing with a small sized project.

---

<div class="post-metadata">

**Author:** ![h0tk3y](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/h0tk3y/32/1781_2.png) [@h0tk3y](https://discuss.kotlinlang.org/u/h0tk3y)\
**Post date:** [September 25, 2017, 11:22am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/9 "2017-09-25T11:22:39Z")

</div>

The 1.1.50+ IntelliJ IDEA plugin supports checking the Kotlin code style against the settings configured for the project.

Currently this is only an IDE feature, but there’s a work-in-progress Gradle plugin with the same functionality (not available yet).

![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/c/ca65160d7421827fcb8487cff20fafe0e2334d29.png)

---

<div class="post-metadata">

**Author:** ![hqzxzwb](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@hqzxzwb](https://discuss.kotlinlang.org/u/hqzxzwb)\
**Post date:** [November 1, 2018, 5:51am UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/10 "2018-11-01T05:51:41Z")

</div>

Is that work-in-progress Gradle plugin released yet?

---

<div class="post-metadata">

**Author:** ![h0tk3y](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/h0tk3y/32/1781_2.png) [@h0tk3y](https://discuss.kotlinlang.org/u/h0tk3y)\
**Post date:** [November 1, 2018, 2:20pm UTC](https://discuss.kotlinlang.org/t/recommended-code-style-tool/3012/12 "2018-11-01T14:20:50Z")

</div>

@hqzxzwb There’s a Beta that you can try: [GitHub - JetBrains/inspection-plugin: Gradle plugin to launch IDEA inspections](https://github.com/JetBrains/inspection-plugin)
