Skip to content

Import priority tool #59702

@FMorschel

Description

@FMorschel

In dart-lang/language#4112 one technique discussed/suggested is to export a library with show/hide.

and then import that everywhere you would otherwise import package:flutter/material.dart.

I think we need improved tooling for this.

When I once attempted something similar, the inconvenience of needing to select the correct import - and needing to remember it - is not great.

Perhaps we should have some kind of annotation we could use to say that "this export is preferred over importing directly"? Or perhaps that should be its own issue? I'm not sure where it would go though.

Originally posted by @TekExplorer in dart-lang/language#4112 (comment)

In my company, we have an internal rule. Say we have the following project structure:

lib/
├── a.dart
├── b.dart
├── f1/
│   ├── a1.dart
│   ├── b1.dart
│   └── f1.dart // barrel file exporting a1, b1
└── f2/
    ├── a2.dart
    ├── b2.dart
    ├── f2.dart // barrel file exporting a2, b2, f3/f3
    └── f3/
        ├── a3.dart
        └── f3.dart // barrel file exporting a3
  • If we are in either a or b, we'd import the barrel files for f1 or f2.
  • If we are in a1 and we need something from b1 we'd import it directly, if we need anything else we'd import the closest file with that declaration (meaning a, b or f2/f2)
  • If we are in a2 we'd follow the same rule as above (for files inside f3 we'd import its barrel)
  • If we are in f3 we'd import only barrel files or a/b.

I'm sure other projects have other rules for this but the point stands that importing the right file is a bit hard and a better tool for this would be a great addition!

Not sure what to suggest besides the above but I'm opening this as a place for this conversation.

P.S.: If this is not the right place to open this please say so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions