You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's another formatter with much more configuration called Detekt that some kotlin projects may want to use instead of Ktlint.
(Personally, I still love Ktlint but some people want options). It would be nice if there was an integration with Detekt built in to Spotless..
Reacted by Aidan Follestad, Sascha Peilicke, Pedro Alvarado, Reza Moallemi, Veyndan Stuart, Suresh, André Justi, Erik Huizinga, Marlon López, Nick Achtien and 10 more
Hi @saschpe. Looks like you've done a lot of great work, but the reflection part is pretty tricky. Just wanted to let you know that #524 might be an easier approach.
Just to say that I believe that detekt and klint can (or at least should be able to) be used altogether. A typical use case would be to lint with klint and to do static analysis with detekt.
Reacted by Erik Huizinga, Art Shendrik and Lucas Shadler
Any progress? I see there are commits referencing this issue, but there is no PR. @saschpe is it a matter of opening a PR from your detekt branch in your fork, or are there any issues?
Not really, I lost interest once Klint development started again. A while ago, it had very controversial default settings that where not modifiable. This changed so at least I don't have any further need for Detekt. Sorry.
I agree with @nedtwigg's comment on ktfmt! But just to note that it requires Java 11, so it doesn't yet work with Android projects.
I understand though that the next Android Studio version will be based on Java 11, which should be a big milestone towards allowing Android projects to be built with Java 11, and thus allowing ktfmt to be adopted in that ecosystem.
Just a formatter. We'll merge anything that someone is actually using, but I don't think Spotless provides much benefit to static analysis tools. See this discussion for details.
Then I guess that you can close this issue? Any future inquiries about detekt will find this issue or can be forwarded to it, unless the needs/possibilities change.
For now the recommendation is to use detekt separately.
Nicola here from the Detekt team: we'd love to see this happening. If someone is looking into adding support for Detekt to Spotless we can provide some help
Reacted by Jc Miñarro, Ned Twigg, Byungjun You, Ankush Gupta, Thiago Delgado, Jordan Terry, Juan Rodríguez, Adam Ward, Mayank Kharbanda, Walmyr Carvalho and 7 more
Hello @nedtwigg I'm playing around the code-base to add detekt support (trying to mimic the other implementations). I see that I have to make an implementation of FormatterFunc.NeedsFile. Its function applyWithFile(String unix, File file) requires a string to be returned. I can't quite figure our what's the purpose of that string. Some insight will be helpful.
The function should not read or write to the contents of the file, the file is provided only for its path. The function should read the unix string, and return the formatted string.
Given detekt's nature I don't think we can integrate it with spotless. It doesn't exactly focus on formatting code rather it focus on the code analysis. You can format with it but the default rule sets doesn't even support it. More info:
--auto-correct, -ac
Allow rules to auto correct code if they support it. The default rule
sets do NOT support auto correcting and won't change any line in the
users code base. However custom rules can be written to support auto
correcting. The additional 'formatting' rule set, added with
'--plugins', does support it and needs this flag.
Default: false
Point to be noted that the formatting rule set is a wrapper on ktlint
Agree with @dewantawsif, and if you really need the format from Detekt side (which is ktlint-based), you should integrate Detekt and enable it from the Detekt side.
It is very unfortunate, it would be greate for projects that already use spotless for other kind of files to use detekt from it. For me it is always an issue to justify usage of both in my projects (((
Activity
nedtwigg commentedon Sep 21, 2017
Sounds like it'd be a great addition. Here's how to add it, we'd be happy to help any contributor if they get stuck.
nedtwigg commentedon Feb 13, 2020
Hi @saschpe. Looks like you've done a lot of great work, but the reflection part is pretty tricky. Just wanted to let you know that #524 might be an easier approach.
saschpe commentedon Feb 14, 2020
Ok, I'll take a look.
LifeIsStrange commentedon Jun 18, 2020
Just to say that I believe that detekt and klint can (or at least should be able to) be used altogether. A typical use case would be to lint with klint and to do static analysis with detekt.
erikhuizinga commentedon Nov 20, 2020
Any progress? I see there are commits referencing this issue, but there is no PR. @saschpe is it a matter of opening a PR from your
detektbranch in your fork, or are there any issues?saschpe commentedon Nov 20, 2020
Not really, I lost interest once Klint development started again. A while ago, it had very controversial default settings that where not modifiable. This changed so at least I don't have any further need for Detekt. Sorry.
nedtwigg commentedon Nov 20, 2020
ktfmtis another option which works welljbduncan commentedon Nov 20, 2020
I agree with @nedtwigg's comment on ktfmt! But just to note that it requires Java 11, so it doesn't yet work with Android projects.
I understand though that the next Android Studio version will be based on Java 11, which should be a big milestone towards allowing Android projects to be built with Java 11, and thus allowing ktfmt to be adopted in that ecosystem.
erikhuizinga commentedon Nov 20, 2020
Does ktfmt do static code analysis like detekt, or is it just a formatter/style linter like ktlint?
nedtwigg commentedon Nov 20, 2020
Just a formatter. We'll merge anything that someone is actually using, but I don't think Spotless provides much benefit to static analysis tools. See this discussion for details.
erikhuizinga commentedon Nov 20, 2020
Then I guess that you can close this issue? Any future inquiries about detekt will find this issue or can be forwarded to it, unless the needs/possibilities change.
For now the recommendation is to use detekt separately.
nedtwigg commentedon Jan 12, 2022
From @rougsig in issue above:
That's a good usecase! As mentioned earlier in this thread:
Reopening this issue for now until rougsig finished their PR or gives up :)
emismo commentedon May 16, 2023
any update on this ?
cortinico commentedon May 17, 2023
Nicola here from the Detekt team: we'd love to see this happening. If someone is looking into adding support for Detekt to Spotless we can provide some help
erfansn commentedon Apr 27, 2024
?
OksiBlack commentedon May 30, 2024
Is there a hope? @rougsig
rougsig commentedon May 30, 2024
@OksiBlack i think no
dewantawsif commentedon Jul 4, 2024
Hello @nedtwigg I'm playing around the code-base to add detekt support (trying to mimic the other implementations). I see that I have to make an implementation of
FormatterFunc.NeedsFile. Its functionapplyWithFile(String unix, File file)requires a string to be returned. I can't quite figure our what's the purpose of that string. Some insight will be helpful.nedtwigg commentedon Jul 5, 2024
The function should not read or write to the contents of the file, the file is provided only for its path. The function should read the
unixstring, and return the formatted string.dewantawsif commentedon Jul 5, 2024
Given
detekt's nature I don't think we can integrate it with spotless. It doesn't exactly focus on formatting code rather it focus on the code analysis. You can format with it but the default rule sets doesn't even support it. More info:Point to be noted that the
formattingrule set is a wrapper onktlintGoooler commentedon Aug 31, 2025
Agree with @dewantawsif, and if you really need the format from Detekt side (which is ktlint-based), you should integrate Detekt and enable it from the Detekt side.
OksiBlack commentedon May 7, 2026
It is very unfortunate, it would be greate for projects that already use spotless for other kind of files to use detekt from it. For me it is always an issue to justify usage of both in my projects (((