Skip to content

Rule avoid_type_to_string not working #58377

Open

Description

@tomjmech

The rule avoid_type_to_string is not working for me.

Here are the steps to reproduce:

  1. dart --version
    Dart SDK version: 2.12.3 (stable) (Wed Apr 14 11:02:39 2021 +0200) on "windows_x64"

  2. dart create --template package-simple example_lib

  3. Replace content of analysis_options.yaml with the following:

linter:
  rules:
    avoid_type_to_string: true
  1. Append the following to lib/example_lib.dart:
class A {}

void f() {
  A().runtimeType.toString();
}
  1. dart analyze
    Expected result: a message regarding avoid_type_to_string
    Actual result: no issues found

Activity

  1. pq commented on Apr 21, 2021

    @pq
    Member

    /fyi @a14n

  2. added
    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
    on Apr 21, 2021
  3. goderbauer commented on Apr 26, 2021

    @goderbauer
    Contributor

    I was just running into this as well, the BAD example given in the docs [1] also doesn't produce any lints:

    void bar(Object other) {
      if (other.runtimeType.toString() == 'Bar') {   // LINT expected
        doThing();
      }
    }
    
    Object baz(Thing myThing) {
      return getThingFromDatabase(key: myThing.runtimeType.toString());   // LINT expected
    }
    
    // ---
    
    void doThing() {
    
    }
    
    Object getThingFromDatabase({String? key}) {
      return 'Foo';
    }
    
    class Thing {
    
    }

    [1] https://dart-lang.github.io/linter/lints/avoid_type_to_string.html

  4. pq commented on Apr 26, 2021

    @pq
    Member

    @a14n: any thoughts?

  5. a14n commented on Apr 26, 2021

    @a14n
    Contributor

    @pq I'm not the author of this lint ;)

  6. pq commented on Apr 26, 2021

    @pq
    Member

    Sorry! I was confused w/ no_runtimeType_toString! 😬 Apologies!

    Looks like that one was a contribution from @nscobie (dart-archive/linter#2209). They're on to other stuff though so we'll likely have to look at it.

  7. nscobie commented on Apr 27, 2021

    @nscobie

    Hi all, sorry to hear this lint is having issues.

    I can definitely repro this not working with dart analyze using Dart SDK version 2.12.3, as reported.

    However, it does appear to still be working on my end when running dart test -N avoid_type_to_string in this repository.

    1. When testing in this repository, it successfully reports all violations for the current test cases, the BAD example listed in the docs, and the repro case reported in this issue.
    2. This holds true for both the current HEAD (commit de386a3), and linter version 0.1.129 (the one used in Dart SDK 2.12.3).

    Could this be an issue with rolling into/configuring in the SDK/analyzer? I am not at all familiar with that process, or the overall interplay between the SDK and linter packages.

    Unfortunately I won't have much availability to help with this until my exams are over in a few weeks.

  8. added
    P3A lower priority bug or feature request
    on Oct 26, 2022
  9. oprypin commented on Nov 22, 2022

    @oprypin
    Contributor

    FWIW this issue still applies - this lint never finds any violations, as far as I see.

  10. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    and removed on Feb 21, 2025
  11. jv-soares commented on Mar 13, 2025

    @jv-soares

    Also not working on my side with Dart 3.6.0

  12. self-assigned this
    on Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.customer-flutterdevexp-linterIssues with the analyzer's support for the linter packagelinter-false-negativeIssues related to lint rules that fail to report a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions