目录

depend_on_referenced_packages

Depend on referenced packages.

此规则自 Dart 2.14 版本起可用。

_规则集:core , recommended , flutter _

详情

#

DO depend on referenced packages.

When importing a package, add a dependency on it to your pubspec.

Depending explicitly on packages that you reference ensures they will always exist and allows you to put a dependency constraint on them to guard you against breaking changes.

Whether this should be a regular dependency or dev_dependency depends on if it is referenced from a public file (one under either lib or bin), or some other private file.

BAD:

dart
import 'package:a/a.dart';
yaml
dependencies:

GOOD:

dart
import 'package:a/a.dart';
yaml
dependencies:
  a: ^1.0.0

使用方法

#

要启用 depend_on_referenced_packages 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 depend_on_referenced_packages

analysis_options.yaml
yaml
linter:
  rules:
    - depend_on_referenced_packages