My team and I want to stop commenting on formattin...
# announcements
n
My team and I want to stop commenting on formatting issues in Pull Requests. We have added ktlint to the project and want to integrate it into our workflow as painlessly as possible. Does anyone have any tips or experiences on how they integrated ktlint (or any other linter) with their kotlin workflow?
j
i'm using the following maven plugin config:
Copy code
<plugin>
                    <groupId>com.github.gantsign.maven</groupId>
                    <artifactId>ktlint-maven-plugin</artifactId>
                    <version>${version.maven.ktlint}</version>
                    <executions>
                        <execution>
                            <id>format-and-check</id>
                            <goals>
                                <goal>format</goal>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
m
use the ktlint gradle plugin, run the task on your CI, if it fails, it needs to be fixed for the Pull Request to pass.
Also add the ktlint rules to android studio, so that formatting is applied as you type your code
m
Hi Neil, my team uses detekt(https://github.com/arturbosch/detekt). It works well with us. I never used ktlint. is Ktlint better than detekt? do you have ideia?
d
If detekt is working well for you, you should have little incentive to switch
e
How many people here reject Pull Requests for formatting issues? 😕 Maybe the best is activate some sort of autoformatting at each save in the IDE…
a
One idea would be to add a pre-push hook which runs the linter over the repository (or selectively runs it on changed .kt files) and fail the push if it fails ktlint
m
@Ema no one should, the CI should take care of that
m
@Dico i agree, my question is about maybe ktlint has best feature or other things that is better or not. it is just curiosity 😉
m
I think ktlint is from the kotlin team
j
We run Detekt using Gradle in git pre push hook, and CI builds run Detekt
Detekt also has IDEA plugin to show errors live in editor
👍 1
n
these are all interesting suggestions, thank-you! @Ema as @Michael Bernier said that is exactly what I want to avoid. I want to make sure that code reviewed in a pull request is properly formatted so that nobody ever has to comment on formatting