Is it possible to collect arbitrary data when scan...
# detekt
h
Is it possible to collect arbitrary data when scanning with Detekt? Example Use case: Gather up all a list of the classes defined in a module, and the source file path they were defined in. I'm thinking the result would be something like:
Copy code
3 Classes
com.example.Class1 - Class1.kt
com.example.Class2 - Class2.kt
com.example.Class3 - Class3.kt
I saw there are Metrics to compute things like the number of lines of code, or number of methods and such. This is similar, but not what I need. I'm new to detekt, but it looks really great. Thank you!
It looks like some sort of Extension is the closest thing to it. Will try making one of each: 🤔
Copy code
* - [FileProcessListener]
 * - [ConsoleReport]
 * - [OutputReport]
 * - [ConfigValidator]
 * - [ReportingExtension]
This section of the documentation is helpful https://detekt.dev/docs/introduction/extensions/#custom-processors
Great tip https://github.com/detekt/detekt/issues/6425#issuecomment-1826423765 for using
--no-daemon
when working on a local
detektPlugins
module.
b
What you want is a
FileProcessListener
and a
OutputReport
. The first will collect the data you want and store it inside
Detektion
using
putUserData
. And then the
OutputReport
to generate the report.
thank you color 1
h
I had a hard time with the custom report output config in Gradle, but copy/pasted the one from https://gitlab.com/cromefire/detekt-gitlab-report/-/blob/main/extension/build.gradle.kts?ref_type=heads#L62 and it finally got it working. Thank you!