Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] allow always_declare_return_types to work together with avoid_annotating_with_dynamic #60284

Open
navaronbracke opened this issue Mar 8, 2025 · 1 comment
Labels
area-devexp Developer experience items (DevTools, IDEs, analysis server, completions, refactorings, ...). devexp-linter Issues with the analyzer's support for the linter package linter-false-negative P2 A bug or feature request we're likely to work on

Comments

@navaronbracke
Copy link

Context: I want to avoid dynamic in return values and in parameters / type arguments.

Consider the following situation:

linter:
  rules:
      always_declare_return_types: true
      avoid_annotating_with_dynamic: true
foo() {} // LINT: always_declare_return_types

dynamic bar() {} // NO LINT

Object? qux(dynamic o) {} // LINT: avoid_annotating_with_dynamic

Object? baz(o) {} // NO LINT

The first line foo() {} lints correctly on the missing return type. (which implies dynamic)
However, the second line does not lint on avoid_annotating_with_dynamic for the dynamic return type.
I believe that is a bug? In my opinion it should lint. And it can even provide a quick fix to replace dynamic with Object?, which is what you should really be using.

Maybe this is one of the reasons why avoid_annotating_with_dynamic seems to be broken?

As for enforcing no dynamic in the fourth case I can use always_specify_types,
but maybe we should just have a new lint that disallows dynamic altogether, in all cases? (both implicit and explicit)

See also: #58988

General info

  • Dart 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on "macos_x64"
  • on macos / Version 14.6.1 (Build 23G93)
  • locale is en-BE

Process info

Memory CPU Elapsed time Command line
71 MB 0.0% 23:03:03 dart devtools --machine --allow-embedding --dtd-uri ws:/2c-YbhMscpo=
71 MB 0.0% 23:02:58 dart devtools --machine --allow-embedding --dtd-uri ws:/mb1xzafyaOc=
668 MB 0.0% 23:03:00 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.106.0
415 MB 0.0% 06:55 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.106.0
70 MB 0.0% 23:03:00 dart tooling-daemon --machine
70 MB 0.0% 06:55 dart tooling-daemon --machine
123 MB 1.3% 23:03:00 flutter_tools.snapshot daemon
@lrhn lrhn added the area-devexp Developer experience items (DevTools, IDEs, analysis server, completions, refactorings, ...). label Mar 10, 2025
@bwilkerson
Copy link
Member

However, the second line does not lint on avoid_annotating_with_dynamic for the dynamic return type.
I believe that is a bug?

It seems like a bug to me.

@bwilkerson bwilkerson added devexp-linter Issues with the analyzer's support for the linter package P2 A bug or feature request we're likely to work on linter-false-negative labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp Developer experience items (DevTools, IDEs, analysis server, completions, refactorings, ...). devexp-linter Issues with the analyzer's support for the linter package linter-false-negative P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants