Thread
#detekt
    Charles

    Charles

    2 years ago
    Is there a good way to disallow a certain annotation whole-cloth? I am trying to not let people use Java's
    @SuppressWarnings
    in Kotlin code, because we're trying to track warning suppressing and normalizing would help. The problem with this particular annotation is that there is no associated import to filter on at a file level.
    gammax

    gammax

    2 years ago
    You could potentially write a custom rule that tracks usages of
    java.lang.SuppressWarning
    . I’m not aware of nothing like that already available in Detekt
    Charles

    Charles

    2 years ago
    There's definitely nothing currently available. The problem I'm having is the best approach for that particular rule. It can be applied in so many places.
    b

    Brais Gabin

    2 years ago
    ForbiddenAnnotation… That could be a standard rule in detekt. Would you like to give it a try and write it?
    In any case, could you open an issue to track this? if you need help writing the rule we can use the issue or this channel to help with it.
    gammax

    gammax

    2 years ago
    Agree on the
    ForbiddenAnnotation
    . Just a note that this has a lot of overlapping with
    ForbiddenImports
    (that generally suffice to prevent usage of unwanted annotations). The presented case is more like an edge case as
    @SuppressWarnings
    has no imports.
    Charles

    Charles

    2 years ago
    Yeah, I wonder how often the import rule would otherwise suffice? (But, I'll track it and see if I can come up with a concise
    Rule
    gammax

    gammax

    2 years ago
    The reality is that annotations can be applied on top of a lot of different identifiers (method, fields, classes, etc.). So you probably need a pretty complex rule that tracks all of them. Having using the
    ForbiddenImports
    will allow you to catch it regardless of the usage site of the annotation.
    Charles

    Charles

    2 years ago
    I'll take some time to work on this now
    gammax

    gammax

    2 years ago
    Awesome 👍