Thread
#detekt
    lilypuchi

    lilypuchi

    4 weeks ago
    I’ve written a custom rule as follows:
    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
    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 ?
    @Preview
    @Composable
    fun PreviewScreen() {
      MaterialTheme { .. }
    }
    b

    Brais Gabin

    4 weeks ago
    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
    lilypuchi

    lilypuchi

    3 weeks ago
    @Brais Gabin Yes i report on the KtFunction. I use this rule set a lot for reference. ☺️
    t

    twisterrob

    1 week ago
    @lilypuchi I had success with
    ignoreAnnotated
    using FQCN, see https://github.com/TWiStErRob/net.twisterrob.sun/blob/master/config/detekt/detekt.yml