dart-lang / dart-lang/language

Add syntactic sugar for package imports

Open
#3,929 2 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

In Dart, it's extremely common to see imports that look like this

```dart
import 'package:epubx/epubx.dart';
import 'package:path/path.dart' as path;
import 'package:quiver/collection.dart';
import 'package:web/web.dart';
import 'package:xml/xml.dart';
```

The repetition in there should be plain to see. As it is the case that it's standard for libraries to put the primarily intended import in a file with the same name as the package, I suggest adding syntactic sugar where `import 'package:foo'` would be treated the same as `import 'package:foo/foo.dart'`. Under this proposed change, the current syntax would remain valid.

With this feature, the example above would instead look like

```dart
import 'package:epubx';
import 'package:path' as path;
import 'package:quiver/collection.dart';
import 'package:web';
import 'package:xml';
```

Beyond being less typing and less reading, and generally looking cleaner, I believe this sugar would also make it easier to see at a glance which packages are being imported partially. It would also allow these "standard" package imports to better mirror the format of Dart SDK imports (`import 'dart:async;'`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.