I’ve written a custom rule as follows: ```class L...
# detekt
l
I’ve written a custom rule as follows:
Copy code
class LayoutModifierRequiredRule: Rule() {
  ..

  override fun visitNamedFunction(function: KtFunction) {
    super.visitNamedFunction(function)

    // ignore non-@Composable functions
    if (!function.hasAnnotation("Composable")) { return }
    
    val doesModifierParameterExist = function.valueParameters.any { it.name == "Modifier" }

    if (!doesModifierParameterExist) {
      report(..)
    }
  }
}
and in detekt.yml I’ve added the rule as following
Copy code
LayoutModifierRequiredRule:
  active: true
  ignoreAnnotated: ['Preview']
Even though I mention to ignore @Preview annotation, it still highlights the @Preview functions. Am I doing anything wrong here ?
Copy code
@Preview
@Composable
fun PreviewScreen() {
  MaterialTheme { .. }
}
b
Could you share how do you report the issue? Do you report the KtFunction? If you do so it seems like an issue to me. I assuming that you are using a new version of detekt.
As a side note, I highly recommend this compose rule set: https://github.com/appKODE/detekt-rules-compose
l
@Brais Gabin Yes i report on the KtFunction. I use this rule set a lot for reference. ☺️
t
@lilypuchi I had success with
ignoreAnnotated
using FQCN, see https://github.com/TWiStErRob/net.twisterrob.sun/blob/master/config/detekt/detekt.yml