Skip to content

False positives for Dart APIs annotated with @Deprecated.implementΒ #256

@LuuPNH

Description

@LuuPNH

πŸ› False positives for Dart APIs annotated with @Deprecated.implement

Summary

SonarQ reports false positives for Dart APIs annotated with @Deprecated.implement, treating them as fully deprecated even when they are only instantiated or used, not implemented or extended.

This causes valid Dart code to be flagged incorrectly by rule
S1874 – Code annotated as deprecated should not be used.

SonarQ Issue

<Type> is deprecated and shouldn't be used.
This class will become 'final' in a future release.
<Interface> may be a more appropriate interface to implement.

Important distinction:

@Deprecated.implement applies only when a class implements or extends the annotated type

Expected behavior

  • Do not flag usage or instantiation of APIs annotated with @Deprecated.implement

  • Only flag cases where a class implements or extends those APIs


Environment

  • SonarQube: v2025.1.4 (113907)
  • Quality Profiles:Sonar way 2025-05-20
  • Rule ID: dart:S1874
  • Dart SDK: 3.10.1
  • Flutter: 3.38.3

Example code triggering the issue

From the Dart SDK (dart:core)

@Deprecated.implement(
  "This class will become 'final' in a future release. "
  "'Pattern' may be a more appropriate interface to implement.",
)
abstract interface class RegExp implements Pattern {
   /// ...
}

Code triggering the issue

final regex = RegExp(r'\d+');
final isMatch = regex.hasMatch('123');

Issue message:

'RegExp' is deprecated and shouldn't be used. This class will become 'final' in a future release. 'Pattern' may be a more appropriate interface to implement. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions