How to handle duplicated lines stemming from use of flask smorest

Must-share information:

  • which versions are you using (SonarQube: 9.8 Enterprise, Scanner :latest)
  • how is SonarQube deployed: Helm
  • what are you trying to achieve: reduce the reported number of duplicated lines
  • what have you tried so far to achieve this read the docs

We have a somewhat standard flask application which uses flask-smorest + blueprint.
In smorest, one makes heavy use of decorators for things like schema definitions, standard responses, query parameters, inline documentation etc.
It’s a very declarative form of structuring a flask web app and this of course leads to duplicated blocks of code:




        description="Not Authorized.",

        example={"success": False, "errors": ["Not Authorized."]},





        description="The client is not authorized to perform this operation",





        description="Event not found.",

        example={"success": False, "errors": ["The selected event was not found."]},

def something()

these decorators can be found in a lot of places in our code.
How can we configure sonarqube to ignore these types of duplications? They serve a purpose and are required by flask-smorest.


Welcome to the community!

What you’ve encountered is an unfortunate side effect of how we detect duplications: by looking at tokens rather than appreciating semantics.

Your best bet is to configure duplication exclusions.